10

I have found that "gl_NormalMatrix - 3x3 Matrix representing the inverse transpose model-view matrix". Why does the matrix for normals have to be the inverse transpose model-view matrix? Why can't I just use the model-view matrix for this purpose?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
itun
  • 3,439
  • 12
  • 51
  • 75
  • 1
    You might want to ask new questions as a separate question and not by changing the content of this one. ;) – Bart Apr 28 '11 at 20:55

3 Answers3

10

See here:

This section was inspired by the excellent book by Eric Lengyel “Mathematics for 3D Game Programming and Computer Graphics”.

Many computations are done in eye space. This has to do with the fact that lighting is commonly performed in this space, otherwise eye position dependent effects, such as specular lights would be harder to implement.

Hence we need a way to transform the normal into eye space...

why can’t we just do the same with a normal vector? A normal is a vector of 3 floats and the modelview matrix is 4×4. Secondly, since the normal is a vector, we only want to transform its orientation. The region of the modelview matrix that contains the orientation is the top left 3×3 submatrix. So why not multiply the normal by this submatrix...

Lets have a look at a potential problem...

In the above figure the modelview matrix was applied to all the vertices as well as to the normal and the result is clearly wrong: the normal is no longer perpendicular to the surface.

So now we know that we can’t apply the modelview in all cases to transform the normal vector. The question is then, what matrix should we apply?

Consider a 3×3 matrix G, and lets see how this matrix could be computed to properly transform the normal vectors...

the correct matrix to transform the normal is the transpose of the inverse of the M matrix. OpenGL computes this for us in the gl_NormalMatrix...

gnat
  • 6,213
  • 108
  • 53
  • 73
Stuart Golodetz
  • 20,238
  • 4
  • 51
  • 80
2

It is because the normal is a vector, which is a direction without a position... or at least a direction at any position. The top left 3 x 3 matrix of your normal 4 x 4 modelView matrix contains the rotation component of the modelView matrix. By applying the 3 x 3 you alter the direction of the normal vector. The 4th column of the ModelView matrix contains the translation component, and it makes no sense to be applying a change in position to a vector... a vector does not have a position. The 4 x 4 modelView matrix is required for points as these do have a position.

ste3e
  • 995
  • 1
  • 9
  • 18
0

Well, Normals should not be affected by translation, so I would say that it has to do with putting the model-view matrix to the origin in order to use just the rotation and scaling aspects of the matrix to calculate the normals.

joe_coolish
  • 7,201
  • 13
  • 64
  • 111
  • 2
    No, all you have to do is use a W component of zero when you transform the normal to not include the translation. The lighthouse3d article linked above explains the answer to this exact question (the OP's question). – eodabash Apr 28 '11 at 23:11