Graphics Reference
In-Depth Information
Figure 9.20. Compute shader phase four.
As mentioned earlier, Figure 9.20 shows phase four. With a plane available, it is neces-
sary to process each of the raw heights as originally loaded from the height map. Each thread
takes a single height. It then computes the distance between this sample and the previously-
computed plane, replaces the original raw height value.
// Following fragment of CS relies on this
// utility function:
float ComputeDistanceFromPlane(float4 plane, float3 position)
{
return dot(plane.xyz,position) - plane.w;
}
// Begin phase 5 of the compute shader:
groupResults[GI] = ComputeDistanceFromPlane
(
plane
, float3
(
(float)GTid.x / 15.0f
, groupResults[GI]
, (float)GTid.y / 15.0f
)
);
GroupMemoryBarrierWithGroupSync();
Listing 9.15. Phase four of the compute shader.
Figure 9.21 shows the final phase of the algorithm. This phase takes all of the height
values and computes the standard deviation from the surface of the plane. This single value
Search WWH ::




Custom Search