---
id: "position-based-fluids"
title: "Position Based Fluids"
aliases: [PBF]
domain: "simulation"
stage: "simulation"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, cuda, cpu]
year_introduced: 2013
inputs: [particles]
outputs: [particles]
style: "both"
dynamic: "dynamic"
cost: "medium"
authority: "Macklin & Müller, 2013"
url: "https://texelatlas.vercel.app/t/position-based-fluids/"
sources_verified_at: "2026-11-29"
---
# Position Based Fluids (Macklin & Müller, 2013)

> Particle fluid that enforces incompressibility by solving a density constraint per particle with PBD, giving stable, real-time liquids with tunable artificial pressure.

## Reach for it when

- need stable real-time liquid in an interactive scene
- particle fluid explodes or compresses
- want controllable water on the gpu
- fluid sim must be unconditionally stable

## How it works

Each particle carries a density constraint `rho_i / rho_0 - 1 = 0`, where density is a SPH kernel sum over neighbours found by a uniform grid. After predicting positions under gravity, the solver iterates: compute a Lagrange multiplier per particle (with a relaxation epsilon for stability), then displace each particle by a kernel-weighted sum of its neighbours' multipliers. A tensile-instability correction term (artificial pressure) prevents clumping at low neighbour counts, and vorticity confinement plus XSPH viscosity re-inject lost small-scale motion. Boundaries are collision constraints. Surface reconstruction for rendering is separate (screen-space fluid or marching cubes).

## When to use it

Choose it when you need a visually plausible, controllable, unconditionally stable particle liquid on the GPU for interactive scenes. Prefer [Smoothed Particle Hydrodynamics (fluids)](https://texelatlas.vercel.app/t/sph-fluids.md) (e.g. WCSPH or DFSPH) when you need better physical accuracy, [FLIP/PIC fluids](https://texelatlas.vercel.app/t/flip-pic-fluids.md) when you need lower numerical dissipation and splashier large-scale motion, and [Stable Fluids](https://texelatlas.vercel.app/t/stable-fluids.md) for gas or smoke on a grid.

## Cost

medium — Cost scales with particle count and neighbour search; a few solver iterations per frame.
Measured GPU Weight: 24.38× baseline (heavy) — 0.7557 ms median / 0.7894 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 20.48× baseline (heavy) — 0.3257 ms median (2.32× faster on L4).
Ampere A100 scaling: 15.29× baseline (moderate) — 0.4403 ms median (1.72× faster on A100).

## Failure modes

- Without the artificial-pressure term particles clump into chains at the free surface
- Volume loss/compression visible in tall columns under few iterations
- Over-damped, sluggish look unless vorticity confinement and viscosity are tuned
- Neighbour deficiency at the surface causes density underestimation and surface jitter

## Engine support

- unreal: official — `Niagara Fluids plugin provides GPU-accelerated 2D/3D particle and grid fluid simulation templates` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/niagara-fluids-in-unreal-engine, checked 2026-12-01)

## Dataflow

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

## Presets

### Position Based Fluids — tensile clumping without s_corr (left) vs PBF artificial pressure & vorticity (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_S_CORR": 0.85,
  "P_VORTICITY": 0.75,
  "P_KERNEL_H": 0.16,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_S_CORR = 0.85; // P Tensile s_corr [0.0, 1.5, 0.05]
const float P_VORTICITY = 0.75; // P Vorticity Conf [0.0, 1.8, 0.05]
const float P_KERNEL_H = 0.16; // P Kernel Radius [0.10, 0.26, 0.01]
const float P_SPLIT = 0.48; // P Clump / PBF Split [0.0, 1.0, 0.02]

vec2 hash21(float p) {
  vec3 p3 = fract(vec3(p) * vec3(0.1031, 0.1030, 0.0973));
  p3 += dot(p3, p3.yzx + 33.33);
  return fract((p3.xx + p3.yz) * p3.zy);
}

float poly6(float r, float h) {
  float q = r / max(h, 1e-4);
  if (q >= 1.0) return 0.0;
  float t = 1.0 - q * q;
  return t * t * t;
}

