UNITY_MATRIX_IT_MV[Matrix]

本文详细介绍了 Unity 中的 UNITY_MATRIX_IT_MV 矩阵,它用于将对象空间的法线转换到视图空间。由于法线是向量,仅关心方向而非位置,所以不能简单地使用 ModelView 矩阵变换。当涉及到非均匀缩放时,直接使用 ModelView 矩阵会导致法线方向错误。正确的做法是使用逆转置的 ModelView 矩阵,即 UNITY_MATRIX_IT_MV,以保持法线与表面的垂直关系。内容引用了多个资源,深入探讨了法线矩阵的计算原理和应用场景。
摘要由CSDN通过智能技术生成

前面发了一篇关于unity Matrix的文章。

http://blog.csdn.net/cubesky/article/details/38664143

其中对于一般的Matrix可以说应该有一个清晰的了解了。但是对于UNITY_MATRIX_IT_MV这些matrix估计理解起来还是比较有问题。这里再重点描述一下UNITY_MATRIX_IT_MV。

首先,我们看一下unity中Doc中的描述:

UNITY_MATRIX_IT_MV float4x4 Inverse transpose of model * view matrix.
然后我们来看一下UNITY_MATRIX_IT_MV实际的变换意义

The transpose of World2Object is the transpose of the inverse of the Object2World matrix.

  • MV transforms points from object to eye space
  • IT_MV rotates normals from object to eye space
And similarly:
  • Object2World transforms points from object to world space
  • IT_Object2World (which, as you point out, is the transpose of World2Object) rotates normals from object to world space
If it is orthogonal, the upper-left 3x3 of Object2World will be equal to that of IT_Object2World, and so will also rotate normals from object to world space.

上面这里很好的描述了UNITY_MATRIX_IT_MV的使用场景,专门针对法线进行变换。但是为什么法线的变换和定点不一样呢?让我们来看一篇推导的文章。

The gl_NormalMatrix is present in many vertex shaders. In here some light is shed on what is this matrix and what is it for. This section was inspired by the excellent book by Eric Lengyel “Mathematics for 3D Game Programming and Computer Graphics”.

Many computations are done in eye space. This has to do with the fact that lighting is commonly performed in this space, otherwise eye position dependent effects, such as specular lights would be harder to implement.

Hence we need a way to transform the normal into eye space. To transform a vertex to eye space we can write:

	vertexEyeSpace = gl_ModelViewMatrix * gl_Vertex;

So why can’t we just do the same with a normal vector? A normal is a vector of 3 floats and the modelview matrix is 4×4. Secondly, since the normal is a vector, we only want to transform its orientation. The region of the modelview matrix that contains the orientation is the top left 3×3 submatrix. So why not multiply the normal by this submatrix?

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值