Graphics Reference
In-Depth Information
loadedpoints [ GroupIndex ].Height = 0.0f;
loadedpoints[GroupIndex] .Flow = float4( 0.0f, 8.0f, 0.0f, 0.0f );
// Given your GroupThreadID and the GroupID, calculate the thread's location
// in the buffer.
int3 location = int3( 8, 0, 0 );
location.x = GroupID.x * size_x + ( GroupThreadID.x - 1 );
location. y = GroupID.y * size_y + ( GroupThreadID. y - 1 );
int textureindex = location. x + location.y * totalsize_x;
// Load the data into the GSM
loadedpoints[GroupIndex] = CurrentWaterState[textureindex];
// Synchronize all threads before moving on to ensure everyone has loaded
// their state into the group shared memory.
GroupMemoryBarrierWithGroupSync ();
Listing 12.3. Loading the current simulation state into the group shared memory.
Calculate the updated flow values. After the current simulation state is available in the
GSM, we can start calculating the new state of the simulation. This requires us to determine
how much flow is being induced in each of the virtual pipes between the current thread's
neighbors. As mentioned earlier, we only need to keep track of four flow values for each
thread, and the remaining four flow values can be read from the neighbor fluid column's
flow variables. We will choose the convention that each of the four components of the
float4 flow variable will indicate the flow to the right, to the lower right, to the bottom, and
to the lower left neighbors of the fluid column. This is demonstrated in Figure 12.7, which
also shows how the neighboring fluid columns can be used to read the corresponding flow
values.
With this orientation in mind, we must calculate the delta in height values between
the current fluid column and its neighbors. To do this, we initialize a NewFlow variable to
zero flow. Then we calculate the appropriate
delta value for each component of the vari-
able, but only if the current thread isn't at the
edge of the simulation. It is very important to
ensure that we don't calculate a delta value
with a non-existent fluid column, because we
will either access an incorrect fluid column
(due to the 1D buffer storage) or access an
out-of-range index. The former will probably
introduce erroneous delta values at strange lo-
cations in the simulation, and the latter will
cause a delta value to be created against a zero
Figure 12.7. The flow values, and which virtual
pipes they represent.
Search WWH ::




Custom Search