I tried to render a triangle with a tessellation shader. Now, without the tessellation shaders, the triangle renders fine. As soon as I add the tessellation shaders, I get a blank screen. I have also written glPatchParameteri(GL_PATCH_VERTICES,3)
before glDrawArrays(GL_PATCHES,0,3)
.
Here are the shaders:
VERTEX SHADER:
#version 440 core
layout (location = 0) in vec2 apos;
out vec2 pos;
void main()
{
//gl_Position = vec4(apos,1.0f,1.0f); without tessellation shaders
pos = apos;
}
TESSELLATION CONTROL SHADER
#version 440 core
layout (vertices = 3) out;
in vec2 pos[];
out vec2 EsPos[];
void main()
{
EsPos[gl_InvocationID] = pos[gl_InvocationID];
gl_TessLevelOuter[0] = 3.0f;
gl_TessLevelOuter[1] = 3.0f;
gl_TessLevelOuter[2] = 3.0f;
gl_TessLevelInner[0] = 3.0f;
}
TESSELLATION EVALUATE SHADER
#version 440 core
layout (triangles, equal_spacing, ccw) in;
in vec2 EsPos[];
vec2 finalpos;
vec2 interpolate2D(vec2 v0, vec2 v1);
void main()
{
finalpos = interpolate2D(EsPos[0],EsPos[1]);
gl_Position = vec4(finalpos,0.0f,1.0f);
}
vec2 interpolate2D(vec2 v0, vec2 v1)
{
return (vec2(gl_TessCoord.x)*v0 + vec2(gl_TessCoord.y)*v1);
}
FRAGMENT SHADER
#version 440 core
out vec4 Fragment;
void main()
{
Fragment = vec4(0.0f,1.0f,1.0f,1.0f);
}
EDIT:
I made changes in the interpolate2D function, but still I am getting a blank screen.
The output patch size of the Tessellation Evaluation shader is 3:
layout (vertices = 3) out;
Thus the length of the input array to the Tessellation Control Shader is 3, too. Furthermore, the abstract patch type is triangles,
layout (triangles, equal_spacing, ccw) in;
thus the tessellation coordinate (gl_TessCoord
) is a Barycentric coordinate. Change the interpolation:
vec2 interpolate2D(vec2 v0, vec2 v1, vec2 v2)
{
return v0*gl_TessCoord.x + v1*gl_TessCoord.y + v2*gl_TessCoord.z;
}
void main()
{
finalpos = interpolate2D(EsPos[0], EsPos[1], EsPos[2]);
// [...]
}