Graphics Reference
In-Depth Information
Figure 9.21.
Computer shader phase five.
is a good metric of how coplanar the 256 individual height samples are—lower values imply
a flatter surface, and higher values imply a noisier and more varying patch. This single value
and the plane's normal vector are written out as a float4 in the output texture, so 256 height
map samples have been reduced to four numbers. Listing 9.16 shows the last phase of the
computer shader.
if(GI == 0)
{
//
Let
the first thread compute the
standard
deviation for
//
this patch. The 'average'
is
really just going
to
be 0.0
// as we want the deviation from the plane and any point on the
// plane now
has
a 'height' of zero.
float stddev
= 0.0f;
for(int i
= 0;
i
< 16*16; ++i)
stddev
+=
pow(groupResults[i]
,2)
;
stddev
/= ((16.0f * 16.0f) - 1.0f);
stddev
=
sqrt(stddev);
// Then write the normal vector and standard deviation
//
to
the output
buffer
for
use
by
the
Domain and Hull Shaders
bufferResults[uint2(Gid.x,
Gid.y)] =
float4(plane.xyz, stddev);
}
Listing 9.16.
Phase five of the compute shader.
Integrating the Compute Shader
The previous section details the actual compute shader that implements our algorithm, but
the application must still coordinate this work.
Search WWH ::
Custom Search