Tessellation Control Shader

From OpenGL.org
Revision as of 03:04, 26 July 2013 by Alfonse (talk | contribs) (Inputs: Data moved from the separate page.)

Jump to: navigation, search
Tessellation Control Shader
Core in version 4.0
Core ARB extension ARB_tessellation_shader

The Tessellation Control Shader (TCS) is a Shader program written in GLSL. It sits between the Vertex Shader and the Tessellation Evaluation Shader.

The TCS controls how much tessellation a particular patch gets; it also defines the size of a patch, thus allowing it to augment data. It can also filter vertex data taken from the vertex shader. The main purpose of the TCS is to feed the tessellation levels to the Tessellation primitive generator stage, as well as to feed patch data (as its output values) to the Tessellation Evaluation Shader stage.

Execution model





Output patch size



layout(vertices = patch_size​) out;



All inputs from vertex shaders to the TCS are aggregated into arrays, based on the size of the input patch. The size of these arrays is the number of input patches provided by the patch primitive.

Every TCS invocation for an input patch has access to the same input data, save for gl_InvocationID​ (see below) which will be different for each invocation. So any TCS invocation can look at the input vertex data for the entire input patch.

User-defined inputs can be declared as unbounded arrays:

in vec2 texCoord[];


TCS inputs may have interpolation qualifiers on them. They have no actual function however.

V · E

Tessellation Control Shaders provide the following built-in input variables:

 in int gl_PatchVerticesIn;
 in int gl_PrimitiveID;
 in int gl_InvocationID;
the number of vertices in the input patch.
the index of the current patch within this rendering command.


in gl_PerVertex
  vec4 gl_Position;
  float gl_PointSize;
  float gl_ClipDistance[];
} gl_in[gl_MaxPatchVertices];

Note that just because gl_in​ is defined to have gl_MaxPatchVertices​ entries does not mean that you can access beyond gl_PatchVerticesIn​ and get reasonable values. These variables have only the meaning the vertex shader that passed them gave them.


TCS output variables are passed directly to the Tessellation Evaluation Shader, without any form of interpolation (that's the TES's main job). These can be per-vertex outputs and per-patch outputs.


out vec2 vertexTexCoord[];



Patch variables


patch out vec4 data;

Any TCS invocation can write to a per-patch output; indeed, all TCS invocations will generally write to a per-patch output. As long as they all write the same value, everything is fine.

Built-in outputs

V · E

Tessellation Control Shaders have the following built-in patch output variables:

patch out float gl_TessLevelOuter[4];
patch out float gl_TessLevelInner[2];


As with any other patch​ variable, multiple TCS invocations for the same patch can write to the same tessellation level variable, so long as they are all computing and writing the exact same value.

TCS's also provide the following optional per-vertex output variables:

out gl_PerVertex
  vec4 gl_Position;
  float gl_PointSize;
  float gl_ClipDistance[];
} gl_out[];

The use of any of these in a TCS is completely optional. Indeed, their semantics will generally be of no practical value to the TCS. They have the same general meaning as for vertex shaders, but since a TCS must always be followed by an evaluation shader, the TCS never has to write to any of them.







Note: This is different from the restrictions on barrier()​ in Compute Shaders.






See also