2

I tried to interpolate UV coordinates this way in my TES without success. What is the right way to do UV coordinates interpolation? I remark that I'm working with triangle tessellation.

#version 450 core

layout (triangles, equal_spacing, cw) in;

in vec2 UV_tcs[];
out vec2 UV_tes;

void main()
{
    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 );

    UV_tes = gl_TessCoord.x * UV_tcs[0] + gl_TessCoord.y * UV_tcs[1];

}
jovchaos
  • 31
  • 4

1 Answers1

2

In your case the type of the tessellation primitive is triangle

layout (triangles, equal_spacing, cw) in;

and the input variable UV_tcs is per vertex (and not per patch). See Tessellation Control Shader - Outputs and Tessellation Evaluation Shader - Inputs.

in vec2 UV_tcs[];


See Khronos OpenGL wiki - Tessellation - Triangles

Each vertex generated and sent to the TES will be given Barycentric coordinates as the gl_TessCoord input. This coordinate defines where this vertex is located within the abstract triangle patch. The barycentric coordinates for the 3 vertices of the abstract triangle patch are shown in the diagram. All other vertices will be specified relative to these.

To perform linear interpolation between 3 values, at each of the three vertices, you would do this:

vec3 accum = vec3(0.0f)
    accum += gl_TessCoord[0] * value[0]
    accum += gl_TessCoord[1] * value[1]
    accum += gl_TessCoord[2] * value[2]


This means the attributes have to be interpolated according to the Barycentric coordinates (gl_TessCoord.xyz) of the triangle primitive, independent on the type of the attribute.

You have to do it as you do it for the position (gl_in[].gl_Position), change your code like this:

UV_tes = 
    gl_TessCoord.x * UV_tcs[0] +
    gl_TessCoord.y * UV_tcs[1] + 
    gl_TessCoord.z * UV_tcs[2]; 
Rabbid76
  • 202,892
  • 27
  • 131
  • 174