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];