bliss
01-12-2011, 11:17 PM
The basic question is: why in several lighning tutorials which I read ModelView Matrix should be used for calculating Normal vectors transformation matrix. Why not Model Matrix only?
Some details:
I use GLSL to insert light into my scene.
In vertex shader I should transform normal vector of each object's surface by multiplying it by a normal matrix:
Normal vectors are also transformed from object coordinates to eye coordinates for lighting calculation. Note that normals are transformed in different way as vertices do. It is mutiplying the tranpose of the inverse of GL_MODELVIEW matrix by a normal vector.
[from here (http://www.songho.ca/opengl/gl_transform.html) ]
I calculate ProjectionViewModel matrix by myself and set it in shader. For Lightning i followed the given code:
glm::mat3 mNorm = glm::inverseTranspose(glm::mat3(mModelView));
It works - I can see shades, but they move if I move camera. This obviously happens since I use glm::lookAt for calculating View Matrix.
Once I changed above formula to:
glm::mat3 mNorm = glm::inverseTranspose(glm::mat3(mModel));
everything seems to run the way it should.
Some details:
I use GLSL to insert light into my scene.
In vertex shader I should transform normal vector of each object's surface by multiplying it by a normal matrix:
Normal vectors are also transformed from object coordinates to eye coordinates for lighting calculation. Note that normals are transformed in different way as vertices do. It is mutiplying the tranpose of the inverse of GL_MODELVIEW matrix by a normal vector.
[from here (http://www.songho.ca/opengl/gl_transform.html) ]
I calculate ProjectionViewModel matrix by myself and set it in shader. For Lightning i followed the given code:
glm::mat3 mNorm = glm::inverseTranspose(glm::mat3(mModelView));
It works - I can see shades, but they move if I move camera. This obviously happens since I use glm::lookAt for calculating View Matrix.
Once I changed above formula to:
glm::mat3 mNorm = glm::inverseTranspose(glm::mat3(mModel));
everything seems to run the way it should.