在 TBN 矩阵中,法线、切线和双切线向量总是垂直吗? [英] In a TBN Matrix are the normal, tangent, and bitangent vectors always perpendicular?

查看:65
本文介绍了在 TBN 矩阵中,法线、切线和双切线向量总是垂直吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与另一个问题(有图片)中描述的问题有关:

This is related to a problem described in another question (images there):

Opengl 着色器问题 - 奇怪的光反射伪影

我有一个 .obj 导入器,用于创建数据结构并计算切线和双切线.这是我的对象中第一个三角形的数据:

I have a .obj importer that creates a data structure and calculates the tangents and bitangents. Here is the data for the first triangle in my object:

我对切线空间的理解是法线从顶点向外指向,切线垂直于(正交?)法向量并指向纹理中正S的方向,而双切线则与两者垂直.我不确定你怎么称呼它,但我认为这 3 个向量形成了看起来像旋转或变换的 x、y、z 轴的东西.它们不会是 3 个 随机 方向的向量,对吗?

My understanding of tangent space is that the normal points outward from the vertex, the tangent is perpendicular (orthogonal?) to the normal vector and points in the direction of positive S in the texture, and the bitangent is perpendicular to both. I'm not sure what you call it but I thought that these 3 vectors formed what would look like a rotated or transformed x,y,z axis. They wouldn't be 3 randomly oriented vectors, right?

我的理解:法线贴图中的法线提供了一个新的法线向量.但是在切线空间纹理贴图中,rgb 编码法线和每顶点法线之间没有内置方向.因此,您可以使用 TBN 矩阵来弥合差距并将它们放置在相同的空间中(或将照明放置在正确的空间中).

Also my understanding: The normals in a normal map provide a new normal vector. But in tangent space texture maps there is no built in orientation between the rgb encoded normal and the per vertex normal. So you use a TBN matrix to bridge the gap and get them in the same space (or get the lighting in the right space).

但后来我看到了对象数据...我的结构有 270 个顶点,所有顶点的切线 Y 都为 0.切线数据是否正确?这些切线是否像顶点法线空间一样?或者他们只是看起来完全错误?或者我对它的工作原理和我的数据是否正确感到困惑?

But then I saw the object data... My structure has 270 vertices and all of them have a 0 for the Tangent Y. Is that correct for tangent data? Are these tangents in like a vertex normal space or something? Or do they just look completely wrong? Or am I confused about how this works and my data is right?

为了更接近解决我在另一个问题中的问题,我需要确保我的数据是正确的,以及我对切线空间照明数学如何工作的理解.

To get closer to solving my problem in the other question I need to make sure my data is right and my understanding on how tangent space lighting math works.

推荐答案

切线和双切线向量指向纹理坐标的 S 和 T 分量(对于不习惯 OpenGL 术语的人来说是 U 和 V)的方向.所以切向量点沿 S,双切点沿 T.

The tangent and bitangent vectors point in the direction of the S and T components of the texture coordinate (U and V for people not used to OpenGL terms). So the tangent vector points along S and the bitangent points along T.

所以是的,这些不必与普通或彼此正交.它们遵循纹理映射的方向.事实上,这就是它们的目的:允许您将法线从模型空间转换到纹理空间.它们定义了从模型空间到纹理空间的映射.

So yes, these do not have to be orthogonal to either the normal or each other. They follow the direction of the texture mapping. Indeed, that's their purpose: to allow you to transform normals from model space into the texture's space. They define a mapping from model space into the space of the texture.

只有在该顶点的 S 和 T 分量正交时,切线和副切线才会相互正交.也就是说,如果纹理贴图没有切变.虽然大多数纹理映射算法会尽量减少切变,但它们无法消除它.所以如果你想要一个精确的矩阵,你需要一个非正交的切线和双切线.

The tangent and bitangent will only be orthogonal to each other if the S and T components at that vertex are orthogonal. That is, if the texture mapping has no sheering. And while most texture mapping algorithms will try to minimize sheering, they can't eliminate it. So if you want an accurate matrix, you need a non-orthogonal tangent and bitangent.

这篇关于在 TBN 矩阵中,法线、切线和双切线向量总是垂直吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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