Graphics Reference
In-Depth Information
Generating Normals and Positions in the Hull Shader
With the equations for calculating the control mesh understood, it is now necessary to fit
these into the Direct3D pipeline. This naturally aligns with the hull shader's responsibili-
ties. It also demonstrates a characteristic introduced as part of Chapter 4, in that the hull
shader stage can amplify or reduce the amount of geometry passed down the pipeline in
this case it is necessary to amplify. From the original three vertices, the hull shader must
output ten positions and six normals.
There is also an interesting design decision to be made when implementing this part
of the algorithm with regard to whether the control mesh is generated by the constant or
by the per-element function. Logically, it fits in the per-element definition, but this results
in code with more branches and conditionals (to determine which equation to apply for a
given input value of SV_OutputControlPointID), which may not be as efficient to execute
on a GPU. And not only may it be less efficient to execute a shader program with branches,
but this branched code will be executed many times, once for each output control point.
To avoid branching, it becomes necessary to place the code in the constant function, which
ensures only a single evaluation.
However, it is important to note that this choice only exists for tessellation algorithms
with small amounts of output data from the hull shader. The constant function is limited
to 128 scalars of output (32 float4s), which must include the tessellation factors. Using
Curved Point Normal Triangles requires at least 48 scalars of output (10 positions and 6
normals, each float 3 in size) before considering additional properties such as texture coor-
dinates, color, or tangent vectors.
Listing 9.19 shows how to implement this using the logical approach of evaluating each out-
put control point with branching. Readers can refer to the PNTrianglesll (AMD & Microsoft)
sample in the DirectX SDK for an implementation that uses the constant function approach.
cbuffer TessellationParameters
{
float4 EdgeFactors;
};
struct VS_0UTPUT
{
float3 position
: WORLD_SPACE_CONTROL_POINT_POSITION;
float3 normal
: WORLD_SPACE_CONTROL_POINT_NORMAL;
};
struct HS_OUTPUT
{ float3 position
: WORLD_SPACE_C0NTR0L_P0INT_P0SITI0N;
float3 normal
: WORLD_SPACE_CONTROL_POINT_NORMAL;
};
Struct HS_CONSTANT_DATA_OUTPUT
Search WWH ::




Custom Search