O'Reilly logo

Graphics Shaders, 2nd Edition by Steve Cunningham, Mike Bailey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

315
Tessellation Shaders
Tessellation in computer graphics is a process that divides a surface into a
smoother mesh of triangles. An example of this kind of tessellation is shown
in Figure 13.1.
What Are Tessellation Shaders?
Tessellation shaders are one of the stages available in OpenGL to create the
geometry for a scene. New with OpenGL 4.0, they interpolate geometry to cre-
ate additional geometry that can
13
316
13. Tessellation Shaders
Let you perform adaptive subdivision based on a variety of criteria such
as size or curvature,
Let you provide coarser models that can be rened in the GPU, giving
you a kind of geometric compression,
Let you apply detailed displacement maps without supplying equally
detailed geometry,
Let you adapt visual quality to the required level of detail,
Let you create smoother silhouees, or
Let you perform skinning more easily.
Overall this lets you increase the quality of your nal images. So why not
just add more geometric detail right in your application program? The best
answer is that tessellation shaders have access
to all the information in the graphics pipe-
line, and thus can adapt to the display situa-
tion. Tessellation shaders are at their very best
when they choose tessellation parameters, not
statically but dynamically, based on the current
transformations, curvatures, screen coverage,
etc.
How does the tessellation shader t into
our overall shader world? The tessellation
stage is applied between the vertex shader
(Chapter 7) and the next shader stage in the
pipeline, which could be either the geometry
shader (Chapter 12) or the fragment shader
(Chapter 8). This makes intuitive sense, because
the vertex shader modies vertices individu-
ally with no reference to the primitives they lie
in. The tessellation shader amplies a single
primitive, and the geometry shader can pro-
vide additional primitives based on the original
primitive. The GLSL view of the graphics pipe-
line is shown here in Figure 13.2 with the tessellation stage highlighted.
When we say “tessellation shader,” we generally mean both the tessella-
tion control shader (TCS) and the tessellation evaluation shader (TES), unless
we say otherwise.
Figure 13.1. A polygon-interpolating mesh tes-
sellation from a GLSL shader.
317
What Are Tessellation Shaders?
Tessellation Shaders or Geometry Shaders?
Both geometry shaders and tessellation shaders are capable of creating new
geometry from existing geometry, and both have uses in giving you level-of-
detail support, so you might be confused about when to use each type. While
their capabilities are in some ways similar, there are distinct dierences. A
tessellation shader gives you more geometry, but all the new geometry is of
the same sort as you started with—you can get more segments for a line, more
triangles for a triangular patch, or more isolines or quads for a quad patch, but
you always get the same geometry. You should use a tessellation shader when
you need to generate many new vertices and one of the tessellation topologies
will suit your needs, or if your required patch input involves many (more than
six
1
) vertices.
On the other hand, a geometry shader gives some dierent capabilities.
You must use a geometry shader when you need to convert to dierent geom-
etry topologies, such as presented in the silhouee and hedgehog shaders (tri-
Figure 13.2. The full shader pipeline showing the place of the tessellation shaders.
1. Why six? The input to a geometry shader can have as many as six vertices when you use the
triangles-with-adjacency topology.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required