Fluid Playground

GPU-accelerated real-time fluid simulation — inject dye and watch vortices form

Real-Time Navier-Stokes on Your GPU

This simulation solves the incompressible Navier-Stokes equations in real time using your graphics card. Every frame, the GPU performs advection, pressure projection, and diffusion across a 256×256 velocity field — thousands of tiny fluid calculations happening simultaneously.

Click and drag to inject colored dye and velocity into the fluid. Watch how vortices form, interact, and gradually dissipate through viscous diffusion.

Fluid Playground

Click and drag to inject fluid
Viscosity0.000100
Dye Dissipation0.985
Velocity Decay0.980
Splat Radius0.0040

Presets

Vorticity View

Vorticity measures the local spin of the fluid — the curl of the velocity field. Red regions rotate clockwise, blue regions rotate counterclockwise. Notice how vortices often come in pairs of opposite sign.

Vorticity: red = CW · blue = CCW

Pressure Field

In incompressible flow, pressure is not an independent variable — it's determined entirely by the requirement that the velocity field remains divergence-free. The pressure field shown here is the solution to a Poisson equation solved every frame via Jacobi iteration.

Pressure: high · low

Viscosity Comparison

Compare high-viscosity fluid (like honey) with low-viscosity fluid (like water). High viscosity smooths out velocity gradients quickly, suppressing small-scale structures. Low viscosity allows thin filaments and intricate vortex patterns to persist.

High Viscosity (honey-like)

Low Viscosity (water-like)

Under the Hood

The simulation implements Jos Stam's “Stable Fluids” algorithm (1999) entirely on the GPU via WebGL fragment shaders:

  1. Advection — Semi-Lagrangian method traces particles backward through the velocity field
  2. Diffusion — Jacobi iteration solves the viscous diffusion equation
  3. Force application — Mouse input is applied as a Gaussian splat of velocity and dye
  4. Pressure projection — A Poisson equation is solved (40 Jacobi iterations) to make the velocity divergence-free
  5. Gradient subtraction — The pressure gradient is subtracted from velocity to enforce incompressibility