Position Based Fluids
Particle fluid that enforces incompressibility by solving a density constraint per particle with PBD, giving stable, real-time liquids with tunable artificial pressure.
Also known as PBF
In the family Simulation & animation, particle 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 | Niagara Fluids plugin provides GPU-accelerated 2D/3D particle and grid fluid simulation templates docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
Choose it when you need a visually plausible, controllable, unconditionally stable particle liquid on the GPU for interactive scenes. Prefer Smoothed Particle Hydrodynamics (fluids) (e.g. WCSPH or DFSPH) when you need better physical accuracy, FLIP/PIC fluids when you need lower numerical dissipation and splashier large-scale motion, and Stable Fluids for gas or smoke on a grid.
Field marks
- 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
Presets
Position Based Fluids — tensile clumping without s_corr (left) vs PBF artificial pressure & vorticity (right)
{
"P_S_CORR": 0.85,
"P_VORTICITY": 0.75,
"P_KERNEL_H": 0.16,
"P_SPLIT": 0.48
}Show GLSL (144 lines)
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.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| position-based-fluids-live | Tesla T4 1920x1080 | 24.4× baseline (heavy) · 0.756 ms / 0.789 ms | opengl-timer-query · 36 frames · GPU Weight Atlas · Colab T4 sweep |
| position-based-fluids-live | NVIDIA L4 1920x1080 | 20.5× baseline (heavy) · 0.326 ms / 0.333 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| position-based-fluids-live | NVIDIA A100-SXM4-40GB 1920x1080 | 15.3× baseline (moderate) · 0.440 ms / 0.441 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Smoothed Particle Hydrodynamics (fluids), Position Based Dynamics, Screen-space fluid rendering (curvature flow); cited by Narrow-Range Screen-Space Fluid Depth Filtering, Soft Step solver / substepping, Unified particle physics, Extended Position-Based Dynamics.
Crosses
- Liquids drawn by a splat renderer: A real-time particle liquid rendered through a Gaussian-splat rasteriser, so it gets smooth anisotropic surfaces without a separate fluid-smoothing pass and composites inside a captured splat scene in one sort and one blend.
- Narrow-range SSF liquid with whitewater and wet-ground reaction field: A complete real-time particle liquid pipeline from turbulent splash to stained wet ground. Position-based fluid particles spawn physically classified spray, foam, and bubbles; a narrow-range screen-space filter turns the particle depth into a smooth glass-like surface without silhouette halos; and water contact drives an fp16 stochastically rounded ground reaction field that absorbs, spreads, and dries smoothly without quantization stall.
- Depth-feathered soft-particle mist emitted from PBF splash crests: Triggering buoyant, depth-faded soft-particle spray and sea-mist billboards directly from high-vorticity, low-neighbor PBF wave crests adds believable breaking-wave atmosphere without needing a full multi-million-particle whitewater solver.
- Extended Position-Based Dynamics: Compliance/multiplier machinery can unify fluid density constraints with solid constraints in one solver
Sources
- primaryMiles Macklin, Matthias Müller (2013). Position based fluids. ACM Transactions on Graphics.Verified via crossref · 2026-11-29doi:10.1145/2461912.2461984
- implementationInteractiveComputerGraphics (2016). InteractiveComputerGraphics/SPlisHSPlasH. SPlisHSPlasH is an open-source library for the physically-based simulation of fluids.GitHub API · license MIT · 2026-11-29
- tutorialMatthias Müller. Ten Minute Physics. matthias-research.github.io.Verified via live page · 2026-11-29