# beginner question about normal matrix

Hello,

I have seen some examples of shaders using the normal matrix…frequently is used in lighting shaders in order to calculate the intensity of light.

Can someone explain me what is the normal matrix? How can I obtain this normal matrix?

Thanks.

This is a math question, not an OpenGL question, so in the future don’t expect people to answer you. The normal matrix is the matrix which preserves vertex normals under an affine transform. If you do the math, this turns out to be the inverse transpose of the modelview matrix. Note that you can make the code much more efficient whenever the transform, i.e. the modelview, happens to be orthogonal; this would imply that the inverse transpose is just the identity transform, which then makes the normal matrix the same as the modelview matrix. You should learn linear algebra before attempting to learn computer graphics otherwise none of it will make much sense.

Thanks Jesse for your response.

[QUOTE=planza;1252167]I have seen some examples of shaders using the normal matrix…frequently is used in lighting shaders in order to calculate the intensity of light.

Can someone explain me what is the normal matrix? How can I obtain this normal matrix?[/QUOTE]

Jesse has already explained what it is.

If you’re using the compatibility profile, you can obtain it via the GLSL variable gl_NormalMatrix (note that gl_NormalMatrix is a 3x3 matrix, unlike the other matrix variables which are 4x4). This value is derived automatically from the modelview matrix.

If you’re constructing your own matrices and passing them through e.g. glUniformMatrix(), you may need to construct a corresponding normal matrix yourself.