Graphics Reference
In-Depth Information
to the output resource is shown in Listing 12.7. This final step must mask off the perimeter
threads to ensure that they don't modify the contents of the output resource. In theory, all of
these values would be overwritten by the other thread groups being executed, but depend-
ing on the order that the thread groups are processed in it may lead to invalid data being
written structured buffer. The writing of the output data is the first and only access that is
performed through the unordered access view. This is a good property to replicate in other
algorithms, as it indicates that the device memory has a minimum number of accesses.
// Finally store the updated height and flow values only for the threads
// within the actual group (i.e. excluding the perimeter). Otherwise there would
// be a double calculation for each perimeter texel., making the simulation
// inaccurate!
if ( ( GroupThreadlD.x > 0 ) S8 ( GroupThreadlD.x < padded_x - 1 )
&& ( GroupThreadlD.y > 0 ) && ( GroupThreadlD.y < padded_y - 1 ) )
{
NewWaterState[textureindex] = loadedpoints[GroupIndex];
}
Listing 12.7. Storing the results of the simulation to the output structured buffer.
Rendering the Fluid Simulation
After the simulation state is updated,
the surface of the fluid can be rendered.
However, by this point all of the hard
work has already been completed and
we simply need to read the height values
in the structured buffer that contains the
current state of the simulation. The pipe-
line layout is shown in Figure 12.8.
We perform this height lookup in
the vertex shader using the same calcula-
tion that was used in the compute shader
to find the location within the structured
buffer to load. The difference in this case
is that we use input vertex attributes to
determine which point in the 2D simu-
lation grid each vertex should represent.
To demonstrate the boundaries of each
thread group that is used in the simula-
tion, we color the vertices with one of
Figure 12.9. The final result of the rendered fluid surface.
Search WWH ::




Custom Search