Graphics Reference
In-Depth Information
The second function attribute allowed by the geometry shader is the instance at-
tribute. This attribute activates the geometry shader instancing mechanism, in which the
primitives passed into the geometry shader are duplicated as many times as specified in the
instance attribute declaration. The geometry shader can then declare the SV_GSInstanceID
(as described above) to provide a unique identifier for the instance. The maximum number
of instances that can be created in this way is 32, which allows for significant data ampli-
fication. This instancing technique is aimed at simplifying geometry shader programs that
need to process geometry for several different outputs, such as when more than one view-
point is being rendered simultaneously. For example, when generating a cube map 1 8
with a
single rendering pass, geometry shader instancing can be used to generate the six copies of
the primitive data, which can then choose the appropriate transformation matrix with the
SV_GSInstanceID system value semantic.
3.8.3 Geometry Shader Stage Processing
Geometry Shader Process Flow
Before we investigate the possible operations that can be performed in the geometry shader,
we must first clarify how it uses the stream objects to produce its output. An example ge-
ometry shader was shown in Listing 3.16, and we will reference it throughout this discus-
sion. As we have seen in the previous sections, the geometry shader program receives input
primitives as an array of vertices. The ordering of the vertices will vary, depending on the
type of input primitive that the pipeline produces prior to the geometry shader stage, as
shown in Table 3.1 and Figure 3.36, respectively.
Once the vertex data is available within the geometry shader, some calculations are
performed to either modify the input vertices or create entirely new ones. The sample
code in Listing 3.16 receives a triangle with adjacency as its input, and then simply passes
the main triangle through to its stream output object, ignoring the adjacency information.
The method used to generate the output primitives is to call the stream output object's
Append () method, which takes an instance of the output vertex structure as its argument.
With three different stream types available (one for triangle strips, one for line strips, and
one for point lists) a series of vertices that are appended to a stream will create different
primitives. For example, if a triangle stream is used, and 5 vertices are appended to it, then
a total of 3 triangles will be created in the "strip" vertex. 1 9
Each additional vertex will gen-
erate a new triangle using the previous two vertices to complete the primitive. The same
methodology exists for the line strip stream object, which would create an additional line
primitive for each additional vertex appended after the first one.
1 8
Cube maps are briefly described in the "Using 2D Textures" section of Chapter 2, "Direct3D 11 Resources."
1 9
This is the same "strip" ordering principle that was explained in the "Input Assembler" section of this chapter.
Search WWH ::




Custom Search