I'm using hardware tessellation to render a terrain mesh with variable LOD.

I have this snippet on my tessellation control shader:

int edge1 = gl_InvocationID;
int edge2 = (gl_InvocationID + 1) % 3;
tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[edge1], gl_TessLevelOuter[edge2]), 1.0);

This should compute a color for the control point based on the tessellation level of the two edges that intersect on the point (using quad patches).

It's all working fine except for this: gl_TessLevelOuter[edge1] and gl_TessLevelOuter[edge1].

This indexing always return 0 (I've tried using it directly as a color). To test the problem, I tried this: gl_TessLevelOuter[gl_InvocationID]. It also has the same behavior.

If I do something like this:

if(gl_InvocationID == 0) {
    tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[0], gl_TessLevelOuter[1]), 1.0);
else if(gl_InvocationID == 1) {
    tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[1], gl_TessLevelOuter[2]), 1.0);
else if(gl_InvocationID == 2) {
    tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[2], gl_TessLevelOuter[3]), 1.0);
else if(gl_InvocationID == 3) {
    tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[3], gl_TessLevelOuter[0]), 1.0);

then it all works as expected.

I've checked the OpenGL specification and couldn't find anything about undefined behavior when indexing gl_TessLevelOuter by a non-constant value.

So the question is, am I misunderstanding something, doing something against the specification or is it a GL implementation bug?

I'm using an AMD Radeon HD 6700 with updated drivers, and there are no warnings compiling the shaders. (I've never seen a single shader compiler warning though, so not sure if that's another problem)

  • $\begingroup$ dynamic indexing can cause issues in some drivers $\endgroup$ – ratchet freak Nov 17 '15 at 10:21
  • $\begingroup$ Well, I guess that's the case, can't find a better explanation. $\endgroup$ – MadEqua Nov 23 '15 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.