c++ - 在 OpenGL 中计算法线矩阵

标签 c++ opengl matrix normals

以下站点表示在计算法线矩阵时使用 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/

相关文章:

c++ - C++ 和 Grep 之间二进制到 ASCII 的不同?

c++ - 具有 OpenGL 纹理转换的 Awesomium

c++ - 如何在 OpenGL 中反转纹理颜色

matlab - 使用matlab中其他向量的元素创建矩阵

c++ - 存储用于事件监听器注册的指针

c++ - 我怎样才能让我的程序以秒为单位返回时钟一天中耗时?

c++ - Maya 中的 LocatorNode 始终采用平面着色

java - 矩阵的想法

旋转矩阵的 Python 程序。为什么我的程序花费了这么多时间?

c++ - Visual C++ Studio,仅重新编译修改后的文件