Position Based Fluids × Web Gaussian Splat Renderers (three.js)
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.
Open in StudioReproduced45.7× · 1.42 ms
Verified proof

Split-screen WebGL2 proof comparing raw isotropic Position-Based Fluid particle spheres (left, reading as bumpy disconnected beads) against neighbour-fitted anisotropic 3D Gaussian splats front-to-back composited inside a captured Gaussian-splat gallery alcove in one unified depth sort (right).
Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · turns bumpy PBF fluid particles into smooth anisotropic Gaussian surfaces alpha-sorted seamlessly with static room splats
Show GLSL proof (200 lines)
const float P_ANISO_STRETCH = 2.45; // P Covariance Stretch [1.0, 4.0, 0.05]
const float P_FLOW_SPEED = 1.00; // P Fluid Velocity [0.2, 2.0, 0.05]
const float P_SPLAT_OPACITY = 0.86; // P Splat Density Alpha [0.3, 1.0, 0.02]
const float P_ENV_SPEC = 1.15; // P Specular Sheen [0.2, 2.2, 0.05]
vec3 envColor(vec3 rd) {
float elev = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
vec3 base = mix(vec3(0.06, 0.07, 0.09), vec3(0.24, 0.30, 0.42), pow(elev, 1.3));
float win1 = smoothstep(0.76, 0.94, dot(rd, normalize(vec3(0.55, 0.65, 0.52))));
float win2 = smoothstep(0.82, 0.97, dot(rd, normalize(vec3(-0.70, 0.38, 0.60))));
return base + vec3(2.6, 2.35, 1.95) * win1 + vec3(0.65, 1.15, 1.85) * win2;
}
// Evaluate 3D fluid particle position & velocity tangent along a PBF splashing jet + basin wave
void fluidParticle(int id, float t, out vec3 pos, out vec3 vel, out float dens) {
float fi = float(id);
float phase = fract(fi / 28.0 + t * 0.24 * P_FLOW_SPEED);
float stream = mod(fi, 3.0) - 1.0;
if (id < 18) {
// Pouring parabolic liquid sheet from upper-left spout into stone basin
float s = phase;
float x = mix(-0.92, 0.62, s) + 0.06 * sin(fi * 3.1 + t * 2.2);
float y = 0.64 - 1.28 * s * s + 0.05 * cos(fi * 2.3);
float z = 0.14 * stream + 0.09 * sin(s * 6.2831 + fi);
pos = vec3(x, y, z);
vel = normalize(vec3(1.54, -2.56 * s, 0.12 * cos(s * 6.2831 + fi)));
dens = mix(0.65, 1.0, sin(s * 3.14159));
} else {
// Swirling basin pool crest + splash crown droplets
float a = float(id - 18) * 0.62831 + t * 1.15 * P_FLOW_SPEED;
float r = 0.28 + 0.26 * fract(fi * 0.37);
float x = 0.22 + cos(a) * r * 1.25;
float z = sin(a) * r * 0.72;
float y = -0.58 + 0.14 * sin(a * 2.0 - t * 2.6 * P_FLOW_SPEED) + 0.08 * cos(r * 9.0);
pos = vec3(x, y, z);
vel = normalize(vec3(-sin(a) * 1.25, 0.28 * cos(a * 2.0 - t * 2.6 * P_FLOW_SPEED), cos(a) * 0.72));
dens = 0.85;
}
}
// Ray-sphere distance for isotropic baseline particle
float raySphere(vec3 ro, vec3 rd, vec3 c, float r, out vec3 n) {
vec3 oc = ro - c;
float b = dot(oc, rd);
float h = b * b - (dot(oc, oc) - r * r);
if (h < 0.0) return -1.0;
float t = -b - sqrt(max(h, 0.0));
if (t < 0.0) return -1.0;
n = normalize((ro + rd * t) - c);
return t;
}
// Evaluate 3D anisotropic Gaussian splat density & normal proxy at closest approach along ray
bool evalAnisoGaussian(vec3 ro, vec3 rd, vec3 center, vec3 majorAxis, vec3 radii, out float tHit, out float alpha, out vec3 surfN) {
vec3 T = normalize(majorAxis);
vec3 up = abs(T.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
vec3 B = normalize(cross(T, up));
vec3 N = cross(B, T);
// Transform ray into unit ellipsoid space
vec3 oc = ro - center;
vec3 lo = vec3(dot(oc, T) / radii.x, dot(oc, B) / radii.y, dot(oc, N) / radii.z);
vec3 ld = vec3(dot(rd, T) / radii.x, dot(rd, B) / radii.y, dot(rd, N) / radii.z);
float dd = max(dot(ld, ld), 1e-5);
float t = -dot(lo, ld) / dd;
if (t < 0.1) return false;
vec3 pMin = lo + ld * t;
float d2 = dot(pMin, pMin);
if (d2 > 3.2) return false;
tHit = t;
alpha = exp(-d2 * 1.45);
// Surface normal weighted toward ellipsoid outward gradient + view facing
vec3 localN = normalize(pMin / max(radii, vec3(0.02)) - ld * 0.65);
surfN = normalize(T * localN.x + B * localN.y + N * localN.z);
return true;
}
vec3 acesTone(vec3 x) {
return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
bool useSplats = uv.x > 0.0;
vec2 suv = vec2(useSplats ? (uv.x - 0.25) : (uv.x + 0.25), uv.y);
suv.x *= 1.85;
float camAng = sin(iTime * 0.35) * 0.28;
vec3 ro = vec3(sin(camAng) * 3.1, 0.28, cos(camAng) * 3.1);
vec3 target = vec3(-0.05, -0.10, 0.0);
vec3 fwd = normalize(target - ro);
vec3 right = normalize(cross(vec3(0.0, 1.0, 0.0), fwd));
vec3 up = cross(fwd, right);
vec3 rd = normalize(fwd * 1.75 + right * suv.x + up * suv.y);
// Static captured studio alcove backdrop (warm travertine floor, arched wall, soft splat vignette)
vec3 bg = mix(vec3(0.08, 0.09, 0.12), vec3(0.22, 0.20, 0.18), clamp(rd.y * 0.8 + 0.5, 0.0, 1.0));
// Floor plane at y = -0.82
float bgDepth = 20.0;
if (rd.y < -0.01) {
float tf = (-0.82 - ro.y) / rd.y;
if (tf > 0.0 && tf < 16.0) {
bgDepth = tf;
vec3 fp = ro + rd * tf;
float tiles = mod(floor(fp.x * 2.2) + floor(fp.z * 2.2), 2.0);
vec3 tileCol = mix(vec3(0.32, 0.29, 0.25), vec3(0.42, 0.38, 0.33), tiles);
// Basin shadow & warm caustic glow under splashing pool
float poolGlow = exp(-dot(fp.xz - vec2(0.15, 0.0), fp.xz - vec2(0.15, 0.0)) * 2.2);
tileCol = mix(tileCol, vec3(0.16, 0.36, 0.44), poolGlow * 0.42);
bg = tileCol * exp(-tf * 0.14);
}
}
// Captured stone pedestal splat cluster at spout origin (-1.02, 0.58, 0.0)
vec3 pedN;
float tPed = raySphere(ro, rd, vec3(-1.02, 0.60, 0.0), 0.26, pedN);
if (tPed > 0.0 && tPed < bgDepth) {
bgDepth = tPed;
float nl = max(dot(pedN, normalize(vec3(0.5, 0.8, 0.4))), 0.0);
bg = vec3(0.46, 0.42, 0.36) * (0.25 + 0.85 * nl);
}
vec3 col = bg;
vec3 L = normalize(vec3(0.52, 0.78, 0.44));
if (!useSplats) {
// Left: raw isotropic Position-Based Fluid particle spheres (disconnected bead look)
float bestT = bgDepth;
vec3 bestN = vec3(0.0, 1.0, 0.0);
bool hit = false;
for (int i = 0; i < 28; i++) {
vec3 p, v; float d;
fluidParticle(i, iTime, p, v, d);
vec3 n;
float th = raySphere(ro, rd, p, 0.125, n);
if (th > 0.0 && th < bestT) {
bestT = th;
bestN = n;
hit = true;
}
}
if (hit) {
vec3 V = -rd;
float ndl = max(dot(bestN, L), 0.0);
float ndv = max(dot(bestN, V), 0.05);
float fres = 0.04 + 0.96 * pow(1.0 - ndv, 4.0);
float spec = pow(max(dot(bestN, normalize(L + V)), 0.0), 42.0);
vec3 base = mix(vec3(0.05, 0.22, 0.34), vec3(0.14, 0.52, 0.66), ndl);
col = base + envColor(reflect(-V, bestN)) * fres * 0.55 + vec3(1.1) * spec * 0.65;
}
} else {
// Right: anisotropic PCA covariance Gaussian splats blended in unified depth order
vec3 accumCol = vec3(0.0);
float accumAlpha = 0.0;
float meanDepth = 0.0;
float wSum = 0.0;
vec3 accumN = vec3(0.0);
// Accumulate weighted anisotropic Gaussians (order-weighted transmittance approximation)
for (int i = 0; i < 28; i++) {
vec3 p, v; float dens;
fluidParticle(i, iTime, p, v, dens);
float rx = 0.135 * P_ANISO_STRETCH;
float ry = 0.135 * (0.95 + 0.25 * dens);
float rz = 0.085;
float th, ga; vec3 sn;
if (evalAnisoGaussian(ro, rd, p, v, vec3(rx, ry, rz), th, ga, sn)) {
if (th < bgDepth) {
float a = clamp(ga * P_SPLAT_OPACITY * (0.65 + 0.35 * dens), 0.0, 0.92);
// Depth-priority weight favors closer splats smoothly without hard popping
float depthW = exp(-(th - 1.8) * 1.65) * a;
vec3 V = -rd;
float ndv = clamp(abs(dot(sn, V)), 0.08, 1.0);
float fres = 0.04 + 0.96 * pow(1.0 - ndv, 3.5);
vec3 refl = envColor(reflect(-V, sn));
float spec = pow(max(dot(sn, normalize(L + V)), 0.0), 64.0);
// Deep aquamarine absorption core + bright foam/specular crest
vec3 splatCol = mix(vec3(0.04, 0.28, 0.42), vec3(0.18, 0.66, 0.78), clamp(0.4 + 0.6 * dot(sn, L), 0.0, 1.0));
splatCol = mix(splatCol, refl * P_ENV_SPEC, fres * 0.72) + vec3(1.3, 1.38, 1.45) * spec * P_ENV_SPEC;
accumCol += splatCol * depthW;
accumN += sn * depthW;
meanDepth += th * depthW;
wSum += depthW;
accumAlpha = 1.0 - (1.0 - accumAlpha) * (1.0 - a * 0.68);
}
}
}
if (wSum > 1e-4) {
vec3 fluidRGB = accumCol / wSum;
vec3 smoothN = normalize(accumN / wSum + vec3(0.0, 0.0, 1e-4));
float rim = pow(1.0 - clamp(abs(dot(smoothN, -rd)), 0.0, 1.0), 3.0);
fluidRGB += vec3(0.45, 0.78, 0.92) * rim * 0.38;
// Unified splat composite over static captured alcove
col = mix(bg, fluidRGB, clamp(accumAlpha, 0.0, 0.95));
}
}
col = acesTone(col * 1.08);
if (abs(uv.x) < 0.003) col = vec3(0.95, 0.93, 0.89);
fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Why they connect
Position Based Fluids outputs particles each step. The hop to Web Gaussian Splat Renderers (three.js) is composite, because the viewer expects gaussians: each particle becomes a Gaussian whose covariance comes from a weighted principal-component fit of its neighbours, stretched along the local surface and flattened across it, with opacity rising with neighbour count. The viewer sorts these dynamic splats together with a static captured scene and outputs an ldr-image in which liquid and room blend in one consistent depth order.
How to build it
WebGPU compute: grid neighbour search, PBF density-constraint iterations, vorticity confinement and XSPH viscosity. In the same pass, compute each particle's neighbour covariance and convert it to scale and rotation, clamping the aspect ratio. Write straight into the splat buffer of a three.js splat renderer that supports dynamic updates (Spark exposes splats as three.js objects). Use view-independent colour plus a faked specular term from an environment lookup, since splats do not refract. Re-sort every frame, or use a GPU radix sort. Start with a few tens of thousands of particles.
Field marks
- No refraction or reflection, so the liquid reads as gel or smoke unless shading is faked.
- Re-sorting dynamic splats every frame is the main cost.
- Covariance fits are noisy at the free surface and cause speckle.
- Captured scenes provide no collision geometry for the fluid without a proxy.
Prior art
- glaseagle/splat-fluid. Partial: runs a real-time FLIP fluid in the browser whose particles keep Gaussian shape and colour when rendered (per its README), with FLIP instead of PBF and no neighbour-fitted covariances.
- Physics-Driven Extraction of Dynamic Fluid Asset from Monocular Video with Generative 3DGS. Uses A with B for another goal: fits a particle-in-cell fluid simulation to a video and uses generative 3DGS for the fluid geometry, rather than rendering a live particle fluid through a splat renderer.
Searches run (4)
- arXiv: all:"gaussian splatting" AND all:"fluid simulation" → 2 results
- GitHub repos: "gaussian splatting" "fluid simulation" → 1 result
- arXiv: all:"anisotropic kernels" AND all:"particle fluid" AND all:"splatting" → 0 results
- GitHub repos: "anisotropic kernels" "particle fluid" splatting → 0 results