291

Geometry Shader

Concepts and Examples

The geometry shader is a new capability in shaders, introduced in late 2006

with the release of Shader Model 4 to take advantage of the ever-growing

capability of high-end graphics cards. It adds to the programmer’s graphics

capabilities by providing tools to expand the basic model geometry to include

more or dierent graphics primitives than were initially dened. Thus, geom-

etry shaders should really be called “geometry creators” or “geometry expand-

ers.” The place of the geometry shader in the graphics pipeline is shown in Fig-

ure 12.1, where “vertex processing” can include a vertex shader, tessellation

control shader, or tessellation evaluation shader.

The geometry expansion that is provided by the geometry shader has

many uses. One is in using the input geometry to create additional geome-

try, such as silhouee edges, shrunk triangles, or hedgehog plots. Another is

in managing level of detail (LOD). The LOD, shrunk triangles, and silhouee

edges examples are discussed later in this chapter, and hedgehog plots are

discussed in Chapter 15.

12

292

12. Geometry Shader Concepts and Examples

What Does the Geometry Shader Do?

If you use a geometry shader, your application or your vertex shader can gen-

erate all the familiar topology types plus a few new ones that we will cover

below:

• Points.

• Lines.

• Line strips.

• Line loops.

• Lines with adjacency.

• Line strips with adjacency.

• Triangles.

• Triangle strips.

Figure 12.1. The geometry shader in the graphics pipeline.

293

What Does the Geometry Shader Do?

• Triangle fans.

• Triangles with adjacency.

• Triangle strips with adjacency.

• Quads.

• Quad strips.

Any of these topologies can be used by

the application, but geometry shaders have

a limited number of topologies that they can

accept. These are points, lines, lines with

adjacency, triangles, or triangles with adja-

cency.

Thus, the primitives used by the appli-

cation sometimes need to be internally con-

verted. You, the application programmer, don’t need to know about this. But,

you, the shader writer, do.

On the output side, the geometry shader then generates points, line strips,

or triangle strips, and feeds them on to the rest of the graphics pipeline.

There needn’t be any correlation between geometry shader input type

and geometry shader output type. Points can generate triangles, triangles

can generate triangle strips, and so on. In the silhouee example later on in

this chapter, the input is the new “triangles with adjacency” graphics primi-

tive, while the output is simply lines. This is described more visually in Fig-

ure 12.2.

Figure 12.2. The kinds of processing geometry shaders can do.

Geometry shaders are not intended

to provide a general-purpose LOD

capability because (1) they have

a limit to the number of new

vertices that they can create, and

(2) they have limited access to the

surrounding vertex information

that would be needed for, say,

subdivision surfaces. Tesselation

shaders are meant for this and are

described in the Chapter 13.

Start Free Trial

No credit card required