Narrow-Range Screen-Space Fluid Depth Filtering
Smooth splatted particle-fluid depth buffers in two separable passes by dynamically tracking a narrow lower/upper depth band per pixel, preventing foreground droplets from bleeding into background sheets while remaining faster than curvature flow.
Also known as narrow-range filter, NRF screen-space fluid smoothing, adaptive threshold depth blur
In the family Atmosphere, water & volumes, particle fluid rendering
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | No built-in screen-space fluid rendering or narrow-range depth filter post-processing pass. |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | No built-in screen-space fluid narrow-range depth filter pass. |
| Unity | None found | No built-in narrow-range screen-space fluid depth filtering pass. |
| Unreal 5.7 | None found | No built-in narrow-range screen-space fluid depth filter pass; Niagara Fluids surfaces use meshing or custom materials. |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
In Screen-space fluid rendering (curvature flow), splatting fluid particles as sphere sprites leaves bumpy depth maps that must be smoothed before reconstructing normals. Classical bilateral filters use a fixed range sigma that either leaves particle bumps visible or blends across silhouette gaps, while iterative curvature flow needs dozens of dependent passes.
The narrow-range filter replaces the static range kernel with a running depth interval [lower, upper] initialized around the center pixel's depth (offset by a small multiple of particle radius). As the separable 1D horizontal and vertical passes step outward across neighbors, samples inside the interval contribute with Gaussian spatial weights and gently expand the upper bound to follow smooth curved surfaces. Samples closer than the lower bound are rejected outright so background fluid never pulls toward a foreground splash; samples much farther than the upper bound are clamped to the upper threshold rather than discarded, preserving smooth grazing silhouettes without staircase rims.
Because the filter is separable and converges in one to three horizontal-vertical pairs with depth-scaled world-space kernel radii, it produces clean, low-artifact normals at a fraction of curvature flow's pass count.
When to choose it
Reach for it when
- bilateral blur on screen space fluid depth creates blurry silhouette halos
- particle fluid surface looks blobby or bleeds onto background walls
- need fast separable depth smoothing for real-time liquid rendering
- preserve crisp water foreground edges while smoothing interior particle bumps
- eliminate gaussian depth bleeding between overlapping liquid splashes
Choose it when rendering real-time particle fluids in WebGL2, WebGPU, or game engines and you want crisp silhouette preservation with far fewer GPU passes than iterative curvature flow.
Prefer Screen-space fluid rendering (curvature flow) with curvature flow when you can afford many iterations for maximum smoothness on slow, thick liquids. Prefer Marching Cubes or Surface Nets when you need true 3D water geometry for back-face refraction, reflections, or offline path tracing. Prefer Edge-avoiding a-trous wavelet filter for general screen-space radiance denoising guided by normals and albedo rather than single-surface particle depth.
Field marks
- Separable 1D passes can introduce mild axis-aligned cross artifacts on diagonal thin fluid streams unless a small 2D cleanup pass or tuned threshold is used
- Screen-space kernel radius must scale inversely with view depth, and clamping the maximum pixel radius limits smoothness at very close camera distances
- Too tight a depth threshold leaves individual sphere bumps visible; too wide a threshold merges nearby splashes and detached droplets into webs
- Inherits screen-space fluid limits: only the frontmost depth layer exists, so internal overlapping layers and back faces cannot be reconstructed
Presets
Two-iteration separable narrow-range filter defaults
{
"iterations": 2,
"world_radius_to_particle_radius": 2.5,
"max_pixel_radius": 18,
"depth_threshold_to_particle_radius": 2,
"clamping_factor": 1
}Attribution: written for this index
Narrow-Range SSF Depth Filter — wide bilateral droplet bleeding (left) vs dynamic narrow-band crisp separation (right)
{
"P_RANGE_BAND": 0.14,
"P_DROP_SPEED": 0.85,
"P_SMOOTH_RAD": 1,
"P_SPLIT": 0.48
}Show GLSL (146 lines)
const float P_RANGE_BAND = 0.14; // P Narrow Band Width [0.04, 0.35, 0.02]
const float P_DROP_SPEED = 0.85; // P Splash Speed [0.0, 2.0, 0.05]
const float P_SMOOTH_RAD = 1.00; // P Filter Radius [0.4, 1.8, 0.05]
const float P_SPLIT = 0.48; // P Wide / Narrow Split [0.0, 1.0, 0.02]
// Evaluate raw splatted particle-fluid screen-space depth buffer z(uv) (smaller z = closer to camera!)
// Foreground flying droplets (z ~ 1.15) pass directly in front of a background liquid wave sheet (z ~ 2.35)
float evalFluidDepth(vec2 uv, float tAnim) {
float minZ = 10.0;
// Background fluid wave sheet made of overlapping splatted spheres (z around 2.25..2.55)
for (int i = 0; i < 14; i++) {
float fi = float(i);
float px = -0.78 + fi * 0.12 + 0.04 * sin(tAnim * 1.4 + fi);
float py = -0.18 + 0.16 * sin(fi * 0.72 + tAnim * 1.8) + 0.05 * cos(fi * 1.5);
float r = 0.165;
vec2 d = uv - vec2(px, py);
float r2 = dot(d, d);
if (r2 < r * r) {
float z = 2.38 - sqrt(r * r - r2) * 1.35;
minZ = min(minZ, z);
}
}
// Second lower row of background sheet particles
for (int i = 0; i < 12; i++) {
float fi = float(i);
float px = -0.68 + fi * 0.125;
float py = -0.34 + 0.08 * cos(fi * 0.9 - tAnim * 1.5);
float r = 0.18;
vec2 d = uv - vec2(px, py);
float r2 = dot(d, d);
if (r2 < r * r) {
float z = 2.30 - sqrt(r * r - r2) * 1.35;
minZ = min(minZ, z);
}
}
// Foreground splashing droplets arc (much closer: z ~ 1.08..1.25!) crossing in front of the background sheet!
for (int i = 0; i < 6; i++) {
float fi = float(i);
float phase = fract(tAnim * 0.24 + fi * 0.165);
float px = mix(-0.62, 0.62, phase);
float py = -0.26 + 0.68 * (4.0 * phase * (1.0 - phase)) + 0.04 * sin(fi * 3.1);
float r = 0.082 + 0.018 * sin(fi * 2.3);
vec2 d = uv - vec2(px, py);
float r2 = dot(d, d);
if (r2 < r * r) {
float z = 1.18 - sqrt(r * r - r2) * 1.25;
minZ = min(minZ, z);
}
}
return minZ;
}
// Narrow-range vs naive wide screen-space depth smoothing (Truong & Yuksel 2018)
float evalFilteredDepth(vec2 uv, float tAnim, float band, float rad, bool useNarrow) {
float z0 = evalFluidDepth(uv, tAnim);
if (z0 > 5.0) return 10.0;
// Dynamic narrow-range lower/upper depth envelope tracked around z0
float zLow = z0 - band;
float zHigh = z0 + band;
float accZ = z0;
float accW = 1.0;
float stepUv = 0.017 * rad;
for (int j = -2; j <= 2; j++) {
for (int i = -2; i <= 2; i++) {
if (i == 0 && j == 0) continue;
vec2 off = vec2(float(i), float(j)) * stepUv;
float zn = evalFluidDepth(uv + off, tAnim);
if (zn > 5.0) continue;
float spW = exp(-dot(vec2(float(i), float(j)), vec2(float(i), float(j))) * 0.22);
if (useNarrow) {
// Narrow-range filter: reject background samples > zHigh, clamp near samples < zLow, dynamically tighten band!
if (zn <= zHigh) {
float clampedZ = max(zn, zLow);
accZ += clampedZ * spW;
accW += spW;
zHigh = min(zHigh, clampedZ + band);
zLow = max(zLow, clampedZ - band);
}
} else {
// Wide bilateral/Gaussian blur: averages foreground droplets (z~1.18) with background sheet (z~2.35) -> ugly webbing!
float dz = abs(zn - z0);
float rngW = exp(-dz * dz * 0.65);
float w = spW * rngW;
accZ += zn * w;
accW += w;
}
}
}
return accZ / max(accW, 1e-4);
}
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 sx = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool useNarrow = sx >= split;
float band = clamp(P_RANGE_BAND, 0.03, 0.45);
float tAnim = iTime * max(P_DROP_SPEED, 0.0);
float rad = clamp(P_SMOOTH_RAD, 0.3, 2.0);
// Subtle tile backdrop behind the transparent fluid
vec2 tile = floor((uv + vec2(0.0, 0.1)) * 9.0);
vec3 bg = mix(vec3(0.09, 0.12, 0.17), vec3(0.15, 0.19, 0.26), mod(tile.x + tile.y, 2.0));
vec3 col = bg;
float z = evalFilteredDepth(uv, tAnim, band, rad, useNarrow);
if (z < 5.0) {
float e = 0.008;
float zx = evalFilteredDepth(uv + vec2(e, 0.0), tAnim, band, rad, useNarrow);
float zy = evalFilteredDepth(uv + vec2(0.0, e), tAnim, band, rad, useNarrow);
float dx = (zx < 5.0) ? (zx - z) / e : 0.0;
float dy = (zy < 5.0) ? (zy - z) / e : 0.0;
vec3 N = normalize(vec3(-dx * 0.48, -dy * 0.48, 1.0));
vec3 V = vec3(0.0, 0.0, 1.0);
vec3 L = normalize(vec3(0.55, 0.72, 0.65));
vec3 H = normalize(L + V);
// Refracted background tile + Beer-Lambert liquid tint + crisp Fresnel sky reflection
vec2 refrUv = uv + N.xy * 0.075;
vec2 rTile = floor((refrUv + vec2(0.0, 0.1)) * 9.0);
vec3 refrBg = mix(vec3(0.08, 0.14, 0.22), vec3(0.18, 0.28, 0.38), mod(rTile.x + rTile.y, 2.0));
// Highlight depth separation: closer droplets glow brighter cyan-white, background sheet deeper cobalt
vec3 tint = mix(vec3(0.18, 0.74, 0.94), vec3(0.06, 0.34, 0.62), smoothstep(1.15, 2.35, z));
float fres = 0.06 + 0.88 * pow(1.0 - max(dot(N, V), 0.0), 4.0);
float spec = pow(max(dot(N, H), 0.0), 72.0) * 1.9;
vec3 skyR = mix(vec3(0.22, 0.46, 0.75), vec3(0.88, 0.95, 1.0), smoothstep(-0.2, 0.8, reflect(-V, N).y));
col = mix(refrBg * tint * 1.65 + tint * 0.25, skyR, fres) + vec3(1.0, 0.98, 0.92) * spec;
}
float sep = smoothstep(0.0035, 0.0008, abs(sx - split));
col = mix(col, vec3(0.95, 0.97, 1.0), sep);
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 |
|---|---|---|---|
| narrow-range-ssf-depth-filter-live | Tesla T4 1920x1080 | 197× baseline (extreme) · 6.47 ms / 6.61 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| narrow-range-ssf-depth-filter-live | NVIDIA L4 1920x1080 | 177× baseline (extreme) · 2.82 ms / 2.88 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| narrow-range-ssf-depth-filter-live | NVIDIA A100-SXM4-40GB 1920x1080 | 142× baseline (extreme) · 4.09 ms / 4.14 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Position Based Fluids.
Crosses
- 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.
- FLIP/PIC fluids: FLIP particle positions splat sphere depths and additive thickness that the narrow-range filter smooths into a coherent liquid surface.
- Real-time Water Caustics: Noise-free view normals reconstructed from the filtered depth buffer drive refractive bending and caustic projection.
- Weighted blended order-independent transparency: Aerated spray and foam sprites composite cleanly over the filtered opaque-style liquid depth surface.
Sources
- primaryNghia Truong, Cem Yuksel (2018). A Narrow-Range Filter for Screen-Space Fluid Rendering. Proceedings of the ACM on Computer Graphics and Interactive Techniques.Verified via crossref · 2026-11-30doi:10.1145/3203201
- implementationHumpalumps (2026). Humpalumps/ultra-elements. Real-time elemental spell VFX lab for three.js (WebGL2): 39 tunable spellsGitHub API · license MIT · 2026-11-30