---
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"
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"
cost: "cheap"
authority: "Mitchell"
url: "https://texelatlas.vercel.app/t/volumetric-light-scattering-god-rays/"
sources_verified_at: "2026-11-29"
---
# Screen-space Volumetric Light Scattering (God Rays) (Mitchell)

> Fake sun shafts by blurring an occluder mask radially away from the sun's screen position and adding it over the frame.

## Reach for it when

- 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

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

Choose it as a very cheap sun-shaft effect on mobile, web and older hardware, or as an art-directed stylised rim of light.

Prefer [Froxel Volumetric Fog](https://texelatlas.vercel.app/t/froxel-volumetric-fog.md) for physically shadowed shafts from many lights and for shafts that persist when the sun is off-screen. Prefer [Exponential Height Fog](https://texelatlas.vercel.app/t/exponential-height-fog.md) when you only need haze. Use [Scalable Production Sky and Atmosphere (Hillaire)](https://texelatlas.vercel.app/t/hillaire-sky-atmosphere.md) for the sun colour.

## Cost

cheap — Fixed N texture samples per pixel (often 32 to 100) in a post pass; run at reduced resolution to cut cost.
Measured GPU Weight: 43.37× baseline (heavy) — 1.4269 ms median / 1.4553 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 37.84× baseline (heavy) — 0.6017 ms median (2.37× faster on L4).
Ampere A100 scaling: 25.08× baseline (heavy) — 0.7223 ms median (1.98× faster on A100).

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

## Engine support

- babylonjs: builtin — `new BABYLON.VolumetricLightScatteringPostProcess('vls', 1.0, camera, mesh, 100, ..., engine)` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/PostProcesses/volumetricLightScatteringPostProcess.ts, checked 2026-12-01)
- blender: builtin — `Compositor > Add > Filter > Glare, Glare Type = Sun Beams` (evidence: https://docs.blender.org/manual/en/5.2/compositing/types/filter/glare.html, checked 2026-12-01) — Screen-space crepuscular rays in the compositor.
- threejs: official — `import { godrays } from 'three/addons/tsl/display/GodraysNode.js'` (evidence: https://github.com/mrdoob/three.js/blob/r187/examples/jsm/tsl/display/GodraysNode.js, checked 2026-12-01)
- unreal: builtin — `Directional Light > Light Shafts > Light Shaft Bloom / Light Shaft Occlusion` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/using-light-shafts-in-unreal-engine, checked 2026-12-01) — Screen-space light shafts; Volumetric Fog also gives true volumetric scattering.

## Dataflow

- Inputs: depth, ldr-image
- Outputs: ldr-image
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu

## Presets

### Ray-marched fog light shafts through a slotted wall (glsl-fragment; rendered 2026-11-29)

```json
{
  "STEPS": 72,
  "SIGMA": 0.45
}
```

```glsl
// Light shafts by ray-marching homogeneous fog: at each sample a shadow test against a slotted wall decides
// whether the point-light behind it is visible. In-scattering is weighted by the Henyey-Greenstein phase
// and view transmittance. The shafts also land on the floor.
const int STEPS = 72;
const float SIGMA = 0.45;
const float WALL_Z = -1.0;
const vec3 LIGHT_POS = vec3(1.2, 2.2, -7.0);

bool slit(vec3 q) { return abs(fract(q.x * 0.7 + 0.5) - 0.5) < 0.08 && q.y < 2.6 && q.y > -1.0; }
float vis(vec3 p) {
  vec3 d = LIGHT_POS - p; float t = (WALL_Z - p.z) / d.z;
  if (t < 0.0) return 1.0;
  return slit(p + d * t) ? 1.0 : 0.0;
}
float 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)); }
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  vec3 ro = vec3(0.0, 0.8, 4.0), rd = normalize(vec3(uv.x, uv.y - 0.06, -1.2));
  float tw = (WALL_Z - ro.z) / rd.z;
  float tf = rd.y < 0.0 ? (-1.0 - ro.y) / rd.y : 1e5;
  float tend = min(tw, tf); vec3 pe = ro + rd * tend;
  vec3 col = vec3(0.01, 0.012, 0.018);
  if (tend == tw && slit(pe)) col = vec3(1.0, 0.9, 0.7) * 3.0;
  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);
  float dither = fract(sin(dot(fragCoord, vec2(12.9898, 78.233))) * 43758.5453);
  float ds = tend / float(STEPS); vec3 sc = vec3(0.0);
  for (int i = 0; i < STEPS; i++) {
    float t = (float(i) + dither) * ds; vec3 p = ro + rd * t;
    float v = vis(p); if (v < 0.5) continue;
    vec3 Ld = normalize(LIGHT_POS - p);
    sc += vec3(1.0, 0.92, 0.75) * v * SIGMA * ds * exp(-SIGMA * t) * hg(dot(Ld, rd), 0.55) * 22.0;
  }
  col = col * exp(-SIGMA * tend) + sc;
  col = 1.0 - exp(-col * 1.3);
  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);
}

```

Attribution: written for this index

## Combines with

- [Exponential Height Fog](https://texelatlas.vercel.app/t/exponential-height-fog.md): Fog makes the ground haze receive the shaft; the shaft pass adds directional brightness.

## Combination ideas

- [Light shafts for any photo](https://texelatlas.vercel.app/ideas/photo-depth-god-rays/)

## Sources

1. [primary] Kenny Mitchell Volumetric Light Scattering as a Post-Process. GPU Gems 3, 2007. https://developer.nvidia.com/gpugems/gpugems3/part-ii-light-and-shadows/chapter-13-volumetric-light-scattering-post-process (verified via http on 2026-11-29)

## Cite this entry

Texel. "Screen-space Volumetric Light Scattering (God Rays)." https://texelatlas.vercel.app/t/volumetric-light-scattering-god-rays/ (accessed 2026-12-01).
