gl_NormalMatrix [英] gl_NormalMatrix
问题描述
我发现"gl_NormalMatrix-表示逆转置模型视图矩阵的3x3矩阵".为什么法线矩阵必须是逆转置模型视图矩阵?为什么我不能仅出于此目的使用模型视图矩阵?
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?
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...
这篇关于gl_NormalMatrix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!