3D图形,单位向量和正交矩阵 [英] 3d graphics, unit vectors and orthogonal matrices

查看:193
本文介绍了3D图形,单位向量和正交矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使自己陷入切线空间,并且我开始提出一些我无法问我的同事的问题,因为他们开始不知道我在说什么.我正在尝试在opengl上进行普通映射.我目前的计划是在几何着色器中计算切线-切线法线矩阵.

I'm trying to get my head wrapped around tangent space and I'm starting to come up with questions that I can't ask my colleagues because they're starting to have no idea what I'm talking about. I'm trying to do normal mapping on opengl. My current plan is to calculate the tangent-bitangent-normal matrix in a geometry shader.

  1. 当我有一个正交矩阵(例如TBN矩阵)并且我让opengl在顶点之间进行插值时,三个结果矢量(T,B和N)仍然是单位长度吗?它们仍然彼此成90度角吗?
  2. 当我将(单位长度)法线贴图样本与正交矩阵相乘时,结果是否也保证为单位长度?我认为是这样,但无法通过它进行推理.
  3. 我当时正在考虑使用详细的法线贴图,以使近距离的物体看起来不像现在那样糟糕.那意味着那会有两个法线贴图.如何合并两个样本?

要回答我自己的问题,一位同事过来研究#2,他想出了一个优雅的证明.在这里输入的内容有点多,但是可以说是真的.

To reply to my own question, a colleague came over to work on #2 and he came up with an elegant proof. It's a bit much to type out here but suffice to say that it's true.

推荐答案

由于仍然没有完整的答案,我认为我可以尝试一下:

Since there are still not complete answers, I figured I'd have a go at it:

1)不,不.想象一下三个成对正交且单位长度的向量v1v2v3.那么,当然-v3是单位长度,并且还正交于v1v2.现在想象一下矩阵A=(v1|v2|v3)B=(v2|v1|-v3).如果在两者之间进行插值,则将在中间显示C=((v1+v2)/2|(v1+v2)/2|0).很容易看出这不会保持长度:(0 0 1)^T只会成为零向量.同样,第一列和第二列将相等,这意味着它们的角度为0°.但是,在实际中,要插值的两个矩阵对于这种退化通常不会有足够的不同.也就是说,如果您的表面是可定向的.如果可以在表面上定义内部和外部一致,则表面是可定向的. moebius-strip是一个常见的反例! 一种更正确的方法是插值旋转(同样,曲面需要可定向):您可以使用球形插值(google!)或归一化插值(插值矩阵并正交化,但是在某些边缘情况下也会失败) .但是,这两种插值都很昂贵-实际上,人们只是将光源转换为顶点的TBN坐标,然后使用线性插值(等效于仅在TBN矩阵上使用线性插值).

1) No and no. Imagine three vectors v1, v2 and v3 that are pair-wise orthogonal and all unit-length. Then of course, -v3 is unit-length and also orthogonal to v1 and v2. Now imagine the matrices A=(v1|v2|v3) and B=(v2|v1|-v3). If you interpolate between the two, you will get C=((v1+v2)/2|(v1+v2)/2|0) right in the middle. It's easy to see that this will not maintain length: (0 0 1)^T will just become the zero-vector. Also, the first and second column will be equal, which means that their angle is 0°. In pratice, however, the two matrices you will be interpolating will usually not be different enough for such a degeneration. that is if your surface is orientable. Surfaces are orientable if you can define a consistent inside and outside on them. The moebius-strip is a common counter-example! A slightly more correct way would be interpolate rotations (again, the surface needs to be orientable): you can either use spherical interpolation (google!) or normalized interpolation (interpolate the matrices and orthogonalize, but this will also fail with some fringe cases). However, both interpolations can be expensive - and in practice, people just transform the light source into the vertices' TBN coordinates and use linear interpolation (which is equivalent to just use linear interpolation on the TBN matrices).

2.)绝对可以.实际上,这适用于任何长度,而不仅仅是长度.正交矩阵会引起同构映射,该映射既保留矢量之间的长度,也保留其角度.您可以使用此类矩阵定义的两种变换是旋转和镜像,它们都可以直观地显示出来.

2.) Definitely yes. In fact, this works for any length, not just one. Orthogonal matrices induce isomorphic mappings, which preserve both lengths and angles between vectors. The two kinds of transformations that you can define using such matrices are rotations and mirrors, both of which intuitively show this.

3.)就我个人而言,我只需将两者相加然后重新规格化即可. Mipmapping通常会冲洗远处的法线贴图,因为法线在求平均值时会变短.当然,您可以在mipmapping代中重新规范法线,但是我将其排除在外以防止混叠并使此效果起作用.除此之外,将两者结合起来基本上是一个品味(和外观!)问题.老实说,这可能是完全不使用细节法线贴图,而只使用高分辨率纹理的更好方法.如今,图形硬件具有足够的RAM用于处理诸如此类的简单事情,如果您认为RAM成为问题,则可以始终流式传输内容.

3.) Personally, I'd just add the two and then renormalize. Mipmapping will typically wash-out normalmaps in the distance because normals become shorter during averaging. Of course, you can renormalize the normals in the mipmapping generation, but I'd leave that out to prevent aliasing and make this effect work. Other than that, it's basically a matter of taste (and looks!) how you combine the two. To be honest, it's probably a better way to not use detail-normalmaps at all and just use higher-resolution textures. Graphics hardware has enough RAM for simple things like that nowadays, and you can always stream stuff if you think RAM is becoming a problem.

这篇关于3D图形,单位向量和正交矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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