Graphics Reference
In-Depth Information
Notice that the first phase uses four threads, one for each corner of the 16x16 pixel
group. Each of the four threads reads in a single sample. It then stores the height in group
Results[ ] and stores a 3D position in corners [ ] [ ]. All other threads are idle at this
point. Listing 9.12 shows the code for this.
if(
((GTid.x == 0) && (GTid.y == 0))
||
((GTid.x == 15) && (GTid.y == 0))
||
((GTid.x == 0) && (GTid.y == 15))
||
((GTid.x == 15) && (GTid.y == 15))
)
{
// This is a corner thread, so we want it to load
// its value first
groupResults[GI] = texHeightMap.Load( uint3( DTid.xy, 0 ) ).r;
corners[GTid.x / 15] [GTid.y / 15]
= float3(GTid.x / 15, groupResults[GI] , GTid.y / 15);
// The above will unfairly bias based on the height ranges
corners[GTid.x / 15] [GTid.y / 15]. x /= 64.0f;
corners[GTid.x / 15][GTld.y / 15]. z /= 64.0f;
}
// Block until all threads have finished reading
GroupMemoryBarrierWithGroupSync();
Listing 9.12. Phase one of the compute shader.
Figure 9.18 depicts the next phase, where the same four threads continue to process
the corner points. In this instance, they need to know about their neighboring corners, so
that they can generate the cross-product and hence a normal vector for each corner en-
tirely ALU work. Concurrently, the other 252 threads can be reading in the remaining
height map samples. Listing 9.13 shows this in action.
if ((GTid.x == 0) && (GTid.y == 0))
{
rawNormals[0] [0] = normalize(cross
(
corners[0][1] - corners[0][0],
corners[l] [0] - corners[0][0]
));
}
else if ((GTid.x == 15) && (GTid.y == 0))
Search WWH ::




Custom Search