# Rendering smoke and fire in real-time

A student project for the Advanced Image Synthesis course 2006

Ingemar Rask and Johannes Schmid

## Final Description

### Physical Simulation

As a project for the Physically-based simulation class, Johannes Schmid implemented a 3D Navier-Stokes fluid solver based on Jos Stam's "Stable fluid" [1] method and publically available source code thereof [2]. A good computational model of fire using fluid simulation was presented by Nguyen et al. [3]. However, their model seemed to involved to implement for this miniproject, so we just took some ideas from it.

What we percieve as yellow-reddish flames in a fire is the blackbody radiation of hot gaseous products, which are the result of combustion. For this project, we limited ourselves to the simulation of this part of the fire and ignored the actual combustion process. The fluid solver is used to simulate the density and temperature field in the fire. We simulate only one scalar field and use it for both temperature and density (conceptually), which is of course a simplification. Both fluid and fluid velocity are seeded randomly at the bottom of the simulation domain. The temperature field is added to the upward velocity field to simulate buoyancy. Vorticity confinement, as described in [4], is applied to add further turbulences. The simulation is done in a grid of 32x32x32 voxels, which performs at over 5 fps on fast machines.

### Rendering

The rendering is obtained by drawing alpha-blended viewplane-aligned slices of the simulation domain, which is represented by a 3D texture. To obtain correct interpolation within the grid, the 3D texture contains the temperature values instead of actual color values. A fragment program then uses the interpolated temperature value to look up the color from a second texture. This color texture is obtained by integrating the Planck Spectrum and taking into account the adaption of the eye, as described by Ngyuen et al. [3] in Section 5.2.

For rendering of smoke, it is crucuial to have some form of illumination. We used CPU-based ray casting to assign an illumination value to each voxel. As the light ray advances through the volume, the local density value is used to attenuate the brightness of the ray. The illumination value then determines the color of the pixel, and the density value determines the transparency. Since a direct interpolation of color and alpha value will give the correct result in this setting, no fragment program is needed for smoke rendering.

## Screenshots and Videos

A few shots of the fire:
Video (MPEG2, 2 MiB)

Drawing only 10 slices and displaying their outlines:

Smoky shots:
Video (MPEG2, 4 MiB)

## Implementation

All the programmming has been done in C++ under Linux. We used SDL [5] to perform various system-level tasks, such as setting up the output window and multi-threading. The rendering itself is done in OpenGL, which is supported by SDL.

Since both SDL and OpenGL are availible on various platforms, the code should be fairly simple to port. Unfortunately, Windows only supports OpenGL 1.0 at the moment, whereas 3D textures were introduced in OpenGL 1.2. It would be possible to make use of 3D textures through extensions (EXT_texture3D).

### Requirements

• OpenGL >= 1.2
• SDL >= 1.2
• A hardware 3D accelerator that supports 3D textures and simple fragment programs

### Usage

Command line: ./fluid [-w|-l <filename>]

• -w <filename> will write the simulation data to the given file
• -l <filename> will load the simulation data from the given file (no simulation is performed)
• If no argument is given, the simulation will be performed but not written to disk

Run-time usage:

• Left mouse button performs trackball rotation
• Mouse wheel performs dolly
• Key c toggles the display of the simulation domain outline
• Key s toggles the display of slice outlines
• Key i toggles the display of frame rate information
• Spacebar pauses the simulation

### Downloads

 smoke64.tar.gz Smoke simulation, 64x64x64 grid, right mouse button rotates the light source s64_2.dat Smoke simulation data from the screenshots, 64x64x64, 125 MiB smoke32.tar.gz Smoke simulation, 32x32x32 grid, right mouse button blows smoke into the scene fire32rand.tar.gz Fire simulation, 32x32x32 grid, high randomness fire32.tar.gz Fire simulation, 32x32x32 grid, moderate randomness f32rand.dat Fire simulation data from the screenshots, 32x32x32, 88 MiB

## References

 [1] Jos Stam, "Stable Fluids", SIGGRAPH 1999, 121-128 (1999) [2] Jos Stam, "Real-Time Fluid Dynamics for Games", Proceedings of the Game Developer Conference, March 2003 [3] Nguyen, D., Fedkiw, R. and Jensen, H., "Physically Based Modeling and Animation of Fire", SIGGRAPH 2002, ACM TOG 21, 721-728 (2002) [4] Fedkiw, R., Stam, J. and Jensen, H.W., "Visual Simulation of Smoke", SIGGRAPH 2001, 23-30 (2001) [5] SDL, Simple DirectMedia Layer, http://www.libsdl.org/