Graphics Reference
In-Depth Information
value that is returned in out-of-range accesses. In either case, this is undesirable and should
be avoided. The process for calculating these delta values is shown in Listing 12.4.
// Initialize the flow variable to the last frames flow values
float4 NewFlow = float4( 0.0f, 0.0f, 0.0f, 0.0f );
// Check for 'not J right edge
if ( ( GroupThreadlD.x < padded_x - 1 ) && ( location. x < totalsize_x - 1 ) )
{
NewFlow. x = ( loadedpoints[GroupIndex+1].Height
- loadedpoints[GroupIndex].Height );
// Check for 'not' bottom edge
if ( ( GroupThreadID.y < padded_y - 1 ) && ( location.y < totalsize_y - 1 ) )
{
NewFlow.y = ( loadedpoints[(GroupIndex+l) + padded_x] .Height
- loadedpoints[GnoupIndex].Height );
}
}
// Check for f not' bottom edge
if ( ( GroupThreadID.y < padded_y - 1 ) && ( location.y < totalsize_y - 1 ) )
{
NewFlow.z = loadedpoints[GroupIndex+padded_x].Height
- loadedpointsfGroupIndex].Height;
// Check for f not J left edge
if ( ( GroupThreadlD.x > 0 ) && ( location.x > 0 ) )
{
NewFlow.w = ( loadedpoints[GroupIndex + padded_x - 1]. Height
- loadedpoints[GroupIndex].Height );
}
}
Listing 1 2.4. Calculating the height delta between fluid columns.
The delta height values can then be combined, using a number of constants to rep-
resent the physical properties of the simulation. These constants are declared as literal
constants in the shader, but they could just as easily be loaded into the shader through a
constant buffer if they will change over the lifetime of the application. The calculation of
the new flow values is shown in Listing 12.5, where the NewFlow variable is updated to
hold the new flow values, instead of the delta heights. The new flow value is a combination
of the existing flow in the virtual pipe from the previous simulation step and the additional
flow induced by the delta in height values, and is also based on the size of the time step
that has passed since the last update. The application provides the elapsed frame time in
the TimeFactors. x parameter, and a minimum selection is made between the actual time
Search WWH ::




Custom Search