View Full Version : beginner question about normal matrix

planza

06-26-2013, 11:25 AM

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.

Jesse

06-26-2013, 02:02 PM

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.

planza

06-26-2013, 02:18 PM

Thanks Jesse for your response.

GClements

06-26-2013, 03:34 PM

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?

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.