为什么用模型视图矩阵的逆矩阵的转置来变换法线? [英] Why transform normals with the transpose of the inverse of the modelview matrix?

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

问题描述

我正在研究一些着色器,我需要转换法线.

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

我在几篇教程中读到的转换法线的方式是将它们与模型视图矩阵的逆矩阵的转置相乘.但我找不到解释为什么会这样,这背后的逻辑是什么?

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.

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

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