Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy Not Applying the Model View Matrix on Normal Vector in Toon Shading (Lighthouse3d Tutorial)?
    text
    copied!<p>I am learning GLSL by going through <a href="http://www.lighthouse3d.com/opengl/glsl/" rel="nofollow">a tutorial on the Web</a>.</p> <p>The tutorial has an example called the Toon Shading. <a href="http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shading-version-i/" rel="nofollow">Here is the link to Toon Shading - Version I</a>.</p> <p>In this example, the vertex shader is written as follows:</p> <pre><code> uniform vec3 lightDir; varying float intensity; void main() { intensity = dot(lightDir,gl_Normal); gl_Position = ftransform(); } </code></pre> <p>To my best understanding, I know that if a surface is rotated then the normal vectors of the vertices of that surface should also be rotated the same amount, so that the normal vectors reflect the new direction of the surface. However, in the codes above, the Model View Matrix is not applied on to the normal vector. The normal vector is used directly to calculate the light intensity.</p> <p>Regarding my concern, here is what the tutorial says:</p> <p>"lets assume that the light’s direction is defined in world space."</p> <p>and</p> <p>"If no rotations or scales are performed on the model in the OpenGL application, then the normal defined in world space, provided to the vertex shader as gl_Normal, coincides with the normal defined in the local space."</p> <p>These explanations gives me several questions:</p> <pre><code>1. What are world space and local space? How are they different? (This question seems a little bit elementary, but I need to understand...) 2. I figure the fact that "the light’s direction is defined in world space" has something to do with not applying the Model View Matrix on to the normal vector of a vertex. But, what is that? 3. Finally, If we don't apply the Model View Matrix on the normal vector then wouldn't the normal be pointing to a direction different from the actual direction of the surface? How do we solve this problem? </code></pre> <p>I hope I made my questions clear.</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload