Realtime explosion simulation

Fall 2007

Christian Miller (ckm _AT_ cs.utexas.edu)

The goal

We set out to replicate the results of Feldman, O'Brien, and Arikan [2] by creating a similar system capable of simulating realistic suspended particle explosions. Given that the original method required only a few seconds of computation per frame when published in 2003, we also attempted to make the system operate at interactive rates.



A time sequence showing an explosion from [2].  


The method

The simulation is comprised of two components: a grid-based fluid, and a combustible particle system. They transfer heat and force to each other at each step of the simulation, and this interaction is what enables the explosion to take place.

The fluid solver uses Jos Stam's Stable Fluids technique [3], and solves the Poisson equations with a simple Gauss-Seidel iterative relaxation scheme. Vorticity confinement [1] is added to enhance visually attractive swirls in the fluid. The grid contains a temperature field which advects and diffuses around, and a buoyancy term proportional to temperature is added back into the velocity field to make hot air rise.

The particle system contains a collection of small fuel particles that move around via drag forces from the fluid. They also absorb heat from the fluid, and once a particle's temperature rises above a certain threshold, it ignites. It burns its mass at a constant rate, injecting heat and pressure back into the fluid as it goes. Once its mass is depleted, the particle deactivates and cools off.

To initiate the explosion, a ball of fuel particles is created and lit with a small injection of temperature and pressure. The interior fuel particles ignite and burn, releasing heat and increasing pressure, which simultaneously expands the cloud of fuel and ignites nearby particles. Soon, all fuel has been ignited, and the fireball burns to completion.

Rendering the explosion is accomplished in [2] using expensive offline techniques, which were infeasible for our realtime implementation. Thus, our rendering is accomplished by drawing depth sorted, screen aligned billboards at particle locations. These billboards were colored on a scale according to temperature, with hot temperatures using large, bright images, and low temperatures using small, sooty images. Note that we did not generate these images ourselves; we used the program available here.

To make the system realtime, several techniques were used to speed it up. First, the choice of grid size used for the fluid simulation has the largest impact on performance. Since we render only the particles, the fluid need only be high enough resolution to make a convincing simulation, and a large number of particles can fill in detail in the final image. We found that grids as small as 32 cells per side produced acceptable results, though higher resolutions certainly helped. Second, the use of an iterative relaxation scheme in the fluid solver allowed us to tweak the number of iterations to trade off speed and accuracy. Surprisingly few iterations were needed for acceptable results; in our case, 20 was more than sufficient. Finally, the system was profiled to find hotspots, and the most expensive functions were vectorized using SSE. In particular, vectorizing the relaxation steps yielded large speedups.


The results

Our system is capable of generating impressive fireballs in realtime. We created two implementations: a 2D version to illustrate the components of the simulation, and a 3D version to demonstrate particle rendering and the feasibility of using this technique in games. The test machine used was a MacBook Pro with a 2.2 GHz Core 2 Duo processor. (Only one core is ever used, the system is not yet multithreaded.)

The above series of screenshots shows an explosion in the two-dimensional simulator. The black and white background is the temperature field embedded in the fluid, with hotter regions showing in white. The particles are color-coded according to their state: blue is unignited, red is burning (brighter red indicates hotter temperature), and grey is depleted. The fluid grid used is 128x128, with 65536 particles embedded in it. The simulation runs at approximately 40 frames per second on the test machine.

Above is a series of screenshots from the three-dimensional simulator, rendered with depth sorted billboard particles. The fluid grid used is 32x32x32, with 16384 particles embedded in it; the white lines trace the boundaries of the fluid grid. It runs on the test machine at just over 30 frames per second.


Discussion

From a simulation standpoint, the system achieved its goals handsomely. The fluid simulation is stable, fast, and visually appealing. The particles ignite and burn to create a spectacular ball of flame and a convincing explosion effect. Above all, this is achieved at interactive rates on reasonable hardware. It is especially worth noting that the simulation is not as optimized as it could be; there's still plenty of room left to further vectorize computation and split it across multiple threads. With a bit of work, a 3D simulation on a 64x64x64 grid should be achievable in realtime using two to four SPEs on a PS3.

The biggest advantage this technique has over existing realtime explosions, though it is not demonstrated well by the examples above, is that it supports arbitrary boundary conditions. In effect, any obstacle can be placed near the fireball and it will adapt realistically, including archways, columns, houses, etc.

The largest factor limiting use of this technique is its memory requirements. A 32x32x32 3D simulation uses approximately 26 MB of memory, which may not be affordable if memory is already packed with textures and geometry. Also, most of the numerous parameters used to tweak the simulation lack any intuitive physical meaning, making tuning the explosion to look as desired a tiresome trial-and-error process.

From a rendering standpoint, the system is less of a success. It does create visually interesting images that successfully connote some sort of physically-based explosion process, but ultimately, the billboard particle rendering style is too spotty to create realism. The results of the 3D simulation tend to look more like high-temperature jellyfish than explosions, which indicates that further work is necessary to get cheap, good-looking renderings of the burning particles.

Looking towards the future, it is clear that the work remaining to be done is in rendering. A promising avenue of exploration is to come up with an image-space rendering technique for the point cloud, which would allow greater control over the viewer-dependent effects that occur when viewing the explosion and be less susceptible to the texture of individual particles


The code

The code package below is an Xcode 3 project, requiring an Intel Mac running OS X 10.5 (Leopard) with the developer tools installed. However, this was merely the platform used for development; there is nothing inherent in the simulation code that prevents it from being used under other systems, other than the requirement that the SSE and SSE2 instruction sets are available. Usage is free and unrestricted, provided the author (Christian Miller) is credited. Note, however, that the code has not yet been cleaned or made fit for public consumption. Enter at your own risk.

Code here


Acknowledgements

I'd like to thank the UT Graphics lab for their feedback and comments, especially Warren Hunt for his excellent optimization advice. I also thank Bryan Feldman and Okan Arikan for their suggestions, as well as the anonymous creator of the explosion texture generation program used in this project.


Citations

[1] Fedkiw, R., Stam, J. and Jensen, H.W. "Visual Simulation of Smoke.", SIGGRAPH 2001, 23-30 (2001).

[2] Feldman, B. E., O'Brien, J. F., Arikan, O., "Animating Suspended Particle Explosions." The Proceedings of ACM SIGGRAPH 2003, San Diego, California, July, pp. 708-715

[3] Stam, J., "Stable Fluids." In SIGGRAPH 99 Conference Proceedings, Annual Conference Series, August 1999, 121-128.