Baltor Get started

Gallery / Godot shaders

Screen-space light shafts from the sky

In your harnessGodot shaderMIT

Crepuscular rays as a post process: sky pixels near the sun become light sources, and each pixel marches toward the sun's screen position accumulating them with decay, so objects cut dark shafts into the glow.

Render of Screen-space light shafts from the sky
The render its check recorded in Godot 4.7.2, 256 by 256 pixels.

What it takes and gives

Shader type
spatial
Render modes
unshaded, cull_disabled, depth_test_disabled, depth_draw_never, skip_vertex_transform, fog_disabled
Parameters
screen_texture (sampler2D), depth_texture (sampler2D), sun_azimuth_degrees (float = 8), sun_elevation_degrees (float = 9), ray_color (vec4 = 1, 0.86, 0.6, 1), samples (int = 48), density (float = 0.85), decay (float = 0.965) and 4 more
Use it on
A MeshInstance3D with a 2 x 2 QuadMesh, material.tres as its material override and a large extra cull margin, as in demo.tscn.
Result
Warm shafts of light streaming from a glow near the horizon between the pillars.
Renderers
compatibility: compiled and rendered, forward plus: not verified, mobile: not verified
Placement
res://baltor/godot_shaders/post_light_scattering/

Limits. Only works while the sun is on or near the screen; rays fade when it leaves. Light sources are sky pixels, so bright emissive objects do not cast rays. Long marches at high resolution are costly. The pass reads Godot's screen texture after opaque geometry, so transparent objects drawn after it are not processed and its order among other transparent passes is not controlled.

Details

Kind
Godot shader
Engine
Godot 4.3 or later
Files
11 files, 83.1 KB
Licence
MIT
Declared effects
reads files, runs commands
Checked with
Godot 4.7.2, opengl3 compatibility (Mesa llvmpipe, Xvfb)
Checks
contract static, engine run, engine log clean, shader in scene, capture written, render not uniform, shader changes pixels
Techniques
Light scattering as a post process (radial march with decay, after Mitchell 2007), Projection of a direction to the screen, Depth-based sky mask
Tags
godot shader, spatial, post-process, god rays, light shafts, crepuscular rays, sun, full-screen
Identity
library.supply.creative_originals.5a436d685dcb4932be940530.f2526a97df3a73ac
Version
f2526a97df3a73ac61536179ab06719874f4c8d3bc27552d391099117b1a7195

The version is the SHA-256 of the item your harness downloads; every file in it names its own checksum.

Something wrong with this item, its rights or its safety? Report it on the support page, or from your harness after a download.