Smoke Simulation

An interactive playground, demonstrating the basic concepts behind a Jos Stam Fluid simulation. Users can generate and swirl smoke manually or place attractors and repulsers to move the fluid automatically. Adding pillars will block the flow of smoke and produce some interesting interactions.

Controls

Try it out

How it works

The fluid sim calculates the interaction between pixel cells, tracking the density changes from frame to frame. The density of each cell is used to determine its alpha value. Four processes affect how the density evolves:

There are a few tricky details about keep density constant, tracing back velocity and ensuring stability over time, for which I will direct you to Jos Stam’s paper in the resources.

Why is it pixelated?

All of the simulation updates are taking place on the CPU, which means the simulation has to iterate over every pixel multiple times to generate a frame. My original attempt parallelized these operations to GLSL shaders that would generate a 3D texture representing the updated forces. Each force has have a corresponding shader that calculates a new state for a single time step. The shader output gets captured in a frame-buffer and passed to the next calculation as a texture. The final density texture is rendered to the screen using the same shader implemented in this CPU simulation. Sadly I couldn’t get this working in time for the presentation, which led to the dimensionality and image quality reduction. Definitely look at the resources section if you are interested in examples of porting this logic to shader code.

Technologies used

Resources