Game Development Reference

In-Depth Information

Figure 6.3.
The choice of the grid cell size of a spatial hash has implications for the query

area of a fluid particle: larger cells (left) versus smaller cells (right). Smaller grid cell sizes

imply a smaller search volume, and thus a smaller amount of potential neighbors visited.

Note, however, that the amount of grid cells intersecting the volume increases, having a

negative impact on efficiency.

minimizes the chance of hash collisions. Choosing a larger number of hash buck-

ets is usually not a problem, as the memory footprint of the hash table is small

compared to the footprint of the list of fluid particles in the spatial hash.

The second choice pertains to the resolution of the spatial hash. The higher

the resolution of the spatial hash, the smaller the grid cells. This means the total

volume of grid cells intersecting the influence area of a particle decreases, so a

particle has a smaller volume to search for neighboring particles, as depicted in

Figure 6.3. For example, a grid cell size equal to 2
h
means that 8 grid cells per

particle are queried for neighbors, with a total volume of (4
h
)
3
=64
h
3
, while

agridcellsizeequalto
h
implies that 27 grid cells have to be queried, with a

total volume of (3
h
)
3
=27
h
3
. The trade-off is that the amount of grid cells in-

tersecting the influence area of a particle increases, so the amount of hash indices

calculated per particle also increases. Whether the cost of calculating the extra

hash indices plus the associated cache misses of retrieving different hash buckets

is less than the efficiency gained by visiting a smaller number of potential neigh-

bors depends on the platform and characteristics of the simulated scenario, i.e.,

the average number of particles residing in a single hash bucket. Therefore, the

choice of spatial hash resolution should always be based on performance profiles

of the intended target platform.

The third choice that influences
q
is related to the fluid simulation itself. To

minimize
q
, we can increase the gas constant
k
used for determining the pres-

sure. This separates the fluid particles as much as possible. The fluid becomes

less compressible in central areas, which is beneficial for simulating water, but

it decreases the stability of particles on the fluid surface. Decreasing external

forces, like gravity pushing down on the fluid, may have a comparable effect, but