Graphics Reference
In-Depth Information
triangles, or patches, the individual vertices are all treated the same by the vertex shader.
The processed output from the vertex shader is combined with the primitive information
generated by the input assembler stage later in the pipeline. This simplifies the job of the
vertex shader stage, allowing it to perform the exact same operations regardless of the primi-
tive type.
The vertex shader is located between the input assembler stage and the hull shader
stage. This means that it processes geometry data immediately after it is inserted into the
pipeline, and immediately before any tessellation is performed. Some examples of opera-
tions that are typically performed in the vertex shader are the application of transformation
matrices to input geometry, performing bone-based animation transformations (also known
as vertex skinning 6 ), and performing per-vertex lighting calculations. We will investigate
more precisely what the vertex shader stage is typically used for, and what tools it has at its
disposal throughout the remainder of this section. We begin by considering what data the
vertex shader receives as input followed by the types of processing that it performs, and
then finally consider what data it produces as output.
3.4.1 Vertex Shader Pipeline Input
Since the vertex shader is located directly after the input assembler in the pipeline, it natu-
rally receives its input from there. All of the work done to configure the input assembler's
input layout is intended to make the created vertices match the format expected by the
vertex shader stage's current program. This is why compiled shader byte code is required
as an input when creating an ID3DllInputl_ayout object—to ensure that the assembled
vertices will match what is needed to execute the vertex shader program.
As indicated in the description of the input assembler's output, the vertex shader input
can also use system value semantics in addition to the attributes of the assembled vertices.
The two system value semantics available as inputs to the vertex shader are SV_VertexID
and SV_InstanceID. Both of these provide useful information to the vertex shader pro-
gram, and the developer only needs to include them in the vertex shader input signature to
acquire them. For example, the SV_VertexID can be used as an index into a lookup table
for providing pseudo-random values to the shader. Similarly, the SV_InstanceID can also
be used as an indexing mechanism. However, it is only updated for each instance generated
by the input assembler, so any lookup table values would be applied uniformly to all of the
vertices of an instance. This could be used to introduce variation between instances of a
mesh to make each instance appear more unique.
We have already described how these system value semantics are available to the
vertex shader as inputs. They can also be provided to later stages in the pipeline, but they
6 Vertex skinning is described in detail in Chapter 8, "Mesh Rendering."
Search WWH ::




Custom Search