在OpenGL中计算法线矩阵 [英] Calculating the Normal Matrix in OpenGL

查看:198
本文介绍了在OpenGL中计算法线矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下站点说在计算法线矩阵时使用model_view矩阵(假设我们未使用内置的gl_NormalMatrix):(site)

The following site says to use the model_view matrix when computing the normal matrix (assuming we are not using the built in gl_NormalMatrix): (site)Light House. I have the following algorithm in my program:

//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());

假设以上大多数语句在上述代码中是正确的.您是否在法线矩阵的计算中不包括投影矩阵?如果不是为什么,投影矩阵不会像法线那样影响法线吗?

Assuming most statements above are correct in the aforementioned code. Do you not include the projection matrix in the computation of the normal matrix? If not why, does the projection matrix not affect the normals like they do points?

推荐答案

这是因为投影是不是仿射变换.投影不保持内积,然后不保持角度.影响光扩散和反射的实际角度是仿射3d空间中的角度.因此,还使用投影矩阵将为您提供不同的角度,错误的角度以及错误的光源.

That's because projection is not an affine transformation. Projections don't maintain the inner product and then they don't maintain the angles. And the real angles that have effect on the light diffusion and reflection are the angles in the affine 3d space. So using also the projection matrix would get you different angles, wrong angles, and hence wrong lights.

这篇关于在OpenGL中计算法线矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