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.
- Enable Fog: In your Global Volume, add the
Fogoverride. CheckEnableand ensure theFog Modeis set toExponential. - Volumetric Fog: Within the Fog settings, check
Volumetric Fog. This unlocks theAmbient DimmerandMean Free Pathproperties.- The Mean Free Path dictates how far light travels before scattering; a lower value makes the air appear thicker and denser.
- Light Shafts: Not all lights contribute to the volume. You must select your
Lightcomponent (e.g., a Directional Light), navigate to theShadowssection, and enableCast Shadows. Crucially, look for theVolumetric Multiplierproperty on the light itself. Setting this above0allows 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.