Opengl的gl_NormalMatrix到底为何物?

OpenGL在处理法线时使用gl_NormalMatrix确保法线在透视投影后仍与投影平面垂直。gl_NormalMatrix并非投影矩阵,而是投影矩阵逆的转置。在Direct3D中此过程自动处理,而在OpenGL中需要手动操作。理解投影后模型的状态有助于明白为何需要gl_NormalMatrix。
摘要由CSDN通过智能技术生成

当用glsl传normal到fragment的时候总要用gl_Normal* gl_NormalMatrix,是为什么呢?做bumpmap的时候,binormal和tangent需不需要也乘以gl_NormalMatrix呢,如果需要把TBN转到世界空间,而不是把灯光转到TBN的话需不需要乘以gl_NormalMatrix或者是需要乘以其它矩阵?有没有想过perspective投影之后模型成什么样子呢?在Direct3D你不需要关心这些,因为都处理好了,所以一路稀里糊涂下来效果也基本上做的出来,在OpenGL就不行了。下面解释了什么是 gl_NormalMatrix,简而言之gl_NormalMatrix是为了令法线在perspective projection之后和投影后的模型平面依然垂直,但是它并不是投影矩阵哦,而是投影矩阵的逆矩阵的翻转矩阵惊恐 。呵呵,顺便想象下投影后的物体是什么样子吧,这样就会幡然醒悟为什么需要重新找垂直于平面的发现了。


Normal Matrix

Normals are funny.  They're vec3's, since you don't want perspective on normals.   And they don't actually scale quite right--a 45 degree surface with a 45 degree normal, scaled by glScalef(1,0.1,1), drops the surface down to near 0 degrees, but actually tilts the normal *up*, in the opposite direction from the surface, to near 90 degrees.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值