{
 "id": "volumetric-light-scattering-god-rays",
 "title": "Screen-space Volumetric Light Scattering (God Rays)",
 "aliases": [
  "crepuscular rays",
  "light shafts",
  "radial blur god rays"
 ],
 "domain": "volumes",
 "subdomain": "light shafts",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu"
 ],
 "year_introduced": 2008,
 "inputs": [
  "depth",
  "ldr-image"
 ],
 "outputs": [
  "ldr-image"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Fake sun shafts by blurring an occluder mask radially away from the sun's screen position and adding it over the frame.",
 "how_it_works": "Render a mask in which the sky and sun are bright and every occluder is black (the depth buffer or a separate pass can supply this). In a post pass, for each pixel, take N samples along the line toward the sun's screen-space position, accumulating the mask with a decay that falls as the sample moves away from the pixel, and a weight and exposure controls. The sum approximates integrating scattered sunlight along the view ray through the medium as if the medium had uniform density and the mask were the visibility to the sun. The result is added to the scene colour, usually only when the sun is in front of the camera and faded out by the dot product of view and sun direction. Resolution can be quarter size with a bilateral upsample.",
 "when_to_use": "Choose it as a very cheap sun-shaft effect on mobile, web and older hardware, or as an art-directed stylised rim of light.\n\nPrefer `froxel-volumetric-fog` for physically shadowed shafts from many lights and for shafts that persist when the sun is off-screen. Prefer `exponential-height-fog` when you only need haze. Use `hillaire-sky-atmosphere` for the sun colour.",
 "cost": {
  "class": "cheap",
  "notes": "Fixed N texture samples per pixel (often 32 to 100) in a post pass; run at reduced resolution to cut cost."
 },
 "failure_modes": [
  "Effect disappears abruptly when the sun leaves the screen, since it needs the sun position on screen",
  "Banding or repeated ghost rays with too few samples along the blur direction",
  "Bright foreground objects (not the sun) bloom radial streaks if the mask is thresholded poorly",
  "Shafts do not show through translucent occluders or reflect the actual scattering medium density",
  "Rays appear in front of objects if the sky-only mask ignores depth of transparent surfaces"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://developer.nvidia.com/gpugems/gpugems3/part-ii-light-and-shadows/chapter-13-volumetric-light-scattering-post-process",
   "type": "web",
   "title": "Volumetric Light Scattering as a Post-Process",
   "authors": [
    "Kenny Mitchell"
   ],
   "year": null,
   "venue": "GPU Gems 3, 2007",
   "url": "https://developer.nvidia.com/gpugems/gpugems3/part-ii-light-and-shadows/chapter-13-volumetric-light-scattering-post-process",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261112162422/https://developer.nvidia.com/gpugems/gpugems3/part-ii-light-and-shadows/chapter-13-volumetric-light-scattering-post-process",
     "timestamp": "20261112162422"
    },
    "page_title": "Chapter 13. Volumetric Light Scattering as a Post-Process",
    "host": "developer.nvidia.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems3/part-ii-light-and-shadows/chapter-13-volumetric-light-scattering-post-process → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems3/part-ii-light-and-shadows/chapter-13-volumetric-light-scattering-post-process → 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": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "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": 0.95,
   "__bib": "mitchellvolumetric"
  }
 ],
 "presets": [
  {
   "id": "volumetric-light-scattering-god-rays-specimen",
   "title": "Ray-marched fog light shafts through a slotted wall",
   "runtime": "glsl-fragment",
   "params": {
    "STEPS": 72,
    "SIGMA": 0.45
   },
   "code": "// Light shafts by ray-marching homogeneous fog: at each sample a shadow test against a slotted wall decides\n// whether the point-light behind it is visible. In-scattering is weighted by the Henyey-Greenstein phase\n// and view transmittance. The shafts also land on the floor.\nconst int STEPS = 72;\nconst float SIGMA = 0.45;\nconst float WALL_Z = -1.0;\nconst vec3 LIGHT_POS = vec3(1.2, 2.2, -7.0);\n\nbool slit(vec3 q) { return abs(fract(q.x * 0.7 + 0.5) - 0.5) < 0.08 && q.y < 2.6 && q.y > -1.0; }\nfloat vis(vec3 p) {\n  vec3 d = LIGHT_POS - p; float t = (WALL_Z - p.z) / d.z;\n  if (t < 0.0) return 1.0;\n  return slit(p + d * t) ? 1.0 : 0.0;\n}\nfloat hg(float c, float g) { float g2 = g * g; return (1.0 - g2) / (12.566 * pow(1.0 + g2 - 2.0 * g * c, 1.5)); }\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  vec3 ro = vec3(0.0, 0.8, 4.0), rd = normalize(vec3(uv.x, uv.y - 0.06, -1.2));\n  float tw = (WALL_Z - ro.z) / rd.z;\n  float tf = rd.y < 0.0 ? (-1.0 - ro.y) / rd.y : 1e5;\n  float tend = min(tw, tf); vec3 pe = ro + rd * tend;\n  vec3 col = vec3(0.01, 0.012, 0.018);\n  if (tend == tw && slit(pe)) col = vec3(1.0, 0.9, 0.7) * 3.0;\n  if (tend == tf) col = vec3(0.03, 0.03, 0.035) + vec3(1.0, 0.9, 0.7) * 0.7 * vis(pe) * exp(-0.05 * tend);\n  float dither = fract(sin(dot(fragCoord, vec2(12.9898, 78.233))) * 43758.5453);\n  float ds = tend / float(STEPS); vec3 sc = vec3(0.0);\n  for (int i = 0; i < STEPS; i++) {\n    float t = (float(i) + dither) * ds; vec3 p = ro + rd * t;\n    float v = vis(p); if (v < 0.5) continue;\n    vec3 Ld = normalize(LIGHT_POS - p);\n    sc += vec3(1.0, 0.92, 0.75) * v * SIGMA * ds * exp(-SIGMA * t) * hg(dot(Ld, rd), 0.55) * 22.0;\n  }\n  col = col * exp(-SIGMA * tend) + sc;\n  col = 1.0 - exp(-col * 1.3);\n  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "volumetric-light-scattering-god-rays",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5152,
      "std": 0.3138,
      "unique_colors": 66
     },
     "image": "/specimens/volumetric-light-scattering-god-rays-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "froxel-volumetric-fog",
  "exponential-height-fog",
  "rayleigh-mie-single-scattering"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "exponential-height-fog",
   "why": "Fog makes the ground haze receive the shaft; the shaft pass adds directional brightness."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/volumes/volumetric-light-scattering-god-rays.json"
 },
 "solves": [
  "want sun shafts on mobile or web cheaply",
  "light beams through trees or clouds",
  "stylised glow around the sun behind occluders",
  "volumetric rays without raymarching a volume",
  "cheap radial light streaks"
 ],
 "authority": "Mitchell",
 "url": "https://texelatlas.vercel.app/t/volumetric-light-scattering-god-rays/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 43.37,
  "tier": "heavy",
  "p50_ms": 1.4269,
  "p95_ms": 1.4553,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "volumetric-light-scattering-god-rays-specimen",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 37.84,
   "tier": "heavy",
   "p50_ms": 0.6017,
   "p95_ms": 0.612,
   "speedup_x": 2.37,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 25.08,
   "tier": "heavy",
   "p50_ms": 0.7223,
   "p95_ms": 0.7236,
   "speedup_x": 1.98,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}