// Evaluate PBF particle position; left side omits tensile s_corr so particles clump in pairs
vec2 pbfParticle(int idx, float t, bool useSCorr, float sCorrGain, float vortGain) {
  float fi = float(idx);
  float colI = mod(fi, 8.0);
  float rowI = floor(fi / 8.0);
  vec2 rnd = hash21(fi * 17.3 + 2.7);

  // Dam-break wave surging across tank with rotational vorticity eddies
  float baseX = (colI - 3.5) * 0.155;
  float baseY = -0.29 + rowI * 0.125;

  float surge = 0.085 * sin(t * 1.65 + rowI * 0.55);
  float waveY = 0.095 * sin(t * 1.9 + baseX * 4.4) * (0.35 + 0.65 * rowI / 3.0);
  vec2 p = vec2(baseX + surge, baseY + waveY);

  // Vorticity confinement curl kick on right side
  float vortAng = t * 2.1 + fi * 0.9;
  float vortAmp = useSCorr ? (0.032 * vortGain) : 0.010;
  p += vec2(cos(vortAng), sin(vortAng)) * vortAmp * (0.5 + 0.5 * rnd.x);

  // Tensile instability: without s_corr = -k*(W(r)/W(dq))^n, adjacent pairs attract into clumps
  if (!useSCorr) {
    float pairId = floor(fi * 0.5);
    float pairCol = mod(pairId * 2.0, 8.0) + 0.5;
    float pairRow = floor((pairId * 2.0) / 8.0);
    vec2 clusterCenter = vec2((pairCol - 3.5) * 0.155 + surge, -0.29 + pairRow * 0.125 + waveY);
    p = mix(p, clusterCenter + (rnd - 0.5) * 0.025, 0.72);
  } else {
    // Artificial pressure s_corr pushes particles toward uniform blue-noise spacing
    p += (rnd - 0.5) * 0.045 * clamp(sCorrGain, 0.0, 1.5);
  }

  p.x = clamp(p.x, -0.60, 0.60);
  p.y = clamp(p.y, -0.34, 0.34);
  return p;
}

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 screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  bool isPBF = screenX >= split;
  float hRad = clamp(P_KERNEL_H, 0.10, 0.28);
  float sCorrGain = max(P_S_CORR, 0.0);
  float vortGain = max(P_VORTICITY, 0.0);

  // Lab tank backdrop
  vec3 col = mix(vec3(0.022, 0.034, 0.054), vec3(0.048, 0.072, 0.115), smoothstep(-0.5, 0.5, uv.y));
  vec2 grid = abs(fract(uv * 12.0 - 0.5) - 0.5);
  col += vec3(0.014, 0.024, 0.040) * smoothstep(0.035, 0.006, min(grid.x, grid.y));

  vec2 tankBox = abs(uv) - vec2(0.66, 0.38);
  float dTank = length(max(tankBox, 0.0)) + min(max(tankBox.x, tankBox.y), 0.0);
  if (dTank < 0.0) col = mix(col, vec3(0.032, 0.052, 0.088), 0.55);

  float rho = 0.0;
  vec2 gradRho = vec2(0.0);
  float curlVis = 0.0;
  float minD = 1e5;
  float sCorrField = 0.0;

  for (int i = 0; i < 32; i++) {
    vec2 pi = pbfParticle(i, iTime, isPBF, sCorrGain, vortGain);
    vec2 d = uv - pi;
    float r = length(d);
    minD = min(minD, r);
    float w = poly6(r, hRad);
    rho += w;
    if (r < hRad && r > 1e-4) {
      float q = r / hRad;
      float dw = -6.0 * (1.0 - q * q) * (1.0 - q * q) * q / hRad;
      gradRho += (d / r) * dw;
      // Artificial pressure s_corr term (W(r)/W(0.2*h))^4
      float wRef = poly6(0.2 * hRad, hRad);
      float ratio = w / max(wRef, 1e-4);
      sCorrField += ratio * ratio * ratio * ratio * 0.08;
      // Local swirl energy for vorticity glow
      float swirlSign = (mod(float(i), 2.0) < 0.5) ? 1.0 : -1.0;
      curlVis += swirlSign * w * (1.0 - q);
    }
  }

  float iso = 0.52;
  float mask = smoothstep(iso * 0.85, iso * 1.08, rho) * step(dTank, 0.0);
  if (mask > 0.005) {
    vec3 n = normalize(vec3(-gradRho.x * 0.16, -gradRho.y * 0.16, 1.0));
    vec3 lDir = normalize(vec3(0.42, 0.78, 0.65));
    float diff = max(dot(n, lDir), 0.0);
    float spec = pow(max(dot(n, normalize(lDir + vec3(0.0, 0.0, 1.0))), 0.0), 54.0);

    // Density constraint error C_i = rho / rho0 - 1
    float errC = clamp(abs(rho / 1.15 - 1.0), 0.0, 1.0);
    vec3 baseWater = isPBF
      ? mix(vec3(0.04, 0.42, 0.76), vec3(0.14, 0.86, 0.82), clamp(rho * 0.48, 0.0, 1.0))
      : mix(vec3(0.14, 0.28, 0.58), vec3(0.82, 0.36, 0.22), errC);

    // Vorticity highlight streaks on PBF side
    if (isPBF) {
      baseWater += vec3(0.18, 0.52, 0.62) * abs(curlVis) * 0.45 * vortGain;
    }

    float rim = smoothstep(iso * 1.38, iso * 0.90, rho);
    vec3 shaded = baseWater * (0.34 + 0.78 * diff) + vec3(0.92, 0.98, 1.0) * (spec * 0.82 + rim * 0.45);
    col = mix(col, shaded, mask);
  }

  // Particle cores and s_corr repulsion halo on right
  float pDot = smoothstep(0.015, 0.006, minD);
  vec3 dotCol = isPBF ? vec3(0.86, 0.98, 1.0) : vec3(1.0, 0.72, 0.48);
  col = mix(col, dotCol, pDot * 0.78);
  if (isPBF) {
    col += vec3(0.12, 0.75, 0.95) * clamp(sCorrField * 0.18 * sCorrGain, 0.0, 0.22) * step(dTank, 0.0);
  }

  // Tank glass border and split divider
  col = mix(col, vec3(0.66, 0.82, 0.96), smoothstep(0.009, 0.002, abs(dTank)) * 0.85);
  col = mix(col, vec3(0.95, 0.97, 1.0), smoothstep(0.0035, 0.0008, abs(screenX - split)));

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Combines with

- [Extended Position-Based Dynamics](https://texelatlas.vercel.app/t/xpbd.md): Compliance/multiplier machinery can unify fluid density constraints with solid constraints in one solver

## Combination ideas

- [Liquids drawn by a splat renderer](https://texelatlas.vercel.app/ideas/fluids-through-splat-renderer/)
- [Narrow-range SSF liquid with whitewater and wet-ground reaction field](https://texelatlas.vercel.app/ideas/narrow-range-ssf-whitewater-ground-field/)
- [Depth-feathered soft-particle mist emitted from PBF splash crests](https://texelatlas.vercel.app/ideas/pbf-crest-soft-particle-spray/)

## Sources

1. [primary] Miles Macklin, Matthias Müller (2013) Position based fluids. ACM Transactions on Graphics. https://doi.org/10.1145/2461912.2461984 (verified via crossref on 2026-11-29)
2. [implementation] InteractiveComputerGraphics (2016) InteractiveComputerGraphics/SPlisHSPlasH. https://github.com/InteractiveComputerGraphics/SPlisHSPlasH License: MIT. (verified via github on 2026-11-29)
3. [tutorial] Matthias Müller Ten Minute Physics. matthias-research.github.io. https://matthias-research.github.io/pages/tenMinutePhysics (verified via http on 2026-11-29)

## Cite this entry

Texel. "Position Based Fluids." https://texelatlas.vercel.app/t/position-based-fluids/ (accessed 2026-12-01).
