且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在一个四边形上对法线进行双线性插值?

更新时间:2023-01-28 08:59:04

您清楚地了解,GL将要执行的三角插值并不是您想要的. 因此普通数据不能直接来自顶点数据.

As you clearly understands, the triangle interpolation that GL will do is not what you want. So the normal data can't be coming directly from the vertex data.

恐怕您正在设想的解决方案是您可以实现的***解决方案.而且无论您选择什么,都需要将[0..1]系数从顶点传递到着色器(包括2x2纹理.您需要它们作为纹理坐标).

I'm afraid the solutions you're envisioning are about the best you can achieve. And no matter what you pick, you'll need to pass down [0..1] coefficients from the vertex to the shader (including 2x2 textures. You need them for texture coordinates).

不过,您可以采取一些技巧来简化流程.

There are some tricks you can do to somewhat simplify the process, though.

  • 使用顶点ID可以帮助您找到要从顶点传递到片段着色器的顶点角"(我们的[0..1]值).对最低的2位进行简单的位测试可以让您知道要向下传递的角,而无需实际的顶点数据输入.如果要打包纹理数据,则仍需要在纹理内部传递一个标识符,因此可能没有意义.
  • 如果您使用2x2纹理进行插值,则有一些问题.如果源开始时的精度较低,则某些纹理插值器不一定会提供高精度插值.这可能需要您将纹理数据类型更改为更高的精度,以避免出现条带失真.