# Does smooth lighting work with Gouraud shading on single triangles?

I'm currently working on a project where a 3D model gets computed through an isosurface algorithm. This algorithm outputs single triangles with vertices and normals, but without indices. So therefore I have a lot of duplicates which can't be avoided, because of a software restriction.

I was asked to write smooth lighting for this model, by sending the proper normals to the visualisation software, which uses OpenGL and runs under Windows. What I tried was to set the normals for duplicated vertices to the same direction but this also results in unsmoothed lighting

as visible here:

Is it possible to have smooth Gouraud shading on a 3D Model which consists of many single unconnected triangles?

• As long as all duplicates of a vertex have the same normal, you should get smooth shading. Check that (i) the duplicated normals are indeed identical, and (b) the shader is actually doing Gouraud shading and not, say, flat shading (incorrect setting of glShadeModel or interpolation qualifier).
– user106
May 23, 2017 at 2:06
• If you just want to know whether this is possible, this seems ready to answer, and @Rahul's comment contains a good start on such an answer. If you want to know why your specific code isn't working, we'd need to see it in order to investigate it. May 23, 2017 at 10:17
• @Rahul Thank you for your hints. I check the normals and the glShadeModel and both are set correctly. I also wrote the model into an Wavefront obj file and this also results in strange lightning. Here is an image of the model imgur.com/a/JjLxp. May 23, 2017 at 12:11
• Oh..could it be that you are seeing "Mach band-ish" related" artefacts that appear when you get a discontinuity in the 1st derivative of the shading? Basically, the human visual system amplifies these discontinuities (probably to save our ancestors being eaten by lions). May 23, 2017 at 16:12
• Going by your image, it looks like you have Gouraud shading working perfectly well. The problem is a combination of skinny triangles and poorly estimated normals, making it look like the shading is not smooth when really it is just varying rapidly over a narrow region.
– user106
May 24, 2017 at 5:06

After thinking about it for some days I came up with a proof sketch (which is hopefully correct) that it is possible to use Gouraud shading on disconnected triangles, if they share an edge with the same normals as in the picture. The simple idea of this proof is to check that there is no discontinuity between the intensity of the triangles by approaching from each side to the edge. So given two triangles $T_1: (P_1,P_2,P_3)$ and $T_2: (P_1', P_2', P_3')$ which share an edge and let's assume w.l.o.g. that this edges are constructed by $(P_2,P_3)$ and $(P_2', P_3')$. Because Gouraud shading only computes the light intensity at the vertex positions and interpolate in between them, it's save to assume that the intensity at $P_2$ is the same as on $P_2'$, same goes for $P_3$ and $P_3'$. Because it's also save to assume that the values inside the triangles are getting computed correctly so it's only necessary to show that there is no discontinuity between the triangles. To interpolate inside the triangle it's rational to use Barycentric coordinates so that the intensity at any point inside the triangle is given by \begin{align*} I &= aI_2 + bI_3 + (1 - (a+b)) I_1\\ I' &= a'I_2' + b'I_3' + (1 - (a'+b')) I_1' \end{align*} By now going from $I_1$ respectively $I_1'$ to the edge, a sequence can be constructed to archive this, by setting $a_n = \frac{c}{n+1}, b_n=\frac{d}{n+1}, c + d = 1$ and analogously for $a_n', b_n'$. Then the intensity is \begin{align*} I_n &= \frac{c}{n+1} I_2 + \frac{d}{n+1} I_3 + (1 - \frac{c+d}{n+1}) I_1\\ I_n' &= \frac{c'}{n+1}I_2' + \frac{d'}{n+1}I_3' + (1 - \frac{c'+d'}{n+1}) I_1' \end{align*} If one now approaches the edge with: \begin{align*} &\lim\limits_{n\rightarrow 0^+} I_n = cI_2 + dI_3\\ &\lim\limits_{n\rightarrow 0^+} I_n' = c'I_2 + d'I_3' \end{align*} and using the requirement that $I_n$ and $I_n'$ share the same position $P_n$ if they are on an edge, which can be constructed by \begin{align*} P_n &= \frac{c}{n+1} P_2 + \frac{d}{n+1} P_3 + (1 - \frac{c+d}{n+1}) P_1\\ P_n &= \frac{c'}{n+1}P_2' + \frac{d'}{n+1}P_3' + (1 - \frac{c'+d'}{n+1}) P_1' \end{align*} with the fact that $P_2 =P_2'$ and $P_3 = P_3'$ it follows: \begin{align*} &\lim\limits_{n\rightarrow 0^+} P_n = cP_2 + dP_3\\ &\lim\limits_{n\rightarrow 0^+} P_n' = c'P_2 + d'P_3 \end{align*} and $d = 1 - c$ \begin{align*} &\lim\limits_{n\rightarrow 0^+} P_n = cP_2 + (1-c)P_3\\ &\lim\limits_{n\rightarrow 0^+} P_n' = c'P_2 + (1-c')P_3 \end{align*} this results in $c = c'$ and therefore this gives the final result: \begin{align*} \lim\limits_{n\rightarrow 0^+} I_n = cI_2 + (1-c)I_3 = c'I_2' + (1-c')I_3' = \lim\limits_{n\rightarrow 0^+}I_n' \end{align*} Thereby is possible to use Gouraud shading over disconnected triangles as in my case, because the intensity on the edge is the same on both triangles.