3
$\begingroup$

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:

http://imgur.com/a/JjLxp

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

$\endgroup$
  • 3
    $\begingroup$ 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). $\endgroup$ – Rahul May 23 '17 at 2:06
  • $\begingroup$ 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. $\endgroup$ – trichoplax May 23 '17 at 10:17
  • $\begingroup$ @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. $\endgroup$ – Tim Rolff May 23 '17 at 12:11
  • $\begingroup$ 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). $\endgroup$ – Simon F May 23 '17 at 16:12
  • 2
    $\begingroup$ 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. $\endgroup$ – Rahul May 24 '17 at 5:06
1
$\begingroup$

enter image description here

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.

What actually happened in my case was that the normals differs slightly (thank you @Rahul for the tip) which therefore results in this strange look. I fixed them by averaging the normals over a small radius to ensure the proper set up of the normals.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.