gl_TessCoord 在镶嵌过程中是如何计算的?

How the gl_TessCoord is computed during the tessellation?

目前正在学习OpenGL的tessellation shader。但是当涉及到曲面细分评估着色器中的内置变量"gl_TessCoord"时,我无法理解它是如何计算的。

我知道 "gl_TessCoord" 使用不同的细分模式(四边形或三角形)时会有所不同。我查了蓝皮书和红皮书,但他们只给出了一个粗略的解释,说它代表输入顶点的权重。有什么想法吗?

下面是矩形镶嵌的示例代码:

#version 430 core
layout ( quads) in;
void main( void)
{
    // Interpolate along bottom edge using x component of the
    // tessellation coordinate
    vec4 p1 = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_TessCoord.x);
    // Interpolate along top edge using x component of the
    // tessellation coordinate
    vec4 p2 = mix(gl_in[2].gl_Position, gl_in[3].gl_Position, gl_TessCoord.x);
    // Now interpolate those two results using the y component
    // of tessellation coordinate
    gl_Position = mix(p1, p2, gl_TessCoord.y);
}

下面是三角形细分的示例代码:

#version 430 core
layout ( triangles) in;
void main( void)
{
    gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position) +
    (gl_TessCoord.y * gl_in[1].gl_Position) +
    (gl_TessCoord.z * gl_in[2].gl_Position);
}

gl_TessCoord 表示与所有原始拓扑相同的概念。

这个向量是当前图元中的位置,最好不要把它想成xyz。由于它是相对于表面的,因此 uvw(可选)更直观。请注意,您可以随意调用坐标(例如 xyzrgbstpuvw),但 uvw 是规范符号。

OpenGL 4.5 (Core Profile) - 11.2.2 Tessellation Primitive Generation - p. 392

Each vertex produced by the primitive generator has an associated (u, v, w) or (u, v) position in a normalized parameter space, with parameter values in the range [0, 1], as illustrated in figure 11.1.

For triangles, the vertex position is a barycentric coordinate (u, v, w), where u + v + w = 1, and indicates the relative influence of the three vertices of the triangle on the position of the vertex.

For quads and isolines, the position is a (u, v) coordinate indicating the relative horizontal and vertical position of the vertex relative to the subdivided rectangle

在四边形的情况下,每个分量测量距单位正方形两个 条边的距离。在三角形的情况下,它是距三角形 三个 边的距离(重心坐标)。这就是为什么您的四边形曲面细分着色器示例仅使用 uv,而三角形示例使用 uvw.

为了更好地说明这一点,请考虑下图: