Position Based Fluids × Ihmsen Unified Spray, Foam, and Bubble Whitewater Simulation × Narrow-Range Screen-Space Fluid Depth Filtering × Coupled Ground Reaction-Front Field with FP16 Stochastic Rounding
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.
Open in StudioReproduced26.0× · 0.805 ms
Verified proof

Split-screen WebGL2 proof comparing raw un-filtered position-based fluid spheres splashed over a dry stone basin (left, exposing blobby sphere silhouettes, zero foam, and unreactive dry stone) against narrow-range screen-space depth filtering, Beer-Lambert refractive liquid shading, Ihmsen crest/trapped-air whitewater foam & spray, and a stochastically rounded capillary wet-ground reaction field darkening the basin floor (right).
Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · eliminates blobby particle silhouettes via narrow-range depth smoothing while uniting refractive thickness, Ihmsen whitewater foam, and persistent wet-ground stone darkening
Show GLSL proof (143 lines)
const float P_FILTER_BAND = 1.00; // P Narrow-Range Smooth [0.2, 2.0, 0.05]
const float P_WHITEWATER = 1.15; // P Ihmsen Whitewater [0.0, 2.2, 0.05]
const float P_WET_SPREAD = 1.00; // P Capillary Wet Spread [0.0, 2.0, 0.05]
const float P_SURGE_SPEED = 1.00; // P Fluid Surge [0.2, 2.0, 0.05]
float hash21(vec2 p) {
p = fract(p * vec2(127.1, 311.7));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / max(k, 1e-4), 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
// Evaluates fluid surface height + crest energy from 14 animated PBF wave parcels
// smoothMode = false -> raw hard min of individual PBF spheres; true -> narrow-range SSF smoothed sheet
vec3 evalFluidParcels(vec2 p, float t, bool smoothMode) {
float d = 1e5;
float crest = 0.0;
float blendK = smoothMode ? (0.14 * P_FILTER_BAND) : 0.004;
float surge = sin(t * 1.15 * P_SURGE_SPEED) * 0.14;
for (int i = 0; i < 14; i++) {
float fi = float(i);
float lane = (fi / 13.0) * 0.72 - 0.36;
float cx = -0.14 + surge + 0.24 * sin(t * 0.9 * P_SURGE_SPEED + fi * 0.65) + 0.07 * cos(fi * 2.1);
float cy = lane + 0.045 * sin(t * 1.4 * P_SURGE_SPEED + fi * 1.3);
float rad = 0.072 + 0.024 * sin(fi * 1.9 + t * 0.7);
float sd = length(p - vec2(cx, cy)) - rad;
if (smoothMode) {
d = smin(d, sd, blendK);
} else {
d = min(d, sd);
}
// Wavefront crest shear energy peaks on leading (+x) breaking edge
float lead = smoothstep(0.06, -0.05, sd) * smoothstep(-0.08, 0.16, p.x - cx + 0.04);
crest += lead * 0.28;
}
// Main reservoir body feeding from the left edge
float pool = (p.x + 0.22 - 0.06 * sin(p.y * 9.0 + t * 1.8 * P_SURGE_SPEED) - surge * 0.7);
d = smoothMode ? smin(d, pool, 0.12 * P_FILTER_BAND) : min(d, pool);
return vec3(d, clamp(crest, 0.0, 1.5), smoothstep(0.02, -0.18, d));
}
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 useCross = uv.x > 0.0;
vec2 p = vec2(useCross ? (uv.x - 0.25) : (uv.x + 0.25), uv.y);
p.x *= 1.85;
// Flagstone courtyard ground tiles with subtle mortar seams
vec2 tileUV = p * 7.5;
vec2 tileId = floor(tileUV);
vec2 tileF = fract(tileUV);
float mortar = smoothstep(0.04, 0.09, min(min(tileF.x, 1.0 - tileF.x), min(tileF.y, 1.0 - tileF.y)));
float stoneVar = 0.84 + 0.16 * hash21(tileId);
float micro = 0.94 + 0.06 * sin(p.x * 120.0 + sin(p.y * 95.0));
vec3 dryStone = mix(vec3(0.20, 0.19, 0.18), vec3(0.56, 0.53, 0.48) * stoneVar * micro, mortar);
vec3 L = normalize(vec3(0.45, 0.52, 0.72));
vec3 V = normalize(vec3(-p.x * 0.2, -p.y * 0.2, 1.0));
vec3 fRes = evalFluidParcels(p, iTime, useCross);
float sd = fRes.x;
float crestE = fRes.y;
float thick = fRes.z;
// Capillary wet-ground reaction field (with fp16-style stochastic dithering at outer diffusion front)
float wetness = 0.0;
if (useCross) {
// Trail left behind receding surge + capillary seepage through porous mortar seams
vec3 fPrev = evalFluidParcels(p - vec2(0.09 * P_WET_SPREAD, 0.0), iTime - 0.55, true);
float reach = min(sd, fPrev.x - 0.03 * P_WET_SPREAD);
float mortarSeep = (1.0 - mortar) * 0.038 * P_WET_SPREAD;
float rawWet = smoothstep(0.13 * P_WET_SPREAD + mortarSeep, -0.01, reach);
// Stochastic rounding grain along faint diffusion margin
float stoch = (hash21(floor(fragCoord.xy) + floor(iTime * 12.0)) - 0.5) * 0.06;
wetness = clamp(rawWet + stoch * smoothstep(0.0, 0.35, rawWet) * smoothstep(0.75, 0.25, rawWet), 0.0, 1.0);
}
// Wet stone gets dramatically darker and glossier (classic capillary albedo darkening + specular sheen)
vec3 groundAlb = mix(dryStone, dryStone * vec3(0.36, 0.39, 0.43), wetness);
vec3 nStone = normalize(vec3((hash21(tileId + 3.1) - 0.5) * 0.08, (hash21(tileId + 8.7) - 0.5) * 0.08, 1.0));
float groundSpec = pow(max(dot(nStone, normalize(L + V)), 0.0), mix(14.0, 68.0, wetness)) * mix(0.05, 0.55, wetness);
vec3 col = groundAlb * (0.28 + 0.78 * max(dot(nStone, L), 0.0)) + vec3(0.85, 0.92, 1.0) * groundSpec;
if (sd < 0.0) {
// Reconstruct liquid surface normal from screen-space depth gradient
float e = useCross ? 0.008 : 0.004;
float hC = sqrt(max(-sd, 0.0));
float hX = sqrt(max(-evalFluidParcels(p + vec2(e, 0.0), iTime, useCross).x, 0.0));
float hY = sqrt(max(-evalFluidParcels(p + vec2(0.0, e), iTime, useCross).x, 0.0));
vec3 N = normalize(vec3(-(hX - hC) / e * 0.42, -(hY - hC) / e * 0.42, 1.0));
if (!useCross) {
// Left: naive unsmoothed PBF sphere shading (distinct blobby glossy bubbles, no refraction or foam)
float ndl = max(dot(N, L), 0.0);
float spec = pow(max(dot(N, normalize(L + V)), 0.0), 36.0);
vec3 blob = vec3(0.14, 0.46, 0.72) * (0.30 + 0.75 * ndl) + vec3(0.95) * spec * 0.65;
col = blob;
} else {
// Right: narrow-range SSF smooth refraction + Beer-Lambert spectral absorption + Fresnel sky
vec2 refrUV = p - N.xy * 0.045;
vec2 rTileF = fract(refrUV * 7.5);
float rMortar = smoothstep(0.04, 0.09, min(min(rTileF.x, 1.0 - rTileF.x), min(rTileF.y, 1.0 - rTileF.y)));
vec3 refrStone = mix(vec3(0.14, 0.14, 0.14), vec3(0.36, 0.35, 0.32), rMortar) * (0.45 + 0.55 * max(dot(N, L), 0.0));
// Beer-Lambert absorption tinted teal-cobalt with fluid thickness
float depthVal = clamp(hC * 3.8 + thick * 1.4, 0.05, 3.5);
vec3 absorb = exp(-depthVal * vec3(1.65, 0.52, 0.24));
vec3 bodyCol = mix(vec3(0.015, 0.14, 0.24), refrStone, absorb);
float fres = 0.03 + 0.97 * pow(1.0 - max(dot(N, V), 0.0), 4.5);
vec3 R = reflect(-V, N);
vec3 envRefl = mix(vec3(0.18, 0.34, 0.52), vec3(0.88, 0.94, 1.0), clamp(R.y * 0.6 + 0.55, 0.0, 1.0));
float spec = pow(max(dot(N, normalize(L + V)), 0.0), 110.0) * 2.2;
col = mix(bodyCol, envRefl, fres * 0.72) + vec3(1.0, 0.97, 0.92) * spec;
// Ihmsen unified whitewater: trapped-air bubbles (interior) + lacy crest foam (leading edge)
float lace = sin(p.x * 54.0 - iTime * 4.5 + sin(p.y * 48.0)) * cos(p.y * 52.0 + cos(p.x * 44.0));
float edgeFoam = smoothstep(-0.075, -0.002, sd) * (0.55 + 0.45 * lace);
float crestFoam = smoothstep(0.32, 0.92, crestE) * smoothstep(-0.2, 0.55, lace);
float bubbles = smoothstep(0.55, 0.96, hash21(floor((p - vec2(iTime * 0.08, 0.0)) * 75.0))) * crestE * 0.65;
float foam = clamp((edgeFoam * 0.92 + crestFoam * 0.85 + bubbles) * P_WHITEWATER, 0.0, 1.0);
col = mix(col, vec3(0.92, 0.96, 0.99) * (0.62 + 0.38 * max(dot(N, L), 0.0)), foam * 0.88);
}
} else if (useCross) {
// Ballistic Ihmsen spray droplets arcing slightly ahead of breaking fluid crest
vec2 spCell = floor((p - vec2(iTime * 0.14 * P_SURGE_SPEED, 0.0)) * 46.0);
vec2 spF = fract((p - vec2(iTime * 0.14 * P_SURGE_SPEED, 0.0)) * 46.0) - 0.5;
float rnd = hash21(spCell);
float sprayZone = smoothstep(0.11, 0.002, sd) * smoothstep(0.76, 0.96, rnd);
float drop = smoothstep(0.28, 0.08, length(spF)) * sprayZone * P_WHITEWATER;
col = mix(col, vec3(0.94, 0.97, 1.0), clamp(drop, 0.0, 0.9));
}
col = acesTone(col);
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 advances fluid particles via uniform-grid neighbor search and density constraint projection, outputting positions, velocities, and local neighbor densities. Ihmsen Unified Spray, Foam, and Bubble Whitewater Simulation reads those particles to evaluate trapped-air velocity differences and crest curvature, spawning and advecting secondary spray, foam, and bubble particles. The hop to Narrow-Range Screen-Space Fluid Depth Filtering is composite: core fluid particles splat a raw screen-space depth and thickness buffer that the narrow-range filter smooths across contiguous fluid surfaces while strictly rejecting background jumps, and the whitewater particles depth-test and composite into that filtered liquid volume. The hop to Coupled Ground Reaction-Front Field with FP16 Stochastic Rounding is also composite: fluid contact depth and particle impacts stamp moisture and chemical activator into a world-space 2D ground texture stored in fp16, where stochastic rounding prevents tiny diffusion/evaporation deltas from underflowing to zero.
How to build it
Run all four stages in WebGPU compute and raster passes. Step PBF on a hashed 3D grid (2-4 density iterations plus XSPH viscosity), then in a companion compute kernel compute Ihmsen's trapped-air and wave-crest emission potentials to spawn ballistic spray, surface-advected foam, and buoyant bubbles in a secondary particle pool. Splat core fluid spheres to depth and additive thickness render targets, smooth depth with 2-4 separable passes of the narrow-range filter (clamping neighbor depths within a tight view-space band around the center pixel to avoid foreground/background bleeding), reconstruct view normals, and shade refraction, Beer-Lambert absorption, Fresnel, and depth-sorted whitewater. Simultaneously, rasterize or scatter fluid bottom-contact footprints into an fp16 ground field and update a capillary wetting / reaction-diffusion PDE each frame using hash-driven stochastic rounding before storing back to half-float.
Field marks
- Narrow-range depth filtering still exhibits minor screen-space flattening at grazing silhouette rims unless the depth threshold adapts to view-space particle radius.
- Whitewater particle counts can spike explosively during high-energy splashes without strict emission caps and lifetime recycling.
- Mismatch between the PBF collision heightfield and the world-space ground reaction UV map produces floating or offset wet trails.
- Stochastic rounding introduces subtle high-frequency dither in fp16 ground fields that can read as grain on smooth specular wet puddles unless filtered on read.
Prior art
- Humpalumps/ultra-elements. Open-source WebGPU fluid and multi-element sandbox combining PBF, Ihmsen unified whitewater, narrow-range SSF depth filtering, and fp16 stochastically rounded ground reaction fields; listed here as an open Arena cross awaiting a standalone WebGL2 reproduction.