3D Level Design: Control Your Lighting in Unity Using Light Layers
In this article, we are going to cover using Light Layers to only cast light on certain objects which increases performance and doesn’t effect the scene’s aesthetics.
Before getting started, we want to make sure Light Layers is enabled in the HDRP settings. This can be check in the Project Settings.
Looking at the image below, we have several Spot Lights interacting with a volumetric fog and producing light on the test tube.
The producing light in the scene is expensive since it is cast on everything within range, so you will want to limit the amount of light that is casting on Everything in the scene.
We can achieve this accessing the Light Layer setting by select the Gear Icon in the General section.
This will add the Light Layer drop down. It gives you several layers and when you set the Light Layer, the light will only interact with objects in that Light Layer.
The picture above shows the spot lights around the test tube being set to the Light Layer of Nothing. The light is no longer casting on the test tube, but it is still interacting with the volumetric fog.
Now, we are only going to have the spot lights cast on test tube.
We set the Spot Lights to a certain Light Layer (Light Layer 5).
We will need to set the test tube’s Mesh Renderer to the same Light Layer.
This now has the light only interacting with only the test tube and volumetric fog (if there is any).
You can have several objects and lights set to the same light layer to create dynamic lighting with complete control and keep the performance cost down.