Smoothed Particle Hydrodynamics (fluids)
Meshless Lagrangian fluid method: each particle's density, pressure and viscosity forces come from kernel-weighted sums over neighbouring particles.
Also known as SPH
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 | None found | |
| Blender 5.2 | Built in | Particle Properties > Physics > Fluid docs |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Fields are interpolated with a smoothing kernel W(r,h): density is sum_j m_j W(|x_i-x_j|,h), pressure force and viscosity force are kernel gradients/Laplacians of those quantities. Pressure comes from an equation of state (weakly-compressible SPH, stiff and needing tiny steps) or from a pressure solve (PCISPH, IISPH, DFSPH), which allow much larger steps. Neighbours are found with a uniform grid or spatial hash and sorted for coherence on the GPU. Interactive-graphics SPH popularised specialised kernels (poly6 for density, spiky for pressure, viscosity kernel for the Laplacian) to avoid clumping. Surface tension and boundaries are extra particle forces or boundary particles.
When to choose it
Reach for it when
- particle based water simulation for games
- splashing liquid with free surface and no grid
- fluid interacts with moving objects naturally
- simulate honey or water as particles
Choose it when you want a simple, meshless liquid with free surfaces, easy two-way rigid coupling and multiphase support. Prefer Position Based Fluids for faster, more game-oriented stability, FLIP/PIC fluids for large-scale splashes with less particle-pairing noise, and Lattice Boltzmann fluids when a regular grid and straightforward parallelism matter more than free surfaces.
Field marks
- Tensile instability: particles clump or pair when pressure goes negative
- Weakly-compressible variants force very small time steps, or fluid visibly compresses
- Particle deficiency at free surface and boundaries gives density and pressure errors
- Lots of particles (millions) needed for visually smooth surfaces; surface reconstruction adds cost and bumpiness
Presets
Smoothed Particle Hydrodynamics — Poly6 density kernel, Tait pressure heatmap & kernel support rings
{
"P_KERNEL_H": 0.19,
"P_SLOSH_SPEED": 1,
"P_PRESSURE_VIS": 0.78,
"P_SURFACE_ISO": 1
}Show GLSL (122 lines)
const float P_KERNEL_H = 0.19; // P Kernel Radius h [0.11, 0.30, 0.01]
const float P_SLOSH_SPEED = 1.0; // P Slosh Speed [0.0, 2.5, 0.05]
const float P_PRESSURE_VIS = 0.78; // P Pressure Map [0.0, 1.5, 0.04]
const float P_SURFACE_ISO = 1.0; // P Fluid Threshold [0.5, 1.8, 0.04]
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);
}
// Poly6 SPH smoothing kernel W(r, h) ~ (1 - (r/h)^2)^3 for r < h
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;
}
// Sloshing SPH particle trajectory inside rectangular tank x in [-0.62, 0.62], y in [-0.36, 0.36]
vec2 particlePos(int idx, float t) {
float fi = float(idx);
float colIdx = mod(fi, 7.0);
float rowIdx = floor(fi / 7.0);
vec2 h = hash21(fi * 11.7 + 4.2);
// Sloshing basin wave mode + convective circulation roll
float baseX = (colIdx - 3.0) * 0.172 + 0.05 * sin(t * 1.45 + rowIdx * 0.9 + h.x * 6.28);
float slosh = 0.12 * sin(t * 1.35) * (baseX / 0.55);
float splash = 0.055 * sin(t * 2.2 + colIdx * 1.15 + h.y * 6.28) * (rowIdx / 3.0);
float baseY = -0.28 + rowIdx * 0.115 + slosh + splash;
// Hydrostatic swirl eddy near basin center
float eddyAng = t * 0.95 + fi * 0.7;
vec2 swirl = vec2(cos(eddyAng), sin(eddyAng)) * (0.025 + 0.02 * h.x);
vec2 p = vec2(baseX, baseY) + swirl;
p.x = clamp(p.x, -0.58, 0.58);
p.y = clamp(p.y, -0.32, 0.32);
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 tAnim = iTime * max(P_SLOSH_SPEED, 0.0);
float hRad = clamp(P_KERNEL_H, 0.10, 0.34);
float presVis = clamp(P_PRESSURE_VIS, 0.0, 1.5);
float isoThr = clamp(P_SURFACE_ISO, 0.4, 2.0) * 0.58;
// Evaluate SPH density rho(uv) and kernel gradient grad(rho) across 28 fluid particles
float rho = 0.0;
vec2 gradRho = vec2(0.0);
float minDist = 1e5;
float ringVis = 0.0;
for (int i = 0; i < 28; i++) {
vec2 pi = particlePos(i, tAnim);
vec2 d = uv - pi;
float r = length(d);
minDist = min(minDist, 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;
}
// Show kernel support radius h on 3 highlighted probe particles
if (i == 10 || i == 17 || i == 23) {
ringVis = max(ringVis, smoothstep(px * 3.0, px * 0.6, abs(r - hRad)));
}
}
// Dark lab chamber backdrop + subtle tank grid
vec3 col = mix(vec3(0.025, 0.036, 0.058), vec3(0.055, 0.080, 0.125), smoothstep(-0.5, 0.5, uv.y));
vec2 g = abs(fract(uv * 12.0 - 0.5) - 0.5);
col += vec3(0.015, 0.025, 0.042) * smoothstep(0.035, 0.005, min(g.x, g.y));
// Tank interior bounds
vec2 tankD = abs(uv) - vec2(0.64, 0.38);
float dTank = length(max(tankD, 0.0)) + min(max(tankD.x, tankD.y), 0.0);
if (dTank < 0.0) {
col = mix(col, vec3(0.04, 0.06, 0.10), 0.5);
}
// Tait equation of state pressure: p = k * ((rho / rho0)^gamma - 1)
float rhoNorm = rho / max(isoThr, 0.1);
float pressure = max(pow(max(rhoNorm, 0.0), 2.4) - 1.0, 0.0);
// Fluid surface extraction where density exceeds isosurface threshold
float fluidMask = smoothstep(isoThr * 0.86, isoThr * 1.06, rho) * step(dTank, 0.0);
if (fluidMask > 0.005) {
// Reconstruct pseudo-3D fluid surface normal from density gradient
vec3 n = normalize(vec3(-gradRho.x * 0.18, -gradRho.y * 0.18, 1.0));
vec3 lDir = normalize(vec3(0.45, 0.78, 0.68));
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), 48.0);
// Rich deep-water blue -> high-pressure cyan/emerald/amber core
vec3 waterCol = mix(vec3(0.05, 0.34, 0.68), vec3(0.12, 0.78, 0.88), clamp(rhoNorm * 0.45, 0.0, 1.0));
vec3 pressCol = mix(waterCol, vec3(0.98, 0.66, 0.18), clamp(pressure * 0.28 * presVis, 0.0, 0.92));
// Crisp specular foam rim along free surface (low density boundary)
float foam = smoothstep(isoThr * 1.45, isoThr * 0.92, rho);
vec3 shaded = pressCol * (0.36 + 0.74 * diff) + vec3(0.92, 0.98, 1.0) * (spec * 0.85 + foam * 0.42);
col = mix(col, shaded, fluidMask);
}
// Render crisp SPH particle centers & smoothing kernel support radius rings
float pCore = smoothstep(0.017, 0.007, minDist);
col = mix(col, vec3(0.92, 0.98, 1.0), pCore * 0.72);
col += vec3(1.0, 0.86, 0.34) * ringVis * 0.68;
// Glass tank border
col = mix(col, vec3(0.68, 0.84, 0.98), smoothstep(0.009, 0.002, abs(dTank)) * 0.85);
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 |
|---|---|---|---|
| sph-fluids-live | Tesla T4 1920x1080 | 20.4× baseline (heavy) · 0.640 ms / 0.656 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| sph-fluids-live | NVIDIA L4 1920x1080 | 18.0× baseline (moderate) · 0.284 ms / 0.293 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| sph-fluids-live | NVIDIA A100-SXM4-40GB 1920x1080 | 12.2× baseline (moderate) · 0.350 ms / 0.350 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): cited by Interactive Climbing Plant Modeling, FLIP/PIC fluids, Position Based Fluids.
Sources
- primaryJ. J. Monaghan (1992). Smoothed Particle Hydrodynamics. Annual Review of Astronomy and Astrophysics.Verified via crossref · 2026-11-29doi:10.1146/annurev.aa.30.090192.002551
- implementationInteractiveComputerGraphics (2016). InteractiveComputerGraphics/SPlisHSPlasH. SPlisHSPlasH is an open-source library for the physically-based simulation of fluids.GitHub API · license MIT · 2026-11-29