Screen-space Volumetric Light Scattering (God Rays)
Fake sun shafts by blurring an occluder mask radially away from the sun's screen position and adding it over the frame.
Also known as crepuscular rays, light shafts, radial blur god rays
In the family Atmosphere, water & volumes, light shafts
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Official add-on | import { godrays } from 'three/addons/tsl/display/GodraysNode.js' docs |
| Babylon.js 9.38.0 | Built in | new BABYLON.VolumetricLightScatteringPostProcess('vls', 1.0, camera, mesh, 100, ..., engine) docs |
| Godot 4.7 | None found | Godot provides 3D froxel volumetric fog, not a 2D screen-space radial god-ray blur pass. |
| Unity | None found | HDRP uses physically based froxel volumetric fog rather than a screen-space radial-blur god-rays post-process. |
| Unreal 5.7 | Built in | Directional Light > Light Shafts > Light Shaft Bloom / Light Shaft Occlusion docs Screen-space light shafts; Volumetric Fog also gives true volumetric scattering. |
| Blender 5.2 | Built in | Compositor > Add > Filter > Glare, Glare Type = Sun Beams docs Screen-space crepuscular rays in the compositor. |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
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 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 Scalable Production Sky and Atmosphere (Hillaire) for the sun colour.
Field marks
- 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
Presets
Ray-marched fog light shafts through a slotted wall
{
"STEPS": 72,
"SIGMA": 0.45
}Show GLSL (37 lines)
// 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
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| volumetric-light-scattering-god-rays-specimen | Tesla T4 1920x1080 | 43.4× baseline (heavy) · 1.43 ms / 1.46 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| volumetric-light-scattering-god-rays-specimen | NVIDIA L4 1920x1080 | 37.8× baseline (heavy) · 0.602 ms / 0.612 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| volumetric-light-scattering-god-rays-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 25.1× baseline (heavy) · 0.722 ms / 0.724 ms · 2.0× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Light shafts for any photo: Add sun shafts to a single photo or video frame in the browser, occluded by the real objects in the picture. Monocular depth supplies both the occluder mask and the per-pixel distance that sets how much haze sits in front.
- Exponential Height Fog: Fog makes the ground haze receive the shaft; the shaft pass adds directional brightness.
Sources
- primaryKenny Mitchell. Volumetric Light Scattering as a Post-Process. GPU Gems 3, 2007.Verified via live page · 2026-11-29