当我们要在顶点着色器中计算光时,我们需要视图空间中的法向量。一般来说,它看起来如下(从OpenGL Superbible 5th开始):将顶点变换为顶点着色器中的视图空间
// normalMatrix is retrieved from GLMatrixStack modelViewMatrix
vec3 vEyeNormal = normalMatrix * vNormal
我想在不使用GLT库的情况下编写程序。在另一个源(http://en.wikibooks.org/wiki/GLSL_Programming/GLUT/Diffuse_Reflection)我发现下面的公式:
vec3 normalDirection = normalize(m_3x3_inv_transp * v_normal);
可变m_3x3_inv_transp计算如下:
glm::mat3 m_3x3_inv_transp = glm::transpose(glm::inverse(glm::mat3(mesh.object2world)));
我意识到:
- 普通矩阵是仅旋转分量因为 法向量的翻译是不可接受的。
- 秩序的OpenGL操作是Scalng,平移,旋转 (Opengl order of matrix transformations)
- 反演矩阵是撤消上次的变换 (http://tomdalling.com/blog/modern-opengl/04-cameras-vectors-and-input/)
我的问题是,为什么反演和transponsing矩阵后,我得到NormalMatrix以及如何检查它与逆向计算?基于对3D游戏编程和计算机图形(由埃里克·伦盖尔)数学第66页
感谢您在我的思考和简单实用的答案中发现错误。 – CppMonster