• Create Account

### #ActualAks9

Posted 27 October 2012 - 10:04 AM

From my understanding, the main function is called once per control point.

Well, not exactly. A tessellation control shader is invoked once per vertex of the output patch.

And it appears OpenGL supplies the shader with the built in variable 'gl_InvocationID' to store the index of the control point (and its attributes) for each invocation.

That's correct.

So if your input patch is, for example, a triangle, gl_InvocationID will be 0, 1, and 2 in each subsequent call (though the calls could occur in a different order)

No. The number of invocations is equal to the number of vertices in the output patch. That is defined by layout( vertices = ... ) out; qualifier in the TCS. So, for example, if your input patch contains 3 vertices, and TCS contains the following qualifier: layout (vertices = 4) out; you'll actually get four invocations.

My source of confusion is the first 3 lines of code make sense for a 'per-control-point' operation (it uses the gl_InvocationID), but the remaining code seems to be a 'per-patch' operation (it uses all three indices: 0,1,2). The tessellation levels (to my knowledge) correspond to the entire patch. So what I think is happening here, is that the tessellation levels will be improperly calculated twice, and then on the 3rd invocation, (after all the WorldPos_ES_in values are initialized) the correct result will be obtained.

The output of the TCS are both per-control-point (i.e. per-vertex) and per-patch variables (for the output patch). Per vertex variable must be set using gl_InvocationID index. Per-patch variables should be set only by one invocation. So, what you have seen in the tutorial is not quite right. It works, but it is not clean, because all invocations do the same job, and overwrites previously written values. I usually use invocation with ID=0 to set per patch output variables.

if(gl_InvocationID == 0)
{
gl_TessLevelOuter[0] = ...;
gl_TessLevelOuter[1] = ...;
gl_TessLevelOuter[2] = ...;
gl_TessLevelOuter[3] = ...;

gl_TessLevelInner[0] = ...;
gl_TessLevelInner[1] = ...;
//...


I hope this "sharpen" your understanding of TCS.

### #1Aks9

Posted 27 October 2012 - 10:00 AM

From my understanding, the main function is called once per control point.

Well, not exactly. A tessellation control shader is invoked once per vertex of the output patch.

And it appears OpenGL supplies the shader with the built in variable 'gl_InvocationID' to store the index of the control point (and its attributes) for each invocation.

That's correct.

So if your input patch is, for example, a triangle, gl_InvocationID will be 0, 1, and 2 in each subsequent call (though the calls could occur in a different order)

No. The number of invocations is equal to the number of vertices in the output patch. That is defined by layout( vertices = ... ) out; qualifier in the TCS. So, for example, if your input patch contains 3 vertices, and TCS contains the following qualifier: layout (vertices = 4) out; you'll actually get four invocations.

My source of confusion is the first 3 lines of code make sense for a 'per-control-point' operation (it uses the gl_InvocationID), but the remaining code seems to be a 'per-patch' operation (it uses all three indices: 0,1,2). The tessellation levels (to my knowledge) correspond to the entire patch. So what I think is happening here, is that the tessellation levels will be improperly calculated twice, and then on the 3rd invocation, (after all the WorldPos_ES_in values are initialized) the correct result will be obtained.

The output of the TCS are both per-control-point (i.e. per-vertex) and per-patch variables (for the output patch). Per vertex variable must be set using gl_InvocationID index. Per-patch variables should be set only by one invocation. So, what you have seen in the tutorial is not quite right. It works, but it is not clean, because all invocations do the same job, and overwrites previously written values. I usually use invocation with ID=0 to set per patch output variables.


[font=Courier][size=1]       if([/size][/font][font=Courier][size=1]gl_InvocationID == 0[/size][/font][font=Courier][size=1])[/size][/font]
[font=Courier][size=1]	   [/size][/font][size=1]{[/size]
[indent=1][size=1]			    [/size][size=1]gl_TessLevelOuter[0] = ...; [/size][/indent]
[indent=1][size=1]gl_TessLevelOuter[1] = ...; [/size][/indent]
[indent=1][size=1]gl_TessLevelOuter[2] = ...; [/size][/indent]
[indent=1][size=1]gl_TessLevelOuter[3] = ...; [/size][/indent]

[indent=1][size=1]gl_TessLevelInner[0] = ...; [/size][/indent]
[indent=1][size=1]gl_TessLevelInner[1] = ...;[/size][/indent]
[font=Courier][size=1]	   //...[/size][/font]


I hope this "sharpen" your understanding of TCS.

PARTNERS