0

I am trying to use the tessellation shaders in OpenGL ES 3.2, and have tried to follow 2 different tutorials without success.

I am currently drawing a flat rectangle, the goal is to elevate its surface. I receive the vertices in the vertex shader:

#version 320 es

layout (location = 0) in vec3 position;

out vec3 v_position;

uniform mat4 model_matrix;
uniform mat4 mvp_matrix;

void main() {
    vec4 pos = vec4(position, 1.0);
    v_position = vec3(model_matrix * pos);
    gl_Position = mvp_matrix * vec4(position, 1.0);
}

Attempt to tessellate in the tessellation control shader:

#version 320 es

layout (vertices = 3) out;

in vec3 v_position[];

out vec3 t_position[];

void main()
{
    // Set the control points of the output patch
    t_position[gl_InvocationID] = v_position[gl_InvocationID];

    // Calculate the tessellation levels
    gl_TessLevelOuter[0] = 3.0;
    gl_TessLevelOuter[1] = 3.0;
    gl_TessLevelOuter[2] = 3.0;
    gl_TessLevelInner[0] = gl_TessLevelOuter[2];
}

And then try to make a minimum working evaluation shader:

#version 320 es

layout(triangles, equal_spacing, ccw) in;

in vec3 t_position[];

out vec3 f_position;

uniform mat4 mvp_matrix;

void main() {
    f_position = t_position[0];
    gl_Position = mvp_matrix * vec4(f_position, 1.0);
}

I call these shaders using glDrawArrays(GL_PATCHES, 0, vertex_num). However currently I see no output when attempting to tessellate. if instead I remove the tessellation shaders and draw with only the vertex and fragment shaders (after tweaking so that they compile). I do see the rectangle mesh, so I am confident the issue is in my shaders.

I am not getting compilation errors, and calling glGetError() reports no error, so it's my logic that I think is wrong.

Edit:

Immediately prior to the draw call I also do:

glPatchParameteri(GL_PATCH_VERTICES, 3);
genpfault
  • 51,148
  • 11
  • 85
  • 139
Makogan
  • 8,208
  • 7
  • 44
  • 112
  • You have to set [`glPatchParameteri( GL_PATCH_VERTICES, 3 )`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glPatchParameter.xhtml) before the draw call. – Rabbid76 Nov 14 '18 at 19:22
  • I did, sorry forgot to mention it in post – Makogan Nov 14 '18 at 19:40
  • What about `f_position = t_position[0]*gl_TessCoord.x + t_position[1]*gl_TessCoord.y + t_position[2]*gl_TessCoord.z;` – Rabbid76 Nov 14 '18 at 19:51
  • Still no output – Makogan Nov 14 '18 at 19:54
  • Nvm that seems to have been the fix, my IDE just cached the previous verison of the shader and was not updating the change. – Makogan Nov 14 '18 at 20:07
  • Can you please explain what I was doing wrong? – Makogan Nov 14 '18 at 20:07
  • 1
    @Makong At triangle tessellation `gl_TessCoord` contains the [Barycentric coordinate](https://en.wikipedia.org/wiki/Barycentric_coordinate_system#Barycentric_coordinates_on_triangles) of the tessellated position on the triangle. You have to define how the new vertex coordinate is calculated. See [Tessellation - Triangles](https://www.khronos.org/opengl/wiki/Tessellation#Triangles). – Rabbid76 Nov 14 '18 at 20:16

0 Answers0