Course contentsShow
← Unity Game Development
Lesson 710 of 82810. VFX and Post-ProcessingFree lesson

Implementing Volumetric Lighting for Atmospheric Depth

You will learn to enable and tweak volumetric fog and light shafts to add atmospheric depth and cinematic lighting quality.

In this lesson, you will learn how to enable and fine-tune volumetric fog and light shafts to introduce true atmospheric density and cinematic light scattering into your scenes.

Understanding Volumetric Lighting

While standard lighting calculates color at a surface, volumetric lighting simulates how light interacts with particles—like dust, mist, or smoke—suspended in the air. By enabling this, you stop treating light as an invisible force and start treating it as a physical medium, creating the "God ray" effect that adds immense depth and scale to your environments.

Implementation in URP

To implement this, you must first ensure your Universal Render Pipeline Asset has Volumetric Rendering enabled. Once active, the atmospheric behavior is governed by your Global Volume settings.

  1. Enable Fog: In your Global Volume, add the Fog override. Check Enable and ensure the Fog Mode is set to Exponential.
  2. Volumetric Fog: Within the Fog settings, check Volumetric Fog. This unlocks the Ambient Dimmer and Mean Free Path properties.
    • The Mean Free Path dictates how far light travels before scattering; a lower value makes the air appear thicker and denser.
  3. Light Shafts: Not all lights contribute to the volume. You must select your Light component (e.g., a Directional Light), navigate to the Shadows section, and enable Cast Shadows. Crucially, look for the Volumetric Multiplier property on the light itself. Setting this above 0 allows that specific light to create shafts in the fog.

Controlling Density via Scripting

If you need the atmosphere to thicken dynamically—for instance, as a storm rolls in—you can manipulate the fog density through the Volume profile component via script:

using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public void UpdateFogDensity(Volume globalVolume, float newDensity) {
    if (globalVolume.profile.TryGet(out Fog fog)) {
        fog.meanFreePath.value = newDensity;
    }
}

By balancing the light's Volumetric Multiplier with the global Fog density, you create a cohesive visual layer that makes your environment feel tangible rather than hollow.

Key Takeaway: Volumetric lighting transforms empty space into a physical medium by simulating light scattering, effectively grounding your objects within a rich, atmospheric environment.