{
 "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",
 "subdomain": "particle fluid rendering",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "unity",
  "unreal"
 ],
 "year_introduced": 2018,
 "inputs": [
  "depth",
  "particles"
 ],
 "outputs": [
  "depth",
  "normals"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "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.",
 "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.\n\nThe 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.\n\nBecause 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": "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.\n\nPrefer [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": {
  "class": "cheap",
  "notes": "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."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/3203201",
   "type": "paper",
   "title": "A Narrow-Range Filter for Screen-Space Fluid Rendering",
   "authors": [
    "Nghia Truong",
    "Cem Yuksel"
   ],
   "year": 2018,
   "venue": "Proceedings of the ACM on Computer Graphics and Interactive Techniques",
   "url": "https://doi.org/10.1145/3203201",
   "ids": {
    "doi": "10.1145/3203201"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3203201",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3203201",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3203201",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3203201",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3203201",
     "checked_at": "2026-11-30T17:59:51.239Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-30T17:59:51.239Z",
   "title_sim": 1,
   "__bib": "truong2018narrow"
  },
  {
   "role": "implementation",
   "key": "gh:humpalumps/ultra-elements",
   "type": "code",
   "title": "Humpalumps/ultra-elements",
   "description": "Real-time elemental spell VFX lab for three.js (WebGL2): 39 tunable spells",
   "authors": [
    "Humpalumps"
   ],
   "year": 2026,
   "venue": "GitHub",
   "url": "https://github.com/Humpalumps/ultra-elements",
   "ids": {
    "repo": "Humpalumps/ultra-elements"
   },
   "license": "MIT",
   "extra": {
    "stars": 131,
    "stars_checked": "2026-11-30",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-10-30T21:54:34Z",
    "language": "JavaScript",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-30T17:59:51.239Z",
   "title_sim": null,
   "__bib": "humpalumps2026humpalumps"
  }
 ],
 "presets": [
  {
   "id": "narrow-range-ssf-default",
   "title": "Two-iteration separable narrow-range filter defaults",
   "runtime": "json-params",
   "params": {
    "iterations": 2,
    "world_radius_to_particle_radius": 2.5,
    "max_pixel_radius": 18,
    "depth_threshold_to_particle_radius": 2,
    "clamping_factor": 1
   },
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "parameter-only",
   "proof": {
    "kind": "parameter",
    "label": "parameter preset",
    "ok": true,
    "proof": null
   }
  },
  {
   "id": "narrow-range-ssf-depth-filter-live",
   "title": "Narrow-Range SSF Depth Filter — wide bilateral droplet bleeding (left) vs dynamic narrow-band crisp separation (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_RANGE_BAND": 0.14,
    "P_DROP_SPEED": 0.85,
    "P_SMOOTH_RAD": 1,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_RANGE_BAND = 0.14; // P Narrow Band Width [0.04, 0.35, 0.02]\nconst float P_DROP_SPEED = 0.85; // P Splash Speed [0.0, 2.0, 0.05]\nconst float P_SMOOTH_RAD = 1.00; // P Filter Radius [0.4, 1.8, 0.05]\nconst float P_SPLIT = 0.48; // P Wide / Narrow Split [0.0, 1.0, 0.02]\n\n// Evaluate raw splatted particle-fluid screen-space depth buffer z(uv) (smaller z = closer to camera!)\n// Foreground flying droplets (z ~ 1.15) pass directly in front of a background liquid wave sheet (z ~ 2.35)\nfloat evalFluidDepth(vec2 uv, float tAnim) {\n  float minZ = 10.0;\n\n  // Background fluid wave sheet made of overlapping splatted spheres (z around 2.25..2.55)\n  for (int i = 0; i < 14; i++) {\n    float fi = float(i);\n    float px = -0.78 + fi * 0.12 + 0.04 * sin(tAnim * 1.4 + fi);\n    float py = -0.18 + 0.16 * sin(fi * 0.72 + tAnim * 1.8) + 0.05 * cos(fi * 1.5);\n    float r = 0.165;\n    vec2 d = uv - vec2(px, py);\n    float r2 = dot(d, d);\n    if (r2 < r * r) {\n      float z = 2.38 - sqrt(r * r - r2) * 1.35;\n      minZ = min(minZ, z);\n    }\n  }\n  // Second lower row of background sheet particles\n  for (int i = 0; i < 12; i++) {\n    float fi = float(i);\n    float px = -0.68 + fi * 0.125;\n    float py = -0.34 + 0.08 * cos(fi * 0.9 - tAnim * 1.5);\n    float r = 0.18;\n    vec2 d = uv - vec2(px, py);\n    float r2 = dot(d, d);\n    if (r2 < r * r) {\n      float z = 2.30 - sqrt(r * r - r2) * 1.35;\n      minZ = min(minZ, z);\n    }\n  }\n\n  // Foreground splashing droplets arc (much closer: z ~ 1.08..1.25!) crossing in front of the background sheet!\n  for (int i = 0; i < 6; i++) {\n    float fi = float(i);\n    float phase = fract(tAnim * 0.24 + fi * 0.165);\n    float px = mix(-0.62, 0.62, phase);\n    float py = -0.26 + 0.68 * (4.0 * phase * (1.0 - phase)) + 0.04 * sin(fi * 3.1);\n    float r = 0.082 + 0.018 * sin(fi * 2.3);\n    vec2 d = uv - vec2(px, py);\n    float r2 = dot(d, d);\n    if (r2 < r * r) {\n      float z = 1.18 - sqrt(r * r - r2) * 1.25;\n      minZ = min(minZ, z);\n    }\n  }\n\n  return minZ;\n}\n\n// Narrow-range vs naive wide screen-space depth smoothing (Truong & Yuksel 2018)\nfloat evalFilteredDepth(vec2 uv, float tAnim, float band, float rad, bool useNarrow) {\n  float z0 = evalFluidDepth(uv, tAnim);\n  if (z0 > 5.0) return 10.0;\n\n  // Dynamic narrow-range lower/upper depth envelope tracked around z0\n  float zLow = z0 - band;\n  float zHigh = z0 + band;\n  float accZ = z0;\n  float accW = 1.0;\n  float stepUv = 0.017 * rad;\n\n  for (int j = -2; j <= 2; j++) {\n    for (int i = -2; i <= 2; i++) {\n      if (i == 0 && j == 0) continue;\n      vec2 off = vec2(float(i), float(j)) * stepUv;\n      float zn = evalFluidDepth(uv + off, tAnim);\n      if (zn > 5.0) continue;\n      float spW = exp(-dot(vec2(float(i), float(j)), vec2(float(i), float(j))) * 0.22);\n\n      if (useNarrow) {\n        // Narrow-range filter: reject background samples > zHigh, clamp near samples < zLow, dynamically tighten band!\n        if (zn <= zHigh) {\n          float clampedZ = max(zn, zLow);\n          accZ += clampedZ * spW;\n          accW += spW;\n          zHigh = min(zHigh, clampedZ + band);\n          zLow = max(zLow, clampedZ - band);\n        }\n      } else {\n        // Wide bilateral/Gaussian blur: averages foreground droplets (z~1.18) with background sheet (z~2.35) -> ugly webbing!\n        float dz = abs(zn - z0);\n        float rngW = exp(-dz * dz * 0.65);\n        float w = spW * rngW;\n        accZ += zn * w;\n        accW += w;\n      }\n    }\n  }\n  return accZ / max(accW, 1e-4);\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float sx = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool useNarrow = sx >= split;\n\n  float band = clamp(P_RANGE_BAND, 0.03, 0.45);\n  float tAnim = iTime * max(P_DROP_SPEED, 0.0);\n  float rad = clamp(P_SMOOTH_RAD, 0.3, 2.0);\n\n  // Subtle tile backdrop behind the transparent fluid\n  vec2 tile = floor((uv + vec2(0.0, 0.1)) * 9.0);\n  vec3 bg = mix(vec3(0.09, 0.12, 0.17), vec3(0.15, 0.19, 0.26), mod(tile.x + tile.y, 2.0));\n  vec3 col = bg;\n\n  float z = evalFilteredDepth(uv, tAnim, band, rad, useNarrow);\n  if (z < 5.0) {\n    float e = 0.008;\n    float zx = evalFilteredDepth(uv + vec2(e, 0.0), tAnim, band, rad, useNarrow);\n    float zy = evalFilteredDepth(uv + vec2(0.0, e), tAnim, band, rad, useNarrow);\n    float dx = (zx < 5.0) ? (zx - z) / e : 0.0;\n    float dy = (zy < 5.0) ? (zy - z) / e : 0.0;\n    vec3 N = normalize(vec3(-dx * 0.48, -dy * 0.48, 1.0));\n    vec3 V = vec3(0.0, 0.0, 1.0);\n    vec3 L = normalize(vec3(0.55, 0.72, 0.65));\n    vec3 H = normalize(L + V);\n\n    // Refracted background tile + Beer-Lambert liquid tint + crisp Fresnel sky reflection\n    vec2 refrUv = uv + N.xy * 0.075;\n    vec2 rTile = floor((refrUv + vec2(0.0, 0.1)) * 9.0);\n    vec3 refrBg = mix(vec3(0.08, 0.14, 0.22), vec3(0.18, 0.28, 0.38), mod(rTile.x + rTile.y, 2.0));\n    // Highlight depth separation: closer droplets glow brighter cyan-white, background sheet deeper cobalt\n    vec3 tint = mix(vec3(0.18, 0.74, 0.94), vec3(0.06, 0.34, 0.62), smoothstep(1.15, 2.35, z));\n    float fres = 0.06 + 0.88 * pow(1.0 - max(dot(N, V), 0.0), 4.0);\n    float spec = pow(max(dot(N, H), 0.0), 72.0) * 1.9;\n    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));\n\n    col = mix(refrBg * tint * 1.65 + tint * 0.25, skyR, fres) + vec3(1.0, 0.98, 0.92) * spec;\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(sx - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "narrow-range-ssf-depth-filter",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:18.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5653,
      "std": 0.1105,
      "min": 0.4274,
      "max": 0.9672
     },
     "image": "/specimens/narrow-range-ssf-depth-filter-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "screen-space-fluid-rendering",
  "sph-fluids",
  "flip-pic-fluids",
  "position-based-fluids",
  "atrous-wavelet-filter"
 ],
 "extends": [
  "screen-space-fluid-rendering"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "flip-pic-fluids",
   "why": "FLIP particle positions splat sphere depths and additive thickness that the narrow-range filter smooths into a coherent liquid surface."
  },
  {
   "id": "water-caustics-realtime",
   "why": "Noise-free view normals reconstructed from the filtered depth buffer drive refractive bending and caustic projection."
  },
  {
   "id": "weighted-blended-oit",
   "why": "Aerated spray and foam sprites composite cleanly over the filtered opaque-style liquid depth surface."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-30T17:59:51.239Z",
  "draft": "data/drafts/volumes/narrow-range-ssf-depth-filter.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Truong & Yuksel, 2018",
 "url": "https://texelatlas.vercel.app/t/narrow-range-ssf-depth-filter/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 196.53,
  "tier": "extreme",
  "p50_ms": 6.4657,
  "p95_ms": 6.608,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "narrow-range-ssf-depth-filter-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 177.46,
   "tier": "extreme",
   "p50_ms": 2.8216,
   "p95_ms": 2.8752,
   "speedup_x": 2.29,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 141.95,
   "tier": "extreme",
   "p50_ms": 4.0883,
   "p95_ms": 4.1449,
   "speedup_x": 1.58,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}