When we want to compute light in Vertex Shader we need normal vector in view space. In general it looks as below (from OpenGL Superbible 5th):
// normalMatrix is retrieved from GLMatrixStack modelViewMatrix
vec3 vEyeNormal = normalMatrix * vNormal
I want to write program without using GLT Library. In another source (http://en.wikibooks.org/wiki/GLSL_Programming/GLUT/Diffuse_Reflection) I found following formula:
vec3 normalDirection = normalize(m_3x3_inv_transp * v_normal);
Variable m_3x3_inv_transp is computed as follows:
glm::mat3 m_3x3_inv_transp = glm::transpose(glm::inverse(glm::mat3(mesh.object2world)));
I'm conscious that:
- Normal matrix is only rotation component of modelview matrix, because translation of normal vector is unacceptable.
- Order of OpenGL operations is Scalng, Translating, Rotating (Opengl order of matrix transformations)
- Inversing matrix is undo last transformation (http://tomdalling.com/blog/modern-opengl/04-cameras-vectors-and-input/)
My question is why after inversing and transponsing matrix I get NormalMatrix and how to check it with reversing computations?