Course contentsShow
← Unreal Engine Game Development
Lesson 545 of 8807. Visual Fidelity and RenderingFree lesson

Integrating Light Shafts and God Rays

Utilize light function materials and volumetric fog interactions to generate cinematic light shafts that pierce through clouds and dense environment geometry.

In this lesson, you will learn how to orchestrate the interaction between Light Function materials and Volumetric Fog to craft cinematic, piercing "God Rays" that react to your environment’s geometry.

The Mechanism of Light Shafts

God rays are essentially the visible scattering of light as it passes through particles in the air (Volumetric Fog) and is occluded by static or dynamic objects. To create these, we don't just rely on bloom; we must control the light's "shadow" profile using a Light Function.

By applying a Light Function material to your Directional Light, you can project patterns—such as leaf shapes or cloud silhouettes—into the beam. When this light enters a region with Volumetric Fog enabled, the fog density acts as a medium, catching the light rays and making the "pierced" path visible to the player.

Practical Implementation

To set this up, create a new Material and set its Material Domain to Light Function. Inside, you can use a Panner node combined with a Texture Sample (a noise or cloud texture) to simulate moving, ethereal light shifts.

// Basic Light Function Logic
// Use a panner to simulate shifting clouds
float2 UV = TexCoord * TextureScale;
float3 Noise = TextureSample(CloudNoise, UV + (Time * Speed));

// Multiply by an intensity scalar
return Noise * LightIntensity;

Once the material is assigned to the Light Function Material slot of your Directional Light, ensure your Directional Light has Cast Volumetric Translucent Shadows enabled. This allows the light to respect the density of the fog.

Fine-Tuning the Effect

For the rays to truly "pierce," the contrast between the lit and shadowed areas is critical. Use the Volumetric Fog settings in your Exponential Height Fog component to adjust the Scattering Distribution. A higher value will create more pronounced, forward-facing rays. If the effect feels too faint, increase the Volumetric Fog Intensity on the light source itself to make the light shafts "catch" more density in the scene, effectively grounding your light shafts within the environment's volumetric data.

Key Takeaway: Cinematic light shafts are achieved by pairing a Light Function material to modulate the light's emission with Volumetric Fog to provide the medium necessary for the light to become visible as volumetric rays.