Game Development Reference
Figure 6.7. The three different stages used for our performance measurements in Ta-
ble 6.2. From left to right, we have the stage 1 in which fluid particles fall into a glass,
stage 2 with fluid particles at rest and stage 3 in which artificial waves are generated. Parti-
cle colors range from blue to green to red to denote areas of low, medium and high density
respectively (see Color Plate III).
construction time of the spatial hash and evaluation time of the SPH equations.
The results are listed in Table 6.2, while the three different stages are visualized
in Figure 6.7.
As can be observed from Table 6.2, stage 1 requires a large spatial hash con-
struction effort. Because we incrementally construct the spatial hash for all test
cases, a lot of movement translates to more time spent constructing the spatial
hash. Particles fly around and change hash buckets often, but as they spread
around the glass, the number of neighbors is minimized, reducing the amount of
work performed for evaluation of the SPH equations. Table 6.2 shows the highest
construction times but the lowest update times during stage 1. Stage 2 requires
spending more time on the evaluation of the SPH equations than stage 1, as parti-
cles enter the resting state with many neighbors. However, out of all three stages,
stage 2 spends the smallest amount of time on constructing the spatial hash, be-
cause particles stay in the same hash bucket. The results reflect this, showing an
increased evaluation time compared to stage 1, with the lowest hash construction
time overall. Stage 3 is the most demanding stage; fluid particles are moving be-
cause of the artificial wave and heavily compress at one side of the glass. This is
magnified by the fact that the glass is a cylinder. Construction of the spatial hash
during stage 3 takes more time than during stage 2. Also, evaluating the SPH
equations during stage 3 is more expensive than at any other stage because of an
artificially increased number of neighbors.
Overall, it is immediately clear that evaluation of the SPH equations takes
much more time than does construction of the spatial hash. Evaluation can last
anywhere between 10 and 100 times longer than construction. Also, the two grid-
cell-based spatial hash simulations—gcb and hom—require around 10% more
construction time than their counterparts with a regular spatial hash, but they per-
form roughly 20% better during SPH evaluation. Consequently, the time won dur-