以下站点表示在计算法线矩阵时使用 model_view 矩阵(假设我们没有使用内置的 gl_NormalMatrix):(站点)Light House .我的程序中有以下算法:
//Calculate Normal matrix
// 1. Multiply the model matrix by the view matrix and then grab the upper left
// corner 3 x 3 matrix.
mat3x3 mv_orientation = glext::orientation_matrix<float, glext::column>(
glext::model_view<float, glext::column>(glext_model_, glext_view_));
// 2. Because openGL matrices use homogeneous coordinate an affine inversion
// should work???
mv_orientation.affine_invert();
// 3. The normal matrix is defined as the transpose of the inverse of the upper
// left 3 X 3 matrix
mv_orientation.transpose();
// 4. Place this into the shader
basic_shader_.set_uniform_3d_matrix("normal_matrix", mv_orientation.to_gl_matrix());
假设上述代码中的大部分陈述都是正确的。在法线矩阵的计算中不包括投影矩阵吗?如果不是为什么,投影矩阵不会像它们影响点那样影响法线吗?
最佳答案
那是因为projection不是 affine transformation .投影不保持内部产品,然后它们不保持角度。而真正影响光漫射和反射的角度是仿射三维空间中的角度。所以同时使用投影矩阵会让你得到不同的角度,错误的角度,从而导致错误的光线。
关于c++ - 在 OpenGL 中计算法线矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18941632/