Graphics Reference
In-Depth Information
floating-point textures to manage all of the needed data. However, we can take advantage
of the fact that the flow into one virtual pipe has an equal and opposite flow, depending
on which of the two water columns is using it. This means that we can store only four
flow values for every fluid column, and that the remaining four flow values can be taken
from the neighboring fluid columns. This concept is depicted in Figure 12.3.
This means that together with height data of the simulation, we need a total of five
floating-point variables for each fluid column. Since the maximum number of compo-
nents per-texel in a texture is four, it would be necessary to use two texture resources
together to hold all of the needed data. Instead of doing this, we have chosen to use a
structured buffer resource that can provide all five variables together in a single buffer
element. This allows us to reference the complete state of a fluid column in a single loca-
tion, and we can used a simple array syntax to access the data. Unfortunately, structured
buffers are always 1D in nature, so we will have to manually convert from our 2D grid
coordinates to the appropriate 1D buffer index. In practice this is fairly trivial, since we
will know in advance what the total size of the simulation is, so the compromise does not
introduce a large amount of additional work. Listing 12.1 demonstrates how the struc-
tured buffer is created.
// Here size is the number of elements, and structsize is
// the size of the structure to be used.
m_State.ByteWidth = size * structsize;
m_State.BindFlags = D3D11_BIND_SHADER_RES0URCE | D3D11_BIND_UN0RDERED_ACCESS;
m_State.MiscFlags = D3D11_RES0URCE_MISC_BUFFER_STRUCTURED;
m_State.StructureByteStride = structsize;
m_State.Usage = D3D11_USAGE_DEFAULT;
m_State.CPUAccessFlags = 9;
// here pData is assumed to contain the system memory pointer to
// the initial buffer data.
ID3DllBuffer* pBuffer = 8;
HRESULT hr = m_pDevice->CreateBuffer( &m_State, pData, SpBuffer );
Listing 12.1. Creation of the structured buffer for use in the water simulation.
With the resource type and format selected, we can consider how the state will be
updated during each update phase. Since the current state of the simulation is needed to
calculate the new state, we will need to maintain two individual states. These will be kept
in two identically sized structured buffers, which are created as shown in Listing 12.1.
After each update phase of the simulation, the responsibility of each buffer is reversed
from current to new and vice versa, which allows us to ping-pong the states back and forth
between the two buffers.
Search WWH ::




Custom Search