Lattice Boltzmann fluids
Simulates fluid with particle-distribution functions streaming and colliding on a lattice, with simple local updates that parallelise perfectly on GPUs.
Also known as LBM
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 | None found | Niagara Fluids uses Eulerian grid/FLIP solvers rather than Lattice Boltzmann. |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Instead of velocity and pressure, each cell stores a small set of distribution values (D2Q9 in 2D, D3Q19 or D3Q27 in 3D), one per lattice direction. A step has two phases: collision relaxes each cell's distributions toward equilibrium (BGK, with relaxation time setting viscosity), and streaming copies each distribution to the neighbouring cell it points to. Density and velocity are recovered as sums of the distributions. Solid boundaries use bounce-back, which works for arbitrary voxelised shapes. There is no pressure Poisson solve, so each step is a purely local, memory-bound pass, ideal for fragment/compute shaders.
When to choose it
Reach for it when
- simulate wind flowing around complex obstacles
- need gpu-friendly fluid with many steps per frame
- smoke around voxelised geometry
- fluid solver with simple local parallel updates
- wind tunnel style airflow visualisation
Choose it for wind tunnels, smoke around complex voxel obstacles, and GPU-friendly fluid that must run many steps per frame. Prefer Stable Fluids for artist-friendly large time steps and stable smoke, FLIP/PIC fluids or Smoothed Particle Hydrodynamics (fluids) for liquids with free surfaces, and Position Based Fluids for game liquids.
Field marks
- Only stable for low Mach numbers; high speeds or low viscosity cause blow-ups
- Compressibility errors: density waves reflect around obstacles
- Fixed lattice step ties time step to grid resolution, so large domains need many steps
- Free surfaces and multiphase flow need extra models
Presets
Lattice Boltzmann fluids — D2Q9 Kármán vortex street vorticity, equilibrium vectors & wake shedding
{
"P_REYNOLDS": 1.15,
"P_VORTEX_SHED": 1,
"P_LATTICE_GRID": 0.75,
"P_FLOW_SPEED": 1
}Show GLSL (111 lines)
const float P_REYNOLDS = 1.15; // P Vortex Strength [0.3, 2.2, 0.05]
const float P_VORTEX_SHED = 1.0; // P Strouhal Freq [0.4, 2.0, 0.05]
const float P_LATTICE_GRID = 0.75; // P D2Q9 Stencils [0.0, 1.5, 0.05]
const float P_FLOW_SPEED = 1.0; // P Inflow Speed [0.0, 2.5, 0.05]
// Analytical D2Q9 Karman vortex street streamfunction behind cylinder at cylPos
float streamPsi(vec2 p, vec2 cylPos, float cylR, float t, float reyn, float stFreq) {
vec2 q = p - cylPos;
float r2 = max(dot(q, q), 1e-4);
// Potential doublet flow around cylinder (strictly tangent at r = cylR)
float u0 = 0.75;
float psi = u0 * q.y * (1.0 - (cylR * cylR) / r2);
// Shedding alternating von Karman vortex street downstream (q.x > 0)
float wakeMask = smoothstep(cylR * 0.6, cylR * 2.2, q.x) * exp(-abs(q.y) * 2.2);
float kX = 5.4 * stFreq;
float spacing = 6.2831853 / kX;
float phase = t * 1.45 * stFreq;
for (int k = 0; k < 6; k++) {
float fk = float(k);
float sgn = (mod(fk, 2.0) < 0.5) ? 1.0 : -1.0;
float vx = mod(fk * spacing * 0.5 + phase * (spacing / 6.2831853), 1.65) + cylR * 1.15;
float vy = sgn * (0.072 + 0.032 * vx);
vec2 dv = q - vec2(vx, vy);
float d2 = dot(dv, dv);
float core = 0.0055 + 0.006 * vx;
float fade = exp(-vx * 0.82) * smoothstep(cylR * 0.9, cylR * 1.8, vx);
// Lamb-Oseen regularized point vortex contribution
psi += sgn * 0.058 * reyn * fade * wakeMask * log(d2 + core);
}
return psi;
}
vec2 evalVelocity(vec2 p, vec2 cylPos, float cylR, float t, float reyn, float stFreq) {
float e = 0.006;
float dPsiDy = (streamPsi(p + vec2(0.0, e), cylPos, cylR, t, reyn, stFreq) - streamPsi(p - vec2(0.0, e), cylPos, cylR, t, reyn, stFreq)) / (2.0 * e);
float dPsiDx = (streamPsi(p + vec2(e, 0.0), cylPos, cylR, t, reyn, stFreq) - streamPsi(p - vec2(e, 0.0), cylPos, cylR, t, reyn, stFreq)) / (2.0 * e);
return vec2(dPsiDy, -dPsiDx);
}
// Diverging scientific vorticity palette (blue = clockwise, dark slate = irrotational, orange/gold = CCW)
vec3 vortPalette(float w) {
float a = clamp(abs(w), 0.0, 1.0);
vec3 neg = mix(vec3(0.04, 0.14, 0.34), vec3(0.14, 0.86, 1.00), pow(a, 0.72));
vec3 pos = mix(vec3(0.32, 0.08, 0.10), vec3(1.00, 0.72, 0.18), pow(a, 0.72));
return mix(vec3(0.035, 0.052, 0.082), (w >= 0.0 ? pos : neg), smoothstep(0.02, 0.85, a));
}
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 px = 1.0 / max(iResolution.y, 1.0);
float tAnim = iTime * max(P_FLOW_SPEED, 0.0);
float reyn = clamp(P_REYNOLDS, 0.2, 2.5);
float stFreq = clamp(P_VORTEX_SHED, 0.35, 2.2);
float gridVis = clamp(P_LATTICE_GRID, 0.0, 1.6);
vec2 cylPos = vec2(-0.42, 0.0);
float cylR = 0.115;
// Evaluate macroscopic velocity u and vorticity curl(u) = dv/dx - du/dy
vec2 vel = evalVelocity(uv, cylPos, cylR, tAnim, reyn, stFreq);
float e = 0.01;
vec2 vxP = evalVelocity(uv + vec2(e, 0.0), cylPos, cylR, tAnim, reyn, stFreq);
vec2 vxM = evalVelocity(uv - vec2(e, 0.0), cylPos, cylR, tAnim, reyn, stFreq);
vec2 vyP = evalVelocity(uv + vec2(0.0, e), cylPos, cylR, tAnim, reyn, stFreq);
vec2 vyM = evalVelocity(uv - vec2(0.0, e), cylPos, cylR, tAnim, reyn, stFreq);
float omega = (vxP.y - vxM.y - (vyP.x - vyM.x)) / (2.0 * e);
// Advected streamline dye streaks to reveal flow topology
float psi = streamPsi(uv, cylPos, cylR, tAnim, reyn, stFreq);
float streak = smoothstep(0.06, 0.01, abs(fract(psi * 7.5 + 0.5) - 0.5));
vec3 col = vortPalette(omega * 0.22);
float speed = length(vel);
col += vec3(0.18, 0.32, 0.45) * streak * clamp(speed * 0.55, 0.15, 0.65);
// Microscopic D2Q9 lattice stencil overlay showing discrete velocity population arrows per cell
if (gridVis > 0.01) {
float cellScale = 14.0;
vec2 cellId = floor(uv * cellScale);
vec2 cellCenter = (cellId + 0.5) / cellScale;
vec2 lf = fract(uv * cellScale) - 0.5;
vec2 cVel = evalVelocity(cellCenter, cylPos, cylR, tAnim, reyn, stFreq);
float cSpd = length(cVel);
vec2 dir = cVel / max(cSpd, 1e-4);
// Project local offset onto cell velocity direction to draw a tiny directional D2Q9 flux vector
float proj = clamp(dot(lf, dir), 0.0, clamp(cSpd * 0.32, 0.08, 0.38));
float dVec = length(lf - dir * proj);
float dDot = length(lf);
float glyph = max(smoothstep(0.055, 0.018, dVec), smoothstep(0.075, 0.03, dDot) * 0.65);
col += vec3(0.75, 0.90, 1.0) * glyph * 0.26 * gridVis;
}
// Solid bounce-back cylindrical obstacle (no-slip LBM boundary condition)
float dCyl = length(uv - cylPos) - cylR;
if (dCyl < 0.0) {
vec2 rel = (uv - cylPos) / cylR;
float nz = sqrt(max(1.0 - dot(rel, rel), 0.0));
vec3 cn = normalize(vec3(rel, nz));
float diff = max(dot(cn, normalize(vec3(0.5, 0.7, 0.6))), 0.0);
col = vec3(0.14, 0.17, 0.23) * (0.35 + 0.85 * diff);
}
col = mix(col, vec3(0.86, 0.92, 1.0), smoothstep(px * 3.0, px * 0.6, abs(dCyl)) * 0.9);
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 |
|---|---|---|---|
| lattice-boltzmann-fluids-live | Tesla T4 1920x1080 | 28.3× baseline (heavy) · 0.889 ms / 0.922 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| lattice-boltzmann-fluids-live | NVIDIA L4 1920x1080 | 23.4× baseline (heavy) · 0.370 ms / 0.370 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| lattice-boltzmann-fluids-live | NVIDIA A100-SXM4-40GB 1920x1080 | 19.6× baseline (moderate) · 0.566 ms / 0.566 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Particle systems, Stable Fluids.
Crosses
- Fog that flows through generated caves: Procedural caves and dungeons whose fog actually moves through them: drafts along corridors, eddies behind pillars. The generator's voxel grid is used directly as the fluid solver's solid boundary, so no remeshing sits between level and air.
Sources
- primaryShiyi Chen, Gary D. Doolen (1998). LATTICE BOLTZMANN METHOD FOR FLUID FLOWS. Annual Review of Fluid Mechanics.Verified via crossref · 2026-11-29doi:10.1146/annurev.fluid.30.1.329
- primaryTimm Krüger, Halim Kusumaatmaja, Alexandr Kuzmin, Orest Shardt, Goncalo Silva, Erlend Magnus Viggen (2017). The Lattice Boltzmann Method. Graduate Texts in Physics.Verified via crossref · 2026-11-29doi:10.1007/978-3-319-44649-3
- primaryXiaoming Wei, Wei Li, K. Mueller, A.E. Kaufman (2004). The lattice-boltzmann method for simulating gaseous phenomena. IEEE Transactions on Visualization and Computer Graphics.Verified via crossref · 2026-11-29doi:10.1109/tvcg.2004.1260768