Fluid Flow Simulator illustration

Fluid Flow Simulator

An incompressible fluid solver running entirely on the graphics card: every step, WebGL fragment shaders advect the velocity field along itself (Jos Stam’s semi-Lagrangian method), add vorticity confinement to keep small whirls alive, compute the divergence, solve for pressure with about twenty Jacobi iterations and subtract its gradient so the flow stays divergence-free. Drag across the canvas with mouse or finger to inject velocity and a dye whose hue drifts slowly through the spectrum; left alone, the simulation splats itself every few seconds so it never sits still. Sliders control how fast dye and velocity dissipate, the vorticity (curl) strength and the splat radius. Needs WebGL with floating-point textures; a notice appears if the browser can’t provide them.

Runs 100% in your browser — simulations are computed locally on your device.

Notes

  • Stam’s "Stable Fluids" (SIGGRAPH 1999) traces each cell backward along the velocity field and interpolates — unconditionally stable at any time step, which is why it runs at 60 fps where classical explicit solvers blow up.
  • Incompressibility (∇·u = 0) is enforced by Helmholtz–Hodge decomposition: solve the Poisson equation ∇²p = ∇·u, then subtract ∇p from the velocity field.
  • Semi-Lagrangian advection is numerically diffusive and smears small vortices; vorticity confinement (Fedkiw et al., 2001) measures the local curl and adds a force that spins them back up.
  • Runs 100% in your browser — simulations are computed locally on your device.