<p>I have implemented an algorithm to calculate vertex normals by taking the normalized average of all its adjacent triangles. I have subdivided a cube two times with catmull clark and checked the shading. If you look close at the first image you can have these dark lines than run along the topological edges of the mesh (defined in the second picture).</p>
<p>Is this normal (no pun intented) and have to do with vertex normals being just an approximation of surface normals? If so why exactly does these artifacts occur? Or have I probably done something wrong with how I calculated the normals?</p>
<p><a href="https://i.sstatic.net/hzQ36.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hzQ36.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/zBpnH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zBpnH.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/4clpz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4clpz.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-08-06T09:41:44.850Z
Looks like the optical illusion known as https://en.wikipedia.org/wiki/Mach_bands
lightxbulb
CC BY-SA 4.0
2021-08-06T19:49:27.933Z
@lightxbulb I see thanks! I just wanted to clarify. I see clear mach bands where's the edge between the light and shadow. And I meant along the topological edges that you can see defined in the second picture. These are mach bands then too right? Whatever reason might be behind the issue, this causes very ugly shading. Do you know if there're any ways to avoid this? Maybe use different shading algorithm in fragment shaders?
Lenny White
CC BY-SA 4.0
2021-08-06T20:07:22.080Z
I think the issue is a disconitnuous derivative, which you see there. I assume that if your normals are proper (I am not certain about that), and one uses non-linear interpolation (e.g. slerp with 3 vectors) then one should be able to get the proper shading. This is too expensive however, and people usually opt to just increase the triangle count.
lightxbulb
CC BY-SA 4.0
2021-08-06T21:14:29.020Z
Here is an interesting blog on this subject (and interpolation in general): https://asawicki.info/news_1721_how_to_correctly_interpolate_vertex_attributes_on_a_parallelogram_using_modern_gpus
pmw1234
CC BY-SA 4.0
2021-08-06T21:20:29.577Z
@pmw1234 While I liked the blog I am not sure how quadrilateral interpolation is relevant to the question, maybe I am missing something. On a side note, this may be relevant: https://www.researchgate.net/publication/220067106_A_comparison_of_algorithms_for_vertex_normal_computation
lightxbulb
CC BY-SA 4.0
2021-08-06T22:38:16.160Z
Nice paper! If you look at figure 3a you will see that all the normal computation algorithms covered in the paper give generally good results for spheres with a low amount of variance between them. Hence the blog link, which by and large discusses attribute interpolation and gives some interesting insights into interpolation that help shed light on the problem in general. Oh, and yes, it does focus on quads.
pmw1234
<opengl><shading>
Dark line artifact along edges of the shaded mesh
Lenny White
# Dark line artifact along edges of the shaded mesh

(Asked by: username_0 on 2021-08-06)

I have implemented an algorithm to calculate vertex normals by taking the normalized average of all its adjacent triangles. I have subdivided a cube two times with catmull clark and checked the shading. If you look close at the first image you can have these dark lines than run along the topological edges of the mesh (defined in the second picture).

Is this normal (no pun intented) and have to do with vertex normals being just an approximation of surface normals? If so why exactly does these artifacts occur? Or have I probably done something wrong with how I calculated the normals?

[![enter image description here](https://i.sstatic.net/hzQ36.png)](https://i.sstatic.net/hzQ36.png)
[![enter image description here](https://i.sstatic.net/zBpnH.png)](https://i.sstatic.net/zBpnH.png)
[![enter image description here](https://i.sstatic.net/4clpz.png)](https://i.sstatic.net/4clpz.png)

**Tags:** opengl, shading

> **Comments:**
> **username_1**: Looks like the optical illusion known as https://en.wikipedia.org/wiki/Mach_bands  
> **username_0**: @username_1 I see thanks! I just wanted to clarify. I see clear mach bands where's the edge between the light and shadow. And I meant along the topological edges that you can see defined in the second picture. These are mach bands then too right? Whatever reason might be behind the issue, this causes very ugly shading. Do you know if there're any ways to avoid this? Maybe use different shading algorithm in fragment shaders?  
> **username_1**: I think the issue is a disconitnuous derivative, which you see there. I assume that if your normals are proper (I am not certain about that), and one uses non-linear interpolation (e.g. slerp with 3 vectors) then one should be able to get the proper shading. This is too expensive however, and people usually opt to just increase the triangle count.  
> **username_2**: Here is an interesting blog on this subject (and interpolation in general): https://asawicki.info/news_1721_how_to_correctly_interpolate_vertex_attributes_on_a_parallelogram_using_modern_gpus  
> **username_1**: @username_2 While I liked the blog I am not sure how quadrilateral interpolation is relevant to the question, maybe I am missing something. On a side note, this may be relevant: https://www.researchgate.net/publication/220067106_A_comparison_of_algorithms_for_vertex_normal_computation  
> **username_2**: Nice paper! If you look at figure 3a you will see that all the normal computation algorithms covered in the paper give generally good results for spheres with a low amount of variance between them. Hence the blog link, which by and large discusses attribute interpolation and gives some interesting insights into interpolation that help shed light on the problem in general. Oh, and yes, it does focus on quads.  

---

## 0 answers

