简体   繁体   English

在OpenGL中计算法线矩阵

[英]Calculating the Normal Matrix in OpenGL

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 . 以下站点表示在计算法线矩阵时使用model_view矩阵(假设我们未使用内置的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? 如果不是为什么,投影矩阵不会像法线那样影响法线吗?

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. 影响光扩散和反射的实际角度是仿射3d空间中的角度。 So using also the projection matrix would get you different angles, wrong angles, and hence wrong lights. 因此,还使用投影矩阵将为您提供不同的角度,错误的角度以及错误的光源。

Do you not include the projection matrix in the computation of the normal matrix? 您是否在法线矩阵的计算中不包括投影矩阵?

No. Normals are required for calculations, like illumination, happening in world and/or view space. 否。法线是计算和/或查看空间中发生的照明(例如照明)所必需的。 It doesn't make sense from a mathematical point of you to do this after projection. 从您的数学角度来看,在投影之后执行此操作是没有意义的。

If not why, does the projection matrix not affect the normals like they do points? 如果不是为什么,投影矩阵不会像法线那样影响法线吗?

Because it would make no sense. 因为那没有意义。 That normals should not undergo projective transformation was the original reason to have a separate projection matrix. 法线不应该进行投影变换是拥有独立投影矩阵的最初原因。 If you'd put normals through the projection they'd loose their meaning and usefullness. 如果让法线穿过投影,它们就会失去其意义和实用性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM