Help end child hunger

GLSL Tutorial – Tessellation

Prev: Primitive Assembly Next: Geometry Shader

Tessellation is a stage in the graphics pipeline that receives patches as inputs and generates new primitives which can be points, lines, or triangles.

A patch is an array of vertices whose attributes are computed by the vertex shader. For the vertex shader it is business as usual, it receives the patch vertices as inputs and outputs new vertices. The tessellation shaders receive the array of transformed vertices, i.e. the patch, and commonly subdivides it in smaller primitives.

As opposed to other OpenGL primitive types, patches have a user-defined number of vertices. Function glPatchParameteri is used to set this value, which remains constant in draw calls, as follows:

glPatchParameteri( GL_PATCH_VERTICES, verticesPerPatch );

where verticesPerPatch must be an integer in [1, GL_MAX_PATCH_VERTICES]. This constant can be queried with glGetIntegerv.

The tessellation pipeline has three sub-stages: tessellation control, primitive generation, and tessellation evaluation. The first and last sub-stages are programmable, i.e. we can write shaders for them, whereas the second stage is fixed.

The first stage, the tessellation control shader, receives an array with the vertices of the input patch, and computes the attributes for each of the vertices that make up the output patch, also stored in an array. These shaders are also responsible to write per-patch attributes, which define the subdivision degree of the patch.

There are two types of patches: triangular and quads. Note, however, that the number of vertices in a patch is not related to its type. For instance, it’s possible to have a quad patch defined with a single vertex, or 16 vertices to define a Bézier patch. The usage of the name vertices is actually misleading, it would be better to refer to them as simply data.

The subdivision is controlled by the tessellation levels. These can be set from 0 to GL_MAX_TESS_GEN_LEVEL, a value which can be retrieved with glGetIntegerv. This value is commonly 64.

The tessellation levels control the subdivision of each side of the patch, as well as it’s interior. Hence, we have four outer tessellations for a quad, and three for a triangular patch. There are two inner tessellations levels for a quad, for triangular patches a single inner tessellation level is required.

Note that the shader may skip setting the tessellation levels, in which case, the default tessellation levels will be used. These default values can be queried with glGetIntegerv.

The application can set, and modify, these values as follows:

glPatchParameteri( GL_PATCH_DEFAULT_OUTER_LEVEL, myDefaultOuterLevel );
glPatchParameteri( GL_PATCH_DEFAULT_INNER_LEVEL, myDefaultInnerLevel );

After the vertices have been computed, and the tessellation levels set, we’re ready to go to stage 2, the primitive generation. This stage is fixed function, and its responsible for the actual generation of new vertices inside the patch. Note however that this stage has no knowledge of OUR patch, instead it works on a template patch with coordinates as follows:

The tessellation levels are defined to influence specific areas or edges as shown above.


Prev: Primitive Assembly Next: Geometry Shader

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: