Graphics Reference
In-Depth Information
// Determine the appropriate LOD for this patch
float dist[] =
{
// Main quad
ComputePatchLOD( ntidPointsfaf )
// +x neighbor
, ComputePatchLOD( midPoints[l] )
// +z neighbor
, ComputePatchLOD( midPoints[2] )
// -x neighbor
, ComputePatchLOD( midPoints[3] )
// -z neighbor
, ComputePatchLOD( midpoints [4] )
};
// Set it up so that this patch always has an interior matching
// the patch LOD.
o.insideTesselation[0] =
o.insideTesselation[l] = dist[0];
// For the edges its more complex as we have to match
// the neighboring patches. The rule in this case is:
//
// - If the neighbor patch is of a lower LOD we
// pick that LOD as the edge for this patch.
//
// - If the neighbor patch is a higher LOD then
// we stick with our LOD and expect them to blend down
// towards us
o.edgeTesselation[0] = rnin( dist[0], dist[4] );
o.edgeTesselation[l] = min( dist[0], dist[3] );
o.edgeTesselation[2] = min( dist[0], dist[2] );
o.edgeTesselation[3] = min( dist[0], dist[l] );
return o;
}
Listing 9.5. Hull shader constant function.
The code in Listing 9.5 can be divided into three stages of execution. First, the tile be-
ing rendered and its 4 neighbors have their midpoints computed. Second, the distance from
each midpoint to the camera is used to generate a "raw" level of detail for each of the 5
patches. And finally, these LOD values are assigned to the 6 output values that Direct3D
expects (2 inner factors, SV_InsideTessFactor and 4 edge factors, SV_TessFactor).
The control points input into this stage are all in world space, which is the only
transformation that the vertex shader performs. Thus, ComputePatchMidPoint() (see
Search WWH ::




Custom Search