Graphics Reference
In-Depth Information
Step 2: The Hull Shader
The previous step was all about generating the source data and binding it to the pipeline, in
preparation for this step and the one after it. It is here that the first code is written to directly
implement the algorithm described.
The introduction to Chapter 4 described the hull shader as being comprised of two
pieces of HLSL—the patch constant function and the control point shader. Listing 9.4 im-
plements our hull shader.
struct VSJXJTPUTww
{
float3 position : WORLD_SPACE_C0NTROL_POINT_P0SITION;
float2 texCoord : CONTROL_POINT_TEXCOORD;
};
struct HS_OUTPUT
{
float3 position : C0NTROL_POINT_P0SITION;
float2 texCoord : CONTROL_POINT_TEXCOORD;
};
[domain("quad")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(4)]
[patchconstantfunc("hsPerPatch")]
HS_OUTPUT hsSimple
(
InputPatch<VS_OUTPUT, 12> p,
uint i : SV_OutputControlPointID
)
{
HS_OUTPUT o = (HS_OUTPUT)0;
o.position = p[i].position;
o.texCoord = p[i].texCoord;
return o;
}
Listing 9.4. The hull shader control point function.
Listing 9.4 is the control point shader, which due to the attributes applied is also the
main entry point as far as Direct3D is concerned. At first glance, the body of this shader
appears to be a simple pass-through/identity operation. While this is partially, true a subtle
Search WWH ::




Custom Search