Stable Fluids
Unconditionally stable grid solver for incompressible smoke and gas: advect semi-Lagrangian, diffuse, project to divergence-free.
In the family Simulation & animation, grid fluids
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | None found | |
| Unreal 5.7 | Official add-on | Enable Niagara Fluids plugin > Grid 2D / Grid 3D Gas and Smoke Eulerian fluid solvers docs |
| Blender 5.2 | Built in | Physics > Fluid (Mantaflow grid/FLIP Navier-Stokes fluid solver) docs |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Each step applies external forces, then advects the velocity field by tracing each cell backwards through the flow and sampling the old field with interpolation (semi-Lagrangian), which is stable for any step size. Viscosity is an implicit diffusion solve. A projection step solves a Poisson equation for pressure and subtracts its gradient so that divergence is zero. Smoke density or temperature are advected as passive scalars through the same velocity field. On GPUs each stage is a fragment pass with ping-pong textures, and the Jacobi pressure solve typically takes 20-40 iterations. Vorticity confinement is commonly added to recover small swirls lost to numerical diffusion.
When to choose it
Reach for it when
- need smoke or ink that doesn't explode at large timesteps
- cheap 2d or 3d smoke on a grid
- art-directable gas and fire
- fluid solver must be unconditionally stable
- interactive swirling smoke in a game
Choose it when you want cheap, robust, art-directable 2D or 3D smoke, fire and ink on a regular grid. Prefer FLIP/PIC fluids when you need liquid with a free surface, Lattice Boltzmann fluids for easily parallel grid flow with simple boundaries, and Smoothed Particle Hydrodynamics (fluids) for meshless splashing fluids.
Field marks
- Semi-Lagrangian advection smears detail (numerical diffusion) and kills small vortices
- Fixed grid: no free surface, large domains cost cubically
- Jacobi pressure solve with few iterations leaves residual divergence and visible compressibility
- Boundary conditions on moving obstacles need care or smoke leaks
Presets
Stable fluids — semi-Lagrangian divergence-free advection & vorticity dye plumes
{
"P_VISCOSITY": 0.35,
"P_VORTICITY": 1.35,
"P_ADVECTION": 1.1,
"P_SPEED": 1
}Show GLSL (82 lines)
const float P_VISCOSITY = 0.35; // P Viscosity [0.05, 1.2, 0.02]
const float P_VORTICITY = 1.35; // P Vorticity [0.2, 2.5, 0.05]
const float P_ADVECTION = 1.1; // P Advect Step [0.2, 2.2, 0.05]
const float P_SPEED = 1.0; // P Flow Speed [0.0, 2.5, 0.05]
// Analytical streamfunction psi(p,t) -> curl(psi) is strictly divergence-free (div u = 0)
float streamFunc(vec2 p, float t, float visc) {
float damp = exp(-visc * 0.45);
float psi = 0.0;
// Multi-scale Karman vortex street & dipole eddies
psi += 0.48 * sin(p.x * 2.1 - t * 0.65) * cos(p.y * 2.3 + t * 0.42);
psi += 0.28 * damp * cos(p.x * 4.3 + p.y * 3.1 + t * 0.92);
psi += 0.16 * damp * damp * sin(p.x * 7.8 - p.y * 6.4 - t * 1.35);
// Central swirling vortex dipole
vec2 c1 = vec2(0.28 * cos(t * 0.55), 0.24 * sin(t * 0.68));
vec2 c2 = -c1;
psi += 0.36 * exp(-dot(p - c1, p - c1) * 7.5);
psi -= 0.36 * exp(-dot(p - c2, p - c2) * 7.5);
return psi;
}
// Divergence-free velocity u = (dPsi/dy, -dPsi/dx)
vec2 evalVelocity(vec2 p, float t, float visc, float vort) {
float e = 0.008;
float dPsiDx = (streamFunc(p + vec2(e, 0.0), t, visc) - streamFunc(p - vec2(e, 0.0), t, visc)) / (2.0 * e);
float dPsiDy = (streamFunc(p + vec2(0.0, e), t, visc) - streamFunc(p - vec2(0.0, e), t, visc)) / (2.0 * e);
return vec2(dPsiDy, -dPsiDx) * vort;
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float t = iTime * max(P_SPEED, 0.0);
float visc = clamp(P_VISCOSITY, 0.02, 1.5);
float vort = clamp(P_VORTICITY, 0.1, 2.8);
float adv = clamp(P_ADVECTION, 0.1, 2.4);
// Semi-Lagrangian backtracing: unconditionally stable RK2 advection through 7 substeps
vec2 pos = uv;
float dt = 0.055 * adv;
float curlAccum = 0.0;
for (int i = 0; i < 7; i++) {
float ti = t - float(i) * dt * 0.85;
vec2 v1 = evalVelocity(pos, ti, visc, vort);
vec2 mid = pos - 0.5 * dt * v1;
vec2 v2 = evalVelocity(mid, ti - 0.5 * dt, visc, vort);
pos -= dt * v2;
curlAccum += length(v2);
}
curlAccum /= 7.0;
// Source dye jets injected at advected coordinates (cyan, magenta, amber-gold)
float band1 = exp(-pow(sin(pos.y * 3.8 + pos.x * 1.4) * 1.8, 2.0));
float band2 = exp(-pow(cos(pos.x * 4.1 - pos.y * 1.8) * 1.9, 2.0));
float band3 = exp(-pow(sin((pos.x + pos.y) * 5.2) * 2.1, 2.0));
// Viscous diffusion softens filament contrast at higher P_VISCOSITY
float crisp = mix(1.45, 0.65, clamp(visc, 0.0, 1.0));
float d1 = pow(clamp(band1, 0.0, 1.0), crisp);
float d2 = pow(clamp(band2, 0.0, 1.0), crisp);
float d3 = pow(clamp(band3, 0.0, 1.0), crisp);
vec3 col = vec3(0.018, 0.024, 0.042);
col += vec3(0.08, 0.82, 0.96) * d1 * 1.05;
col += vec3(0.96, 0.22, 0.58) * d2 * 0.95;
col += vec3(1.05, 0.72, 0.18) * d3 * 0.78;
// Specular-like vorticity highlight along high-shear ribbons
vec2 vNow = evalVelocity(uv, t, visc, vort);
float speedMag = length(vNow);
float streamIso = smoothstep(0.92, 0.99, 0.5 + 0.5 * cos(streamFunc(uv, t, visc) * 32.0));
col += vec3(0.75, 0.92, 1.0) * streamIso * 0.12 * clamp(speedMag, 0.0, 1.5);
col *= 0.65 + 0.55 * clamp(curlAccum * 0.75, 0.0, 1.4);
// Dark subtle frame vignette
col *= 1.0 - 0.28 * dot(uv, uv);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| stable-fluids-live | Tesla T4 1920x1080 | 44.5× baseline (heavy) · 1.47 ms / 1.53 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| stable-fluids-live | NVIDIA L4 1920x1080 | 39.8× baseline (heavy) · 0.632 ms / 0.634 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| stable-fluids-live | NVIDIA A100-SXM4-40GB 1920x1080 | 26.9× baseline (heavy) · 0.775 ms / 0.775 ms · 1.9× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): cited by Discrete elastic rods (hair and rope simulation), FLIP/PIC fluids, GPU Pipe-Model Hydraulic Erosion, Lattice Boltzmann fluids, Unified particle physics.
Crosses
- Chladni-vibrated iridescent soap film: Acoustic standing waves on a circular membrane stir a viscous soap film into swirling interference bands. Modal Bessel eigenmodes push fluid away from antinodes toward nodal rings, sculpting nanometre-scale film thickness that flashes across the spectrum under thin-film interference.
- Storms that form and drift: Cloudscapes where storm cells form, merge, shear and dissipate with a wind field, because coverage and cloud type are advected by a small 2D fluid simulation rather than scrolled as a static weather map.
Sources
- primaryJos Stam (1999). Stable fluids. Proceedings of the 26th annual conference on Computer graphics and interactive techniques - SIGGRAPH '99.Verified via crossref · 2026-11-29doi:10.1145/311535.311548
- tutorialJos Stam. Real-Time Fluid Dynamics for Games. dgp.toronto.edu.Verified via live page · 2026-11-29
- tutorialMark J. Harris. GPU Gems Chapter 38: Fast Fluid Dynamics Simulation on the GPU. developer.nvidia.com.Verified via live page · 2026-11-29