O'Reilly logo

OpenGL Insights by Christophe Riccio, Patrick Cozzi

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

An Introduction to Tessellation
Shaders
Philip Rideout and Dirk Van Gelder
6.1 Introduction
Tessellation shaders open new doors for real-time graphics programming. GPU-
based tessellation was possible in the past only through trickery, relying on multiple
passes and misappropriation of existing shader units.
OpenGL 4.0 finally provides first-class support for GPU tessellation, but the new
shading stages can seem nonintuitive at first. This chapter explains the distinct roles
of those stages in the new pipeline and gives an overview of some common rendering
techniques that leverage them.
GPUs tend to be better at “ streamable” amplification; rather than storing an
entire post-subdivided mesh in memory, tessellation shaders allow vertex data to be
amplified on the fly, discarding the data when they reach the rasterizer. The system
never bothers to store a highly-refined ver tex buffer, which would have an impractical
memory footprint for a GPU.
Pretessellation graphics hardware was already quite good at rendering huge
meshes, and CPU-side refinement was often per fectly acceptable for static meshes.
So why move tessellation to the GPU?
The gains are obvious for animation. On a per-frame basis, only the control
points get sent to the GPU, greatly alleviating bandwidth requirements for high-
density surfaces.
Animation isnt the only killer application of subdivision surfaces. Displacement
mapping allows for staggering geometric l evel-of-detail. Previous GPU techniques
87
6
88 IDiscovering
required multiple passes over the geometry shader, proving awkward and slow. Tes-
sellation shaders allow displacement mapping to occur in a single pass [Casta
˜
no 08].
Tessellation shaders can also compute geometric level-of-detail on the fly, which
we’ll explore later in the chapter . Previous techniques required the CPU to resubmit
new vertex buffers when changing the level-of-detail.
6.1.1 Subdivision Surfaces
One of the most compelling uses of GPU tessellation is efficiently rendering Catmull-
Clark subdivision surfaces. Most of these techniques use tessellation shaders to eval-
uate a parametric approximation of the limit surface rather than performing iterative
subdivision. Iterative subdivision can still be done on the GPU but is often better
suited for CUDA or OpenCL.
Pa rametric approximation of Catmull-Clark surfaces (ACC) arose from Charles
Loops research at Microsoft in 2008 [Loop and Schaefer 08], and was subsequently
enhanced to support creases [Kovacs et al. 09]. An excellent overview of the state of
the art can be found in [Ni et al. 09]. This includes a report from Valve, the first
major game developer to use tessellation shaders in this way.
6.1.2 Smoothing Polygonal Data
Catmull-Clark surfaces are not the only way to make good use of tessellation shaders;
game developers may find other surface definitions more attractive. For example,
tessellation can be used to simply smooth out traditional polygonal mesh data.
PN triangles are a popular example of this. An even simpler application is Phong
tessellation, the geometric analogue of a Phong lighting.
6.1.3 GPU Compute
OpenCL or CUDA can be used in conjunction with tessellation shaders for various
techniques. The compute API can b e used for simulation, e.g., hair physics, [Yuksel
and Tariq 10], or it can be used to perform a small number of iterative subdivisions
to “ clean up the input mesh, removing extraordinary vertices before submitting the
data to the OpenGL pipeline [Loop 10].
6.1.4 Curves, Hair, and Grass
Tessellation shaders can also be applied to lines with isoline tessellation, which opens
up several possibilities for data amplification. One is tessellating a series of line seg-
ments into a smooth cubic curve. In this way, application code works only with a
small number of points. Smooth curves are generated entirely on the GPU, either for
3D applications like hair or rope or for 2D applications such as ezier curves from a
drafting tool. Isoline tessellation can also be used to generate multiple curves from a
single cur ve.
6. An Introduction to Tessellation Shaders 89
Figure 6.1. Hairy teapot; lines grown from patches.
Geometry shaders can be used in conjunction with isoline tessellation, which can
be useful for applications such as grass and hair. Figure 6.1 is a screenshot from the
accompanying sample code in which a surface is tessellated into many small polygons,
then extruded into hairs using a geometry shader.
6.1.5 Other Uses
There are also many less obvious uses for tessellation. If a post-tessellated mesh is
sufficiently refined, its geometry can be deformed to simulate lens distortion. These
effects include pincushion warping and panoramic projection. Because GPU raster-
izers can only perform linear interpolation, traditional techniques relying on post-
processing often result in poor sampling.
Figure 6.2 depicts an example of cylindrical warping using tessellation shaders
applied to a cubescape. The vertex buffer sent to the GPU is extremely light because
each cube face is a 4-vertex patch.
Figure 6.2. Cylindrical distortion using tessellation shaders.

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