Game Development Reference
In-Depth Information
Chapter 17
Introduction to Vertex
Shaders
A vertex shader is a program executed on the graphics card's GPU that
replaces the transformation and lighting stage in the fixed function
pipeline. (This is not 100 percent true, as vertex shaders can be emu-
lated in software by the Direct3D runtime if the hardware does not
support vertex shaders.) Figure 17.1 illustrates the section in the pipe-
line that the vertex shader replaces.
Figure 17.1:
The vertex
shader replaces
the lighting and
transformation
stage of the fixed
function pipeline.
From Figure 17.1 we see that vertices are input into the vertex shader
in local coordinates and the vertex shader must output lit (colored) ver-
tices in homogeneous clip space . (We didn't delve into the details of the
projection transformation in this topic for simplicity reasons. But the
space to which the projection matrix transforms vertices is called
homogeneous clip space. Therefore, to transform a vertex from local
space to homogenous clip space, we must apply the following sequence
of transformations: world transformation, view transformation, and pro-
jection transformation, which are done by the world matrix, view
matrix, and projection matrix, respectively.) For point primitives, a ver-
tex shader can also be used to manipulate the vertex size per vertex.
Because a vertex shader is a custom program that we write (in
HLSL), we obtain a huge amount of flexibility in the graphical effects
we can achieve. For example, with vertex shaders we can use any
293
Search WWH ::




Custom Search