Graphics Reference
In-Depth Information
Listing 9.6) can be done as a simple mean average of the four corners. Two things to note
about this section are that for the edge patches where the application will have clamped the
inputs, the midpoint is actually the midpoint of the edge, and not the tile; second the index-
ing into the ip[ ] array matches Figure 9.5, which was part of step 1.
float3 ComputePatchMidPoint(float3 cp0, float3 cp1, float3 cp2, float3 cp3)
{
return (cp0 + cpl + cp2 + cp3) / 4.0f;
}
Listing 9.6. Definition of ComputePatchMidPoint().
With an array of five midpoints generated, these can be compared against the cam-
era position to generate five individual scalars representing the raw LOD for each of the
patches. Of particular interest is that the raw values are continuous in nature (as continuous
as IEEE-754 floating point values can be!) and there is only clamping between the minLOD
and maxLOD values provided by the application. This, when combined with the partition-
ing attribute set to f ractional_odd is all that is necessary to ensure a smooth transition
between levels of detail on a frame-by-frame basis.
The ComputePatchLOD() function, shown in Listing 9.7, is very naive and could be
greatly improved, but for the purpose of an example it works well. The helper function sim-
ply scales linearly between application-provided minimum and maximum levels according
to the distance from the camera—the further away, the lower the detail.
float ComputeScaledDistance(float3 from, float3 to)
{
// Compute the raw distance from the camera to the midpoint of this patch
float d = distance( from, to );
// Scale this to be 0.0 (at the min dist) and 1.0 (at the max dist)
return (d - minMaxDistance.x) / (minMaxDistance.y - minMaxDistance.x);
}
float ComputePatchLOD(float3 midPoint)
{
// Compute the scaled distance
float d = ComputeScaledDistance( cameraPosition.xyz, midPoint );
// Transform this 0.0-1.0 distance scale into the desired LOD's
// note: invert the distance so that close = high detail, far = low detail
return lerp( minMaxLOD.x, minMaxLOD.y, 1.0f - d );
}
Listing 9.7. Definition of ComputePatchLOD().
Search WWH ::




Custom Search