{
 "id": "soft-particles",
 "title": "Soft particles (depth-fade billboards)",
 "aliases": [
  "depth fade",
  "depth-blended sprites"
 ],
 "domain": "simulation",
 "subdomain": "particles & VFX",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2007,
 "inputs": [
  "particles",
  "depth"
 ],
 "outputs": [
  "hdr-image"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Fade a particle sprite's opacity by how far it sits in front of the opaque scene depth, so smoke and fire blend into surfaces instead of cutting a hard line.",
 "how_it_works": "While drawing the quad, the fragment shader samples the scene depth buffer at its screen position and converts both that depth and the particle's own fragment depth to the same linear view-space measure. The difference is the thickness of empty space between the sprite and the surface behind it. The alpha is multiplied by a saturating function of that difference divided by a fade distance, often a smoothstep or a contrast curve. Where the sprite touches geometry the difference approaches zero and alpha goes to zero, hiding the intersection seam. The effect needs the opaque depth available as a texture while writing to a colour target with depth test off or read-only, so renderers copy depth or bind the depth attachment read-only. Refinements add a near-camera fade to avoid sprites clipping the near plane, and scale the fade distance by sprite size or density.",
 "when_to_use": "Choose it whenever billboard smoke, fire, dust or mist touches the ground or walls. Prefer `volume-ray-marching` or `froxel-volumetric-fog` when you need genuine thickness-based extinction and lighting, which soft particles only imitate at the edges. Prefer `particle-systems` plain rendering for effects that never meet geometry. It is a final shading step in `gpu-particle-systems`, and works with depth available from deferred or forward depth prepasses.",
 "cost": {
  "class": "cheap",
  "notes": "One depth texture fetch per particle fragment; the main cost is overdraw you already pay for and a possible depth copy."
 },
 "failure_modes": [
  "Particles inside large nearby volumes fade out entirely when the fade distance is too large relative to sprite size",
  "MSAA depth must be resolved or sampled per sample, otherwise edges show halos",
  "Reading and writing the same depth buffer without a copy is undefined on some platforms",
  "Only fades along the view ray, so sprite edges seen at grazing angles still intersect visibly",
  "Near-plane clipping hard-cuts big sprites unless a camera-distance fade is added"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf",
   "type": "web",
   "title": "Soft Particles (NVIDIA SDK 10 white paper)",
   "authors": [
    "Tristan Lorach"
   ],
   "year": null,
   "venue": "developer.download.nvidia.com",
   "url": "https://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260926023050/https://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf",
     "timestamp": "20260926023050"
    },
    "page_title": null,
    "host": "developer.download.nvidia.com",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "lorachsoft"
  }
 ],
 "presets": [
  {
   "id": "soft-particles-live",
   "title": "Soft Particles — hard billboard intersection clip (left) vs smooth depth-fade alpha (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_FADE_DIST": 0.48,
    "P_SMOKE_DENS": 1.05,
    "P_TURB_SPEED": 0.85,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_FADE_DIST = 0.48; // P Depth Fade Range [0.05, 1.2, 0.02]\nconst float P_SMOKE_DENS = 1.05; // P Plume Opacity [0.3, 1.8, 0.05]\nconst float P_TURB_SPEED = 0.85; // P Rise Speed [0.0, 2.2, 0.05]\nconst float P_SPLIT = 0.48; // P Hard / Soft Split [0.0, 1.0, 0.02]\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(127.1, 311.7));\n  p += dot(p, p + 34.5);\n  return fract(p.x * p.y);\n}\n\nfloat noise2(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  f = f * f * (3.0 - 2.0 * f);\n  return mix(\n    mix(hash21(i), hash21(i + vec2(1.0, 0.0)), f.x),\n    mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), f.x),\n    f.y\n  );\n}\n\nfloat fbm(vec2 p) {\n  float s = 0.0;\n  float a = 0.5;\n  for (int i = 0; i < 4; i++) {\n    s += a * noise2(p);\n    p = p * 2.04 + vec2(13.1, 7.7);\n    a *= 0.5;\n  }\n  return s;\n}\n\nfloat sdBox(vec3 p, vec3 b) {\n  vec3 q = abs(p) - b;\n  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);\n}\n\n// Solid opaque scene: tiled floor, angled concrete wall, and central pillar intersecting smoke sprites\nvec2 mapOpaque(vec3 p) {\n  vec2 res = vec2(p.y + 0.62, 1.0); // floor\n  float dWall = sdBox(p - vec3(0.0, 0.2, -0.78), vec3(2.4, 1.2, 0.14));\n  if (dWall < res.x) res = vec2(dWall, 2.0);\n  float dPillar = sdBox(p - vec3(-0.02, -0.05, 0.08), vec3(0.22, 0.72, 0.22)) - 0.02;\n  if (dPillar < res.x) res = vec2(dPillar, 3.0);\n  float dCrate = sdBox(p - vec3(0.68, -0.34, 0.22), vec3(0.28, 0.28, 0.28)) - 0.02;\n  if (dCrate < res.x) res = vec2(dCrate, 3.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapOpaque(p + e.xyy).x - mapOpaque(p - e.xyy).x,\n    mapOpaque(p + e.yxy).x - mapOpaque(p - e.yxy).x,\n    mapOpaque(p + e.yyx).x - mapOpaque(p - e.yyx).x\n  ));\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 screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isSoft = screenX >= split;\n  float fadeDist = max(P_FADE_DIST, 0.02);\n  float smokeDens = clamp(P_SMOKE_DENS, 0.2, 2.0);\n  float tAnim = iTime * max(P_TURB_SPEED, 0.0);\n\n  vec3 ro = vec3(0.0, 0.24, 2.35);\n  vec3 rd = normalize(vec3(uv - vec2(0.0, 0.06), -1.55));\n\n  // 1. Render opaque scene depth buffer (zScene) and lit shading\n  float tScene = 0.0;\n  float matId = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapOpaque(ro + rd * tScene);\n    if (h.x < 0.002) { hit = true; matId = h.y; break; }\n    tScene += h.x;\n    if (tScene > 9.0) break;\n  }\n\n  vec3 col = mix(vec3(0.04, 0.06, 0.10), vec3(0.11, 0.15, 0.22), smoothstep(-0.4, 0.6, uv.y));\n  if (hit) {\n    vec3 p = ro + rd * tScene;\n    vec3 n = calcNormal(p);\n    vec3 lDir = normalize(vec3(0.52, 0.84, 0.45));\n    float diff = max(dot(n, lDir), 0.0);\n    float ao = clamp(0.42 + 0.58 * mapOpaque(p + n * 0.22).x / 0.22, 0.2, 1.0);\n    vec3 alb = vec3(0.32, 0.36, 0.42);\n    if (matId < 1.5) {\n      float chk = mod(floor(p.x * 2.5) + floor(p.z * 2.5), 2.0);\n      alb = mix(vec3(0.16, 0.19, 0.24), vec3(0.28, 0.32, 0.38), chk);\n    } else if (matId > 2.5) {\n      alb = vec3(0.42, 0.46, 0.52);\n    }\n    col = alb * (0.25 + 0.85 * diff) * ao;\n  } else {\n    tScene = 9.0;\n  }\n\n  // 2. Composite 10 back-to-front camera-facing smoke billboard sprites that cut through the floor & pillar\n  for (int i = 0; i < 10; i++) {\n    float fi = float(i);\n    float zPlane = -0.35 + fi * 0.11;\n    float tSprite = (zPlane - ro.z) / rd.z;\n    if (tSprite <= 0.05) continue;\n\n    // Depth difference between opaque scene and particle sprite\n    float deltaZ = tScene - tSprite;\n    if (deltaZ <= 0.0) continue; // behind opaque geometry\n\n    vec3 pHit = ro + rd * tSprite;\n    vec2 center = vec2(-0.55 + mod(fi * 0.37, 1.18), -0.44 + mod(fi * 0.19 + tAnim * 0.16, 0.72));\n    float rad = 0.44 + 0.06 * sin(fi * 2.1);\n    vec2 local = (pHit.xy - center) / rad;\n    float r2 = dot(local, local);\n    if (r2 >= 1.0) continue;\n\n    float puffNoise = fbm(local * 2.6 + vec2(fi * 3.1, -tAnim * 0.55));\n    float radial = pow(max(1.0 - r2, 0.0), 1.35);\n    float baseAlpha = clamp(radial * (0.45 + 0.95 * puffNoise) * 0.62 * smokeDens, 0.0, 0.92);\n\n    // Core technique: Hard depth-test clip (left) vs Soft Particle depth fade (right)\n    float depthFade = isSoft ? smoothstep(0.0, fadeDist, deltaZ) : 1.0;\n    float alpha = baseAlpha * depthFade;\n\n    // Subtle warm backlit smoke shading\n    float topLit = clamp(local.y * 0.5 + 0.55 + puffNoise * 0.25, 0.0, 1.0);\n    vec3 smokeCol = mix(vec3(0.28, 0.34, 0.44), vec3(0.98, 0.84, 0.68), topLit);\n    // Highlight the ugly hard intersection seam on left so the failure mode is crystal clear\n    if (!isSoft && deltaZ < 0.045) {\n      smokeCol = mix(smokeCol, vec3(1.0, 0.42, 0.28), 0.35);\n    }\n    col = mix(col, smokeCol, alpha);\n  }\n\n  // Split divider\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\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": "soft-particles",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:36.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7107,
      "std": 0.0975,
      "min": 0.2065,
      "max": 0.9014
     },
     "image": "/specimens/soft-particles-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "particle-systems",
  "gpu-particle-systems",
  "volume-ray-marching",
  "froxel-volumetric-fog",
  "exponential-height-fog"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "gpu-particle-systems",
   "why": "The instanced sprite fragment shader reads scene depth and fades alpha at intersections."
  },
  {
   "id": "froxel-volumetric-fog",
   "why": "Soft-faded sprites sit inside the fog, and fog light scattering is applied on top for consistent atmosphere."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/simulation/soft-particles.json"
 },
 "solves": [
  "smoke sprites show a hard line where they hit the floor",
  "billboard fire cuts visibly through nearby walls",
  "particle quads need to fade out against scene geometry",
  "want sprites to blend softly into surfaces behind them"
 ],
 "authority": "Lorach",
 "url": "https://texelatlas.vercel.app/t/soft-particles/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 27.45,
  "tier": "heavy",
  "p50_ms": 0.851,
  "p95_ms": 0.9075,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "soft-particles-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 25.74,
   "tier": "heavy",
   "p50_ms": 0.4093,
   "p95_ms": 0.4145,
   "speedup_x": 2.08,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 17.92,
   "tier": "moderate",
   "p50_ms": 0.5162,
   "p95_ms": 0.5273,
   "speedup_x": 1.65,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}