Volumetric Lighting in Unity

By Saif Jouda | June. 6 2024

Introduction

Volumetric Lighting Example

What is Volumetric Lighting?

Volumetric lighting, also known as "god rays," is a lighting technique commonly used in computer graphics to simulate the way light interacts with a medium such as fog, smoke, dust, or water. This technique adds realism to scenes by simulating the scattering and absorption of light as it passes through these media, creating visible beams or shafts of light.

How Does It Work?

There are several ways to create volumetric lighting, but most techniques involve casting rays from the camera through the scene, sampling the medium at intervals along each ray, and calculating lighting effects such as scattering and absorption at these points.

What Are the Challenges?

What is the Solution?

There is a way to mimic volumetric lighting effects in Unity using shapes and Shader Graph. This approach is lightweight in terms of performance and is compatible with both HDRP and URP.

Step 1: Blender

The Shape

Start by creating a cylinder in Blender, removing its top and bottom faces, and narrowing the upper section. This should result in a cone or 'megaphone' shape.

Shape

UV Mapping

Extend the vertices to cover the entire UV map. This step is crucial for the shader we are going to create.

Before UV Mapping After UV Mapping

Double-Sided Faces

To ensure the volumetric lighting effect is visible from all angles, we need to make the cylinder double-sided. Add a Solidify modifier and set the thickness to a very small value, such as 0.0001m.

Solidify Modifier

Step 2: Unity

Unity Setup

Create a spotlight in Unity and import the 'cone' we created in Blender. Parent the cone to the spotlight, then rotate and scale the cone object so that it aligns with the light cone created by the spotlight. Remember to disable shadows for the cone object.

Unity Setup

Shader Graph

Create an unlit shader graph.

Shader Graph

Results

The final product is a volumetric light that is both lightweight and compatible.

Final Volumetric Lighting