---
id: "narrow-range-ssf-depth-filter"
title: "Narrow-Range Screen-Space Fluid Depth Filtering"
aliases: [narrow-range filter, NRF screen-space fluid smoothing, adaptive threshold depth blur]
domain: "volumes"
stage: "volume"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, unity, unreal]
year_introduced: 2018
inputs: [depth, particles]
outputs: [depth, normals]
style: "photoreal"
dynamic: "dynamic"
cost: "cheap"
authority: "Truong & Yuksel, 2018"
url: "https://texelatlas.vercel.app/t/narrow-range-ssf-depth-filter/"
sources_verified_at: "2026-11-30"
---
# Narrow-Range Screen-Space Fluid Depth Filtering (Truong & Yuksel, 2018)

> 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.

## 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

## How it works

In [screen-space-fluid-rendering](screen-space-fluid-rendering), 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 use it

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](screen-space-fluid-rendering) with curvature flow when you can afford many iterations for maximum smoothness on slow, thick liquids. Prefer [marching-cubes](marching-cubes) or [surface-nets](surface-nets) when you need true 3D water geometry for back-face refraction, reflections, or offline path tracing. Prefer [atrous-wavelet-filter](atrous-wavelet-filter) for general screen-space radiance denoising guided by normals and albedo rather than single-surface particle depth.

## Cost

cheap — Separable 1D passes (typically 2 horizontal + 2 vertical iterations at half or full resolution) make it substantially cheaper than 20–40 iterations of curvature flow.
Measured GPU Weight: 196.53× baseline (extreme) — 6.4657 ms median / 6.608 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 177.46× baseline (extreme) — 2.8216 ms median (2.29× faster on L4).
Ampere A100 scaling: 141.95× baseline (extreme) — 4.0883 ms median (1.58× faster on A100).

## Failure modes

- 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

## Dataflow

- Inputs: depth, particles
- Outputs: depth, normals
- Platforms: webgl2, webgpu, desktop-gpu, unity, unreal

## Presets

### Two-iteration separable narrow-range filter defaults (json-params; parameter preset)

```json
{
  "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) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_RANGE_BAND": 0.14,
  "P_DROP_SPEED": 0.85,
  "P_SMOOTH_RAD": 1,
  "P_SPLIT": 0.48
}
```

```glsl
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.

## Lineage

- extends [Screen-space fluid rendering (curvature flow)](https://texelatlas.vercel.app/t/screen-space-fluid-rendering.md)

## Combines with

- [FLIP/PIC fluids](https://texelatlas.vercel.app/t/flip-pic-fluids.md): FLIP particle positions splat sphere depths and additive thickness that the narrow-range filter smooths into a coherent liquid surface.
- [Real-time Water Caustics](https://texelatlas.vercel.app/t/water-caustics-realtime.md): Noise-free view normals reconstructed from the filtered depth buffer drive refractive bending and caustic projection.
- [Weighted blended order-independent transparency](https://texelatlas.vercel.app/t/weighted-blended-oit.md): Aerated spray and foam sprites composite cleanly over the filtered opaque-style liquid depth surface.

## Combination ideas

- [Narrow-range SSF liquid with whitewater and wet-ground reaction field](https://texelatlas.vercel.app/ideas/narrow-range-ssf-whitewater-ground-field/)

## Sources

1. [primary] Nghia Truong, Cem Yuksel (2018) A Narrow-Range Filter for Screen-Space Fluid Rendering. Proceedings of the ACM on Computer Graphics and Interactive Techniques. https://doi.org/10.1145/3203201 (verified via crossref on 2026-11-30)
2. [implementation] Humpalumps (2026) Humpalumps/ultra-elements. https://github.com/Humpalumps/ultra-elements License: MIT. (verified via github on 2026-11-30)

## Cite this entry

Texel. "Narrow-Range Screen-Space Fluid Depth Filtering." https://texelatlas.vercel.app/t/narrow-range-ssf-depth-filter/ (accessed 2026-12-01).
