The normal matrix is typically the inverse transpose of the upper-left 3x3 portion of the model-view matrix. We use the inverse transpose because normal vectors transform differently than the vertex position
在GLSL中,有一些情况需要把局部坐标系下的向量或点转换到视点坐标系下,如光照计算时,需要把法向转化到视点坐标系。
如果是模型上一点p 转化到视点坐标系下,直接(model-view matrix )*p即可,但法线是向量,不是一个点,不能这样做。我们需要用法线矩阵来转换法线。
法线矩阵通常是模型视点矩阵(model-view matrix)左上角3x3矩阵的逆转置矩阵(inverse transpose)。
但如果我们的model-view 矩阵不包含任何非一致缩放(non-uniform scalings),那么我们可以直接用model-view矩阵的左上角3x3矩阵来作为normal matrix来转换normal。
If your model-view matrix does not include any non-uniform scalings, then one can use the upper-left 3x3 of the model-view matrix in place of the normal matrix to transform your normal vectors. However, if your model-view matrix does include (uniform) scalings, you'll still need to (re)normalize your normal vectors after transforming them