I'm learning environment mapping in OpenGL by following this page.
In his vertex shader, the author calculates the vertex normal in eye space with the following code:
nEye = vec3(viewMatrix * modelMatrix * vec4(vertexNormal, 0.0));
This works, but I've fooled around and made modifications to the shader code, so that it calculates the vertex normal with this code:
nEye = vec3(normalMatrix * vec4(vertexNormal, 0.0));
Where normalMatrix is a uniform 4x4 matrix I calculated outside the shader:
objectNormalMatrix = viewMatrix * modelMatrix; objectNormalMatrix.invert(); objectNormalMatrix.transpose();
(I read from this question that the above is how you are supposed to calculate the normal matrix).
For either method of calculating the vertex normal I use, I get the same (working) graphical result, and this is what is confusing me.
My question is, why is
(viewMatrix * modelMatrix) apparently equivalent
normalMatrix? In calculating the normal matrix, I invert and transpose, but I do none of that when just multiplying by
(viewMatrix * modelMatrix).
Here is some extra info that might be relevant:
- The matrix library I use in my application is column major order (same as OpenGL).
- When I pass my matrices to GLSL with
glUniformMatrix, I have
- The view matrix and model matrix in GLSL are uniforms from the application, and they are the exact same view matrix and model matrix matrices I use in my calculation of the normal matrix.