The Compatibility renderer, the one Godot uses for web exports, does not draw volumetric fog: in our Godot 4.7 test, turning it on with a density of 0.08 brightened 0 pixels. Draw the shaft yourself instead: an additive, unshaded quad that hangs from the window along the sun's direction and turns around its own axis to face the camera. In the same scene the script below brightened 1,907 of the pixels we checked, stayed lined up with the sun after it moved (0.00 degrees off) and hid itself when the sun went below the horizon.

The code
Add a MeshInstance3D where the light comes in, such as a window or a hole in the roof, attach this script and drag your DirectionalLight3D into sun. length and width are in metres. intensity is how bright the middle of the shaft gets. It takes its color from the sun's light_color.
extends MeshInstance3D
## A soft light shaft (god ray) that follows your sun and fades out when the sun sets.
## No volumetric fog, so it also works in the Compatibility renderer.
## Put this node where the light comes in (a window, a hole in the roof) and drag your DirectionalLight3D into "sun".
@export var sun: DirectionalLight3D
@export var length := 6.0: ## metres from the opening to where the shaft has faded out
set(v):
length = v
_build()
@export var width := 1.2: ## metres across
set(v):
width = v
_build()
@export var intensity := 0.5
const SHADER := """
shader_type spatial;
render_mode unshaded, blend_add, cull_disabled, depth_draw_never, shadows_disabled, fog_disabled;
uniform vec3 shaft_color : source_color = vec3(1.0);
uniform float intensity = 0.5;
void vertex() {
// turn the quad around the shaft's long axis so it always faces the camera
vec3 axis_point = (MODEL_MATRIX * vec4(0.0, VERTEX.y, 0.0, 1.0)).xyz;
vec3 axis = normalize(MODEL_MATRIX[1].xyz);
vec3 side = normalize(cross(axis, CAMERA_POSITION_WORLD - axis_point));
VERTEX = (inverse(MODEL_MATRIX) * vec4(axis_point + side * VERTEX.x, 1.0)).xyz;
}
void fragment() {
float across = 1.0 - abs(UV.x * 2.0 - 1.0); // 0 at the sides, 1 in the middle
float along = UV.y; // 0 at the opening, 1 at the far end
float a = smoothstep(0.0, 0.8, across) * smoothstep(0.0, 0.08, along) * (1.0 - smoothstep(0.35, 1.0, along));
ALBEDO = shaft_color * intensity * a;
}
"""
var _mat: ShaderMaterial
func _ready() -> void:
_mat = ShaderMaterial.new()
_mat.shader = Shader.new()
_mat.shader.code = SHADER
material_override = _mat
cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
_build()
func _build() -> void:
var q := QuadMesh.new()
q.size = Vector2(width, length)
q.center_offset = Vector3(0, -length * 0.5, 0) # the top edge sits on this node, the shaft hangs below it
mesh = q
extra_cull_margin = width # the shader turns the quad toward the camera
func _process(_delta: float) -> void:
if not _mat:
return
var up := Vector3.UP
var color := Color.WHITE
if sun:
up = sun.global_basis.z.normalized() # from the floor back toward the sun
color = sun.light_color
var side := up.cross(Vector3.FORWARD if absf(up.z) < 0.99 else Vector3.RIGHT).normalized()
global_basis = Basis(side, up, side.cross(up))
var fade := smoothstep(0.0, 0.2, up.y) # 0 once the sun is at or below the horizon
_mat.set_shader_parameter("shaft_color", color)
_mat.set_shader_parameter("intensity", intensity * fade)
visible = fade > 0.0
What we measured
A dark scene with a grey floor and a sun 55 degrees above the horizon. We compared each frame with the same frame without the shaft and counted the pixels that got brighter, checking every second pixel in each direction. Brightness is the average of red, green and blue, from 0 to 1. Two runs gave the same numbers.
- Volumetric fog on, density 0.08, with the light's
light_volumetric_fog_energyleft at 1.0: 0 pixels brighter. The air stayed at 0.034. - The script: 1,907 pixels brighter. A quarter of the way down the shaft the air went from 0.034 to 0.536, half way to 0.469. The air beside the shaft stayed at 0.034.
- Seen from 80 degrees to the side: 1,897 pixels with the script, 329 with a plain quad (the same shader without the
VERTEXline), because the plain quad is seen almost edge-on. - Sun lowered to 30 degrees: the shaft turned with it, 0.00 degrees between the shaft and the light, 1,923 pixels.
- Sun 5 degrees below the horizon: 0 pixels, and the node had set itself to
visible = false.
Why the quad turns toward the camera
A flat quad disappears when you look at it edge-on. The vertex() function rebuilds each corner from a point on the shaft's long axis plus a step sideways, at right angles to both the axis and the direction to the camera. The quad only spins around its own axis, so the shaft keeps its slant from the sun. Because the corners move away from where Godot thinks the mesh is, the script sets extra_cull_margin to the width so the shaft is not culled at the edge of the screen.
What to change
length: long enough to reach the floor. The shaft is brightest between 8% and 35% of its length and fades out toward the end, so it never stops in a hard line.widthandintensity: wide and dim for a soft glow through a window, narrow and brighter for a beam through a crack.blend_addonly adds light, so the shaft never darkens the room. On a bright sky it is hard to see, the same as additive particles on a white background.
Ready-made shafts: Light Shafts & God Rays VFX for Godot 4 has 25 3D presets (windows, blinds, stained glass, forest canopy, caves, underwater, stage lights) and 12 for 2D, each 3D one with dust in the beam and a light pool on the floor, following the sun the same way.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Light Shafts & God Rays VFX for Godot 4 has 37 ready-made shafts for 3D and 2D, with dust in the beam and a light pool on the floor, and they follow your sun too.
More how-tos: Auras, rings, beams and weather
- Magic aura particles that circle a character
- Charge-up particles that fly in to the middle
- Particle ring standing up instead of flat
- 2D particles from a sprite's shape
- A glowing circle on the ground
- A loot beam that never goes flat
- Chain lightning between enemies
- A tower's attack range ring
- Rain that follows the camera
- Rain falling through the roof
- Snow particles not falling
- orbit_velocity not working in 3D: use tangential_accel
- Rain falls through the player
- Snow that stays on roofs
- Emit particles along a Path3D