View Full Version : about normal matrix

When I read OpenGL related documents, I saw something like this

normal matrix is the inverse of the upper left most 3 x 3 of gl_modelViewMatrix

In my understanding, the normals we specified is in object coordinate system. So what is the purpose of modelview inverse matrix? I am confused with its definition and possible usages. Anybody can help clarify?

thanks

Trahern

05-18-2005, 01:04 AM

Originally posted by <NeoBabies>:

When I read OpenGL related documents, I saw something like this

normal matrix is the inverse of the upper left most 3 x 3 of gl_modelViewMatrix

In my understanding, the normals we specified is in object coordinate system. So what is the purpose of modelview inverse matrix? I am confused with its definition and possible usages. Anybody can help clarify?

thanksIts very useful when working with shaders. For example if you want to compute per-fragment lighting you need the light-direction-vector, eye-direction-vector and normal-vector. But all of these vectors have to be in the same coordinate system. As you said normals are defined in object-space but the other vectors ( eye and light ) are usualy computed in world-space. So you have a possibility to convert these two vectors into object space and calculate lighting or to convert normal-vector into world-space which is easier ..you just multiplies normal vector with normalMatix.

Relic

05-18-2005, 01:55 AM

Hmm, a little complicated.

The real reason for the inverse is that rotations and translations do not change the length of vectors, but scale operations do.

Non-uniform glScale parameters will squish your normals to point into the wrong directions. You need to use the inverse scaling to keep them pointing into the correct direction.

To visualize this take a sheet of paper and draw a circle with normals pointing outwards. Now scale one axis by 0.5 giving an ellipse.

Where do the normals point if you would scale them by 0.5 on the same axis?

See? Instead they need to be scaled by 2.0 on that axis.

Note, scale operations require the normals to be renormalized to get correct lighting. OpenGL does this for you with glEnable(GL_NORMALIZE).

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