title: How to calculate the normal matrix?
body: <p>I have some trouble with my normal matrix.</p>
  
  <p>vs.glsl</p>
  
  <pre><code>#version 440
  
  in vec3 vPosition;
  in vec3 vNormal;
  
  out vec4 eyeCordFs;
  out vec4 eyeNormalFs;
  
  uniform mat4 model;
  uniform mat4 view;
  uniform mat4 proj;
  
  void main()
  {   
      mat4 modelView = view * model;
      mat4 normalMatrix = view * transpose(inverse(model));
      vec4 eyeNorm = normalize(normalMatrix * vec4(vNormal, 0.0));
      vec4 eyeCord= modelView * vec4(vPosition, 1.0);
  
      eyeCordFs = eyeCord;
      eyeNormalFs = eyeNorm;
  
      gl_Position = proj * modelView * vec4( vPosition,1.0);
  }
  </code></pre>
  
  <p>fs.glsl</p>
  
  <pre><code>#version 440
  
  in vec4 eyeCordFs;
  in vec4 eyeNormalFs;
  
  out vec3 outputColor;
  
  uniform vec4 lightPos;
  
  void main()
  {
      vec4 s = normalize(lightPos - eyeCordFs) ;
      vec4 r = reflect(-s,eyeNormalFs);
      vec4 v = normalize(-eyeCordFs);
      float spec = max( dot(v,r),0.0 );
      float diff = max(dot(eyeNormalFs,s),0.0);
  
      vec3 diffColor = diff * vec3(1,0,0);
      vec3 specColor = pow(spec,3) * vec3(1,1,1);
      vec3 ambientColor = vec3(0.1,0.1,0.1);
  
      outputColor =  diffColor + 0.5 * specColor + ambientColor; 
  }
  </code></pre>
  
  <p>The output of this looks like
  <img src="https://i.stack.imgur.com/fXDHm.png" alt="enter image description here"></p>
  
  <p>Which seemed a bit strange to me. But I knew that I am not scaling anything so I thought I could use the modelView matrix to transform my normals.</p>
  
  <p>So I changed the line</p>
  
  <pre><code>vec4 eyeNorm = normalize(normalMatrix * vec4(vNormal, 0.0));
  </code></pre>
  
  <p>to</p>
  
  <pre><code>vec4 eyeNorm = normalize(modelView * vec4(vNormal, 0.0));
  </code></pre>
  
  <p>And the output now looks like this</p>
  
  <p><img src="https://i.stack.imgur.com/IJ5S5.png" alt="enter image description here"></p>
  
  <p>which looks correct. Am I calculating my <code>normalMatrix</code> the wrong way?</p>