Graphics Reference
In-Depth Information
void VSMain( in float4 VPos : POSITION // Binds variable to Input
// Assembler
in uint VID : SV_VertexID // Binds variable to a
// system generated value
out float4 OPos : SV_Position // Tells the pipeline to
// interpret the value as the
// output vertex position
)
{
OutPos = mul( VPos, WVPMatrix );
}
Listing 6.11. Using semantics in a vertex shader.
In the example given in Listing 6.11, applying the POSITION semantic to the input
allows the shader to specify which element from a vertex it requires. Thus, the input as-
sembler will use the input layout to determine the proper byte offset within a vertex that is
required to read in the appropriate element. In the same way, values passed from one shader
stage to another can be identified with semantics. This allows the runtime to ensure that the
proper output value is matched to a given input parameter.
System-value semantics, denoted with an SV_ prefix, are instead used to accept a
value from the runtime, or to pass a value to the runtime. In the example shader, SV_
VertexID specifies that the parameter should be set to a value that indicates the index of the
vertex within the vertex buffer. The SVPosition semantic indicates that the value being
output is the final transformed vertex position that should be used for rasterization. For a
full listing of supported system-value semantics, consult the HLSL reference section of the
SDK documentation. You can also refer to Chapter 3 for more information on the meaning
and usage of each of these system value semantics.
6.3.11 Attributes
Attributes are special tags that can be inserted into HLSL code to modify the assembly code
emitted by the compiler, or to control how the shader is executed by the pipeline. Some
are purely optional, while others are required for certain shader types. In all cases, they are
used by being declared immediately before the function, branch, loop, or statement they
are affecting. Table 6.3 contains a list of all attributes, with a short description.
Search WWH ::




Custom Search