---
id: "lattice-boltzmann-fluids"
title: "Lattice Boltzmann fluids"
aliases: [LBM]
domain: "simulation"
stage: "simulation"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, cuda, cpu]
year_introduced: 1998
inputs: [voxels]
outputs: [volume-density, particles]
style: "photoreal"
dynamic: "dynamic"
cost: "medium"
authority: "Chen & Doolen, 1998"
url: "https://texelatlas.vercel.app/t/lattice-boltzmann-fluids/"
sources_verified_at: "2026-11-29"
---
# Lattice Boltzmann fluids (Chen & Doolen, 1998)

> Simulates fluid with particle-distribution functions streaming and colliding on a lattice, with simple local updates that parallelise perfectly on GPUs.

## 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

## 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 use it

Choose it for wind tunnels, smoke around complex voxel obstacles, and GPU-friendly fluid that must run many steps per frame. Prefer [Stable Fluids](https://texelatlas.vercel.app/t/stable-fluids.md) for artist-friendly large time steps and stable smoke, [FLIP/PIC fluids](https://texelatlas.vercel.app/t/flip-pic-fluids.md) or [Smoothed Particle Hydrodynamics (fluids)](https://texelatlas.vercel.app/t/sph-fluids.md) for liquids with free surfaces, and [Position Based Fluids](https://texelatlas.vercel.app/t/position-based-fluids.md) for game liquids.

## Cost

medium — Memory-bandwidth bound: a lattice cell costs 9-27 reads and writes per step.
Measured GPU Weight: 28.31× baseline (heavy) — 0.8889 ms median / 0.9218 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 23.4× baseline (heavy) — 0.3697 ms median (2.4× faster on L4).
Ampere A100 scaling: 19.64× baseline (moderate) — 0.5656 ms median (1.57× faster on A100).

## Failure modes

- 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

## Dataflow

- Inputs: voxels
- Outputs: volume-density, particles
- Platforms: webgl2, webgpu, desktop-gpu, cuda, cpu

## Presets

### Lattice Boltzmann fluids — D2Q9 Kármán vortex street vorticity, equilibrium vectors & wake shedding (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_REYNOLDS": 1.15,
  "P_VORTEX_SHED": 1,
  "P_LATTICE_GRID": 0.75,
  "P_FLOW_SPEED": 1
}
```

```glsl
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).

## Combination ideas

- [Fog that flows through generated caves](https://texelatlas.vercel.app/ideas/drafts-through-generated-dungeons/)

## Sources

1. [primary] Shiyi Chen, Gary D. Doolen (1998) LATTICE BOLTZMANN METHOD FOR FLUID FLOWS. Annual Review of Fluid Mechanics. https://doi.org/10.1146/annurev.fluid.30.1.329 (verified via crossref on 2026-11-29)
2. [primary] Timm Krüger, Halim Kusumaatmaja, Alexandr Kuzmin, Orest Shardt, Goncalo Silva, Erlend Magnus Viggen (2017) The Lattice Boltzmann Method. Graduate Texts in Physics. https://doi.org/10.1007/978-3-319-44649-3 (verified via crossref on 2026-11-29)
3. [primary] Xiaoming Wei, Wei Li, K. Mueller, A.E. Kaufman (2004) The lattice-boltzmann method for simulating gaseous phenomena. IEEE Transactions on Visualization and Computer Graphics. https://doi.org/10.1109/tvcg.2004.1260768 (verified via crossref on 2026-11-29)

## Cite this entry

Texel. "Lattice Boltzmann fluids." https://texelatlas.vercel.app/t/lattice-boltzmann-fluids/ (accessed 2026-12-01).
