Game Engine Architecture

(Ben Green) #1
451

10.2.5. The GPU Pipeline


Virtually all GPUs break the pipeline into the substages described below and
depicted in Figure 10.43. Each stage is shaded to indicate whether its function-
ality is programmable, fi xed but confi gurable, or fi xed and non-confi gurable.


10.2.5.1. Vertex Shader


This stage is fully programmable. It is responsible for transformation and
shading/lighting of individual vertices. The input to this stage is a single ver-
tex (although in practice many vertices are processed in parallel). Its position
and normal are typically expressed in model space or world space. The vertex
shader handles transformation from model space to view space via the model-
view transform. Perspective projection is also applied, as well as per-vertex
lighting and texturing calculations, and skinning for animated characters. The
vertex shader can also perform procedural animation by modifying the posi-
tion of the vertex. Examples of this include foliage that sways in the breeze or
an undulating water surface. The output of this stage is a fully transformed
and lit vertex, whose position and normal are expressed in homogeneous clip
space (see Section 10.1.4.4).
On modern GPUs, the vertex shader has full access to texture data—a ca-
pability that used to be available only to the pixel shader. This is particularly
useful when textures are used as stand-alone data structures like height maps
or look-up tables.


10.2.5.2. Geometry Shader


This optional stage is also fully programmable. The geometry shader oper-
ates on entire primitives (triangles, lines, and points) in homogeneous clip
space. It is capable of culling or modifying input primitives, and it can also
generate new primitives. Typical uses include shadow volume extrusion (see


Fixed-FunctionConfigurable

Programmable

Primitive
Assembly

Geometry
Shader Clipping

Screen
Mapping

Triangle
Setup

Triangle
Traversal

Early
Z Test

Pixel
Shader

Merge
/ ROP

Stream
Output

Vertex
Shader

Frame
Buffer

Figure 10.43. The geometry processing and rasterization stages of the rendering pipeline, as
implemented by a typical GPU. The white stages are programmable, the light grey stages are
confi gurable, and the dark grey boxes are fi xed-function.


10.2. The Rendering Pipeline

Free download pdf