{
 "id": "position-based-fluids",
 "title": "Position Based Fluids",
 "aliases": [
  "PBF"
 ],
 "domain": "simulation",
 "subdomain": "particle fluids",
 "stage": "simulation",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cuda",
  "cpu"
 ],
 "year_introduced": 2013,
 "inputs": [
  "particles"
 ],
 "outputs": [
  "particles"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Particle fluid that enforces incompressibility by solving a density constraint per particle with PBD, giving stable, real-time liquids with tunable artificial pressure.",
 "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": "Choose it when you need a visually plausible, controllable, unconditionally stable particle liquid on the GPU for interactive scenes. Prefer `sph-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.",
 "cost": {
  "class": "medium",
  "notes": "Cost scales with particle count and neighbour search; a few solver iterations per frame."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/2461912.2461984",
   "type": "paper",
   "title": "Position based fluids",
   "authors": [
    "Miles Macklin",
    "Matthias Müller"
   ],
   "year": 2013,
   "venue": "ACM Transactions on Graphics",
   "url": "https://doi.org/10.1145/2461912.2461984",
   "ids": {
    "doi": "10.1145/2461912.2461984"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2461912.2461984",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2461912.2461984",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2461912.2461984",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2461912.2461984",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2461912.2461984",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "macklin2013position"
  },
  {
   "role": "implementation",
   "key": "gh:interactivecomputergraphics/splishsplash",
   "type": "code",
   "title": "InteractiveComputerGraphics/SPlisHSPlasH",
   "description": "SPlisHSPlasH is an open-source library for the physically-based simulation of fluids.",
   "authors": [
    "InteractiveComputerGraphics"
   ],
   "year": 2016,
   "venue": "GitHub",
   "url": "https://github.com/InteractiveComputerGraphics/SPlisHSPlasH",
   "ids": {
    "repo": "InteractiveComputerGraphics/SPlisHSPlasH"
   },
   "license": "MIT",
   "extra": {
    "stars": 1971,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-23T08:16:51Z",
    "language": "C++",
    "homepage": "https://splishsplash.physics-simulation.org/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/InteractiveComputerGraphics/SPlisHSPlasH",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/InteractiveComputerGraphics/SPlisHSPlasH",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/InteractiveComputerGraphics/SPlisHSPlasH",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/InteractiveComputerGraphics/SPlisHSPlasH",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/InteractiveComputerGraphics/SPlisHSPlasH",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/InteractiveComputerGraphics/SPlisHSPlasH",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "interactivecomputergraphics2016interactivecomputergraphics"
  },
  {
   "role": "tutorial",
   "key": "url:https://matthias-research.github.io/pages/tenMinutePhysics",
   "type": "tutorial",
   "title": "Ten Minute Physics",
   "authors": [
    "Matthias Müller"
   ],
   "year": null,
   "venue": "matthias-research.github.io",
   "url": "https://matthias-research.github.io/pages/tenMinutePhysics",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260924155100/https://matthias-research.github.io/pages/tenMinutePhysics/",
     "timestamp": "20260924155100"
    },
    "page_title": "Ten Minute Physics",
    "host": "matthias-research.github.io",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://matthias-research.github.io/pages/tenMinutePhysics → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://matthias-research.github.io/pages/tenMinutePhysics → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://matthias-research.github.io/pages/tenMinutePhysics → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "mllerminute"
  }
 ],
 "presets": [
  {
   "id": "position-based-fluids-live",
   "title": "Position Based Fluids — tensile clumping without s_corr (left) vs PBF artificial pressure & vorticity (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_S_CORR": 0.85,
    "P_VORTICITY": 0.75,
    "P_KERNEL_H": 0.16,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_S_CORR = 0.85; // P Tensile s_corr [0.0, 1.5, 0.05]\nconst float P_VORTICITY = 0.75; // P Vorticity Conf [0.0, 1.8, 0.05]\nconst float P_KERNEL_H = 0.16; // P Kernel Radius [0.10, 0.26, 0.01]\nconst float P_SPLIT = 0.48; // P Clump / PBF Split [0.0, 1.0, 0.02]\n\nvec2 hash21(float p) {\n  vec3 p3 = fract(vec3(p) * vec3(0.1031, 0.1030, 0.0973));\n  p3 += dot(p3, p3.yzx + 33.33);\n  return fract((p3.xx + p3.yz) * p3.zy);\n}\n\nfloat poly6(float r, float h) {\n  float q = r / max(h, 1e-4);\n  if (q >= 1.0) return 0.0;\n  float t = 1.0 - q * q;\n  return t * t * t;\n}\n\n// Evaluate PBF particle position; left side omits tensile s_corr so particles clump in pairs\nvec2 pbfParticle(int idx, float t, bool useSCorr, float sCorrGain, float vortGain) {\n  float fi = float(idx);\n  float colI = mod(fi, 8.0);\n  float rowI = floor(fi / 8.0);\n  vec2 rnd = hash21(fi * 17.3 + 2.7);\n\n  // Dam-break wave surging across tank with rotational vorticity eddies\n  float baseX = (colI - 3.5) * 0.155;\n  float baseY = -0.29 + rowI * 0.125;\n\n  float surge = 0.085 * sin(t * 1.65 + rowI * 0.55);\n  float waveY = 0.095 * sin(t * 1.9 + baseX * 4.4) * (0.35 + 0.65 * rowI / 3.0);\n  vec2 p = vec2(baseX + surge, baseY + waveY);\n\n  // Vorticity confinement curl kick on right side\n  float vortAng = t * 2.1 + fi * 0.9;\n  float vortAmp = useSCorr ? (0.032 * vortGain) : 0.010;\n  p += vec2(cos(vortAng), sin(vortAng)) * vortAmp * (0.5 + 0.5 * rnd.x);\n\n  // Tensile instability: without s_corr = -k*(W(r)/W(dq))^n, adjacent pairs attract into clumps\n  if (!useSCorr) {\n    float pairId = floor(fi * 0.5);\n    float pairCol = mod(pairId * 2.0, 8.0) + 0.5;\n    float pairRow = floor((pairId * 2.0) / 8.0);\n    vec2 clusterCenter = vec2((pairCol - 3.5) * 0.155 + surge, -0.29 + pairRow * 0.125 + waveY);\n    p = mix(p, clusterCenter + (rnd - 0.5) * 0.025, 0.72);\n  } else {\n    // Artificial pressure s_corr pushes particles toward uniform blue-noise spacing\n    p += (rnd - 0.5) * 0.045 * clamp(sCorrGain, 0.0, 1.5);\n  }\n\n  p.x = clamp(p.x, -0.60, 0.60);\n  p.y = clamp(p.y, -0.34, 0.34);\n  return p;\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float px = 1.0 / max(iResolution.y, 1.0);\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isPBF = screenX >= split;\n  float hRad = clamp(P_KERNEL_H, 0.10, 0.28);\n  float sCorrGain = max(P_S_CORR, 0.0);\n  float vortGain = max(P_VORTICITY, 0.0);\n\n  // Lab tank backdrop\n  vec3 col = mix(vec3(0.022, 0.034, 0.054), vec3(0.048, 0.072, 0.115), smoothstep(-0.5, 0.5, uv.y));\n  vec2 grid = abs(fract(uv * 12.0 - 0.5) - 0.5);\n  col += vec3(0.014, 0.024, 0.040) * smoothstep(0.035, 0.006, min(grid.x, grid.y));\n\n  vec2 tankBox = abs(uv) - vec2(0.66, 0.38);\n  float dTank = length(max(tankBox, 0.0)) + min(max(tankBox.x, tankBox.y), 0.0);\n  if (dTank < 0.0) col = mix(col, vec3(0.032, 0.052, 0.088), 0.55);\n\n  float rho = 0.0;\n  vec2 gradRho = vec2(0.0);\n  float curlVis = 0.0;\n  float minD = 1e5;\n  float sCorrField = 0.0;\n\n  for (int i = 0; i < 32; i++) {\n    vec2 pi = pbfParticle(i, iTime, isPBF, sCorrGain, vortGain);\n    vec2 d = uv - pi;\n    float r = length(d);\n    minD = min(minD, r);\n    float w = poly6(r, hRad);\n    rho += w;\n    if (r < hRad && r > 1e-4) {\n      float q = r / hRad;\n      float dw = -6.0 * (1.0 - q * q) * (1.0 - q * q) * q / hRad;\n      gradRho += (d / r) * dw;\n      // Artificial pressure s_corr term (W(r)/W(0.2*h))^4\n      float wRef = poly6(0.2 * hRad, hRad);\n      float ratio = w / max(wRef, 1e-4);\n      sCorrField += ratio * ratio * ratio * ratio * 0.08;\n      // Local swirl energy for vorticity glow\n      float swirlSign = (mod(float(i), 2.0) < 0.5) ? 1.0 : -1.0;\n      curlVis += swirlSign * w * (1.0 - q);\n    }\n  }\n\n  float iso = 0.52;\n  float mask = smoothstep(iso * 0.85, iso * 1.08, rho) * step(dTank, 0.0);\n  if (mask > 0.005) {\n    vec3 n = normalize(vec3(-gradRho.x * 0.16, -gradRho.y * 0.16, 1.0));\n    vec3 lDir = normalize(vec3(0.42, 0.78, 0.65));\n    float diff = max(dot(n, lDir), 0.0);\n    float spec = pow(max(dot(n, normalize(lDir + vec3(0.0, 0.0, 1.0))), 0.0), 54.0);\n\n    // Density constraint error C_i = rho / rho0 - 1\n    float errC = clamp(abs(rho / 1.15 - 1.0), 0.0, 1.0);\n    vec3 baseWater = isPBF\n      ? mix(vec3(0.04, 0.42, 0.76), vec3(0.14, 0.86, 0.82), clamp(rho * 0.48, 0.0, 1.0))\n      : mix(vec3(0.14, 0.28, 0.58), vec3(0.82, 0.36, 0.22), errC);\n\n    // Vorticity highlight streaks on PBF side\n    if (isPBF) {\n      baseWater += vec3(0.18, 0.52, 0.62) * abs(curlVis) * 0.45 * vortGain;\n    }\n\n    float rim = smoothstep(iso * 1.38, iso * 0.90, rho);\n    vec3 shaded = baseWater * (0.34 + 0.78 * diff) + vec3(0.92, 0.98, 1.0) * (spec * 0.82 + rim * 0.45);\n    col = mix(col, shaded, mask);\n  }\n\n  // Particle cores and s_corr repulsion halo on right\n  float pDot = smoothstep(0.015, 0.006, minD);\n  vec3 dotCol = isPBF ? vec3(0.86, 0.98, 1.0) : vec3(1.0, 0.72, 0.48);\n  col = mix(col, dotCol, pDot * 0.78);\n  if (isPBF) {\n    col += vec3(0.12, 0.75, 0.95) * clamp(sCorrField * 0.18 * sCorrGain, 0.0, 0.22) * step(dTank, 0.0);\n  }\n\n  // Tank glass border and split divider\n  col = mix(col, vec3(0.66, 0.82, 0.96), smoothstep(0.009, 0.002, abs(dTank)) * 0.85);\n  col = mix(col, vec3(0.95, 0.97, 1.0), smoothstep(0.0035, 0.0008, abs(screenX - split)));\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "position-based-fluids",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:34.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4431,
      "std": 0.2299,
      "min": 0.1786,
      "max": 0.9416
     },
     "image": "/specimens/position-based-fluids-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "sph-fluids",
  "flip-pic-fluids",
  "unified-particle-physics",
  "position-based-dynamics"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "xpbd",
   "why": "Compliance/multiplier machinery can unify fluid density constraints with solid constraints in one solver"
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/simulation/position-based-fluids.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Macklin & Müller, 2013",
 "url": "https://texelatlas.vercel.app/t/position-based-fluids/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 24.38,
  "tier": "heavy",
  "p50_ms": 0.7557,
  "p95_ms": 0.7894,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "position-based-fluids-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 20.48,
   "tier": "heavy",
   "p50_ms": 0.3257,
   "p95_ms": 0.3328,
   "speedup_x": 2.32,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 15.29,
   "tier": "moderate",
   "p50_ms": 0.4403,
   "p95_ms": 0.441,
   "speedup_x": 1.72,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}