为什么要使用模型视图矩阵逆矩阵的转置来变换法线

为什么要使用模型视图矩阵逆矩阵的转置来变换法线

本文介绍了为什么要使用模型视图矩阵逆矩阵的转置来变换法线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一些着色器,并且需要变换法线.

I am working on some shaders, and I need to transform normals.

我在一些教程中读到了转换法线的方法是将它们与modelview矩阵逆矩阵的转置相乘.但是我找不到为什么的解释,其背后的逻辑是什么?

I read in few tutorials the way you transform normals is you multiply them with the transpose of the inverse of the modelview matrix. But I can't find explanation of why is that so, and what is the logic behind that?

推荐答案

看一下本教程:

https://paroj.github.io/gltut/Illumination/Tut09%20Normal%20Transformation.html

您可以想象,当球体的表面伸展时(因此,球体沿一个轴或类似方向缩放),该表面的法线将全部弯曲"彼此.事实证明,您需要反转应用于法线的比例才能实现此目的.这与使用逆转置矩阵进行转换相同.上面的链接显示了如何从中导出逆转置矩阵.

You can imagine that when the surface of a sphere stretches (so the sphere is scaled along one axis or something similar) the normals of that surface will all 'bend' towards each other. It turns out you need to invert the scale applied to the normals to achieve this. This is the same as transforming with the Inverse Transpose Matrix. The link above shows how to derive the inverse transpose matrix from this.

还请注意,当比例尺均匀时,您可以简单地将原始矩阵作为普通矩阵传递.想象同一球体在所有轴上均等地缩放,则曲面将不会拉伸或弯曲,法线也不会拉伸或弯曲.

Also note that when the scale is uniform, you can simply pass the original matrix as normal matrix. Imagine the same sphere being scaled uniformly along all axes, the surface will not stretch or bend, nor will the normals.

这篇关于为什么要使用模型视图矩阵逆矩阵的转置来变换法线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:18