In this lesson, you will learn how to unify volumetric fog with light cookies to generate high-fidelity, physical light rays that give your scenes atmospheric depth.
The Core Concept: Volumetrics vs. Cookies
While standard lights simply illuminate surfaces, volumetric lighting simulates the interaction between light and suspended particles (dust, mist, or smoke) in the air. To achieve this in Unity, we rely on the HDRP (High Definition Render Pipeline) or the URP (Universal Render Pipeline) fog settings.
The "Volumetric Fog" component acts as the physical medium, but it is often uniform. To give the light "shape" or "character"—such as rays filtering through a dusty window or broken canopy—we use Light Cookies. A cookie is a greyscale mask applied to the light source that acts like a stencil, determining where the light passes through and where it is blocked.
Implementing the Light Shaft
When you enable Volumetrics on a Light component and set its Emission Intensity, the light will begin to scatter through the fog. To add the "Shaft" effect:
- Enable Volumetrics: In your light component, toggle the
Volumetric Multiplier. - Apply a Cookie: Assign a high-contrast black-and-white texture to the
Cookieslot. This texture will act as a physical obstruction (like a window frame), causing the volumetric light to render in defined, sharp bands rather than a generic cone. - Control Density: In your
Volumeprofile, adjust theFogsettings. Specifically, tune theAnisotropyvalue. A higher value (close to 1.0) simulates forward scattering, which makes the light rays appear much more prominent when the player looks toward the light source.
// Example: Modifying Volumetric light intensity via script
// based on atmospheric density levels
Light lightSource = GetComponent<Light>();
lightSource.useColorTemperature = true;
// Increasing volumetric multiplier allows the light
// to 'cut' through the fog density more aggressively
lightSource.volumetricMultiplier = 1.5f;
By combining a textured cookie with high-anisotropy volumetric fog, you transform flat, boring lights into immersive, physical light shafts that respond to the geometry of your scene.
Key Takeaway: Volumetric light shafts are created by applying light cookies to act as masks within a dense, anisotropic volumetric fog medium.