glsl中可提取的mat3(mat4矩阵)语句有什么作用? [英] What extractly mat3(a mat4 matrix) statement in glsl do?

查看:835
本文介绍了glsl中可提取的mat3(mat4矩阵)语句有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按片段照明,并且在校正普通矢量时,我得到以下代码:vec3 f_normal = mat3(MVI) * normal;其中MVI是:mat4 MVI = transpose(inverse(ModelViewMatrix));.那么mat3(MVI)语句之后返回什么?

I'm doing a per fragment lighting and when correcting normal vecter, i got this code: vec3 f_normal = mat3(MVI) * normal; Where MVI is: mat4 MVI = transpose(inverse(ModelViewMatrix));. So what is return after mat3(MVI) statement?

推荐答案

mat3(MVI) * normal

从4x4矩阵返回上层3x3矩阵,并将其乘以法线.该矩阵称为普通矩阵".使用此功能可以将法线从世界空间带到眼睛空间.矩阵的上部3x3部分对于缩放和旋转很重要,而其余部分仅用于平移(法线从不平移)

Returns the upper 3x3 matrix from the 4x4 matrix and multiplies the normal by that. This matrix is called the 'normal matrix'. You use this to bring your normals from world space to eye space. The upper 3x3 portion of the matrix is important for scale and rotation, while the rest is only for translation (and normals are never translated)

要将法线从世界空间移到眼睛空间,您只需要模型视图矩阵的3x3 逆转置即可.除非在这种情况下您的矩阵处于正交法线(没有非均匀比例),否则原始矩阵与其逆转置相同.

To take a normal from world space to eye space, you just need the 3x3 inverse transpose of the model view matrix. Unless your matrix in othro normal (no non-uniform scale) in that case the original matrix is the same as its inverse transpose.

这篇关于glsl中可提取的mat3(mat4矩阵)语句有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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