Light Layers
The High Definition Render Pipeline (HDRP) allows you to use Light Layers, which are LayerMasks, to make Lights in your Scene only light up specific Meshes. You set Light Layers for Lights and Meshes to make Lights only affect Meshes that are on corresponding Light Layers.
Enabling Light Layers
To use Light Layers, you must enable them in your Project’s HDRP Asset. You can then enable Light Layers in the Frame Settings to set your Cameras to process Light Layers.
- Select the HDRP Asset in the Project window and, in the Inspector, go to Lighting > Light Layers and enable the Enable checkbox.
- To enable Light Layers for all Cameras, open the HDRP Global Settings, go to the Frame Settings (Default Values) > Camera section and, in the Rendering section, enable the Light Layers checkbox.
To override the Frame Settings for Cameras and set Light Layers on an individual basis:
- Click on a Camera in the Scene view or Hierarchy window to view its properties in the Inspector.
- Go to the General section and enable the Custom Frame Settings checkbox. This exposes the Frame Settings Overrides, which you can use to customize this Camera only.
- In the Lighting section, enable the Light Layers checkbox to make this Camera use Light Layers.
Using Light Layers
After you enable Light Layers, you can then use them to decouple Meshes from certain Lights in your Scene. To do this:
- Click on a Light in the Hierarchy or the Scene view to view it in the Inspector.
- Enable additional properties in the General section to expose the Light Layer property.
- Use the Light Layer property drop-down to select which Light Layers this Light affects.
- Click on a Mesh Renderer or Terrain in the Hierarchy or the Scene view to view it in the Inspector.
- Use the Rendering Layer Mask drop-down (See MeshRenderer for GameObjects or OtherSettings for Terrain) to select which Light Layers affect this Mesh Renderer or Terrain. When you enable Light Layers, a Light only affects a Mesh Renderer or Terrain if they both use a matching Light Layer.
Shadow Light Layers
When using Light Layers, Meshes only cast shadows for Lights on the same Light Layer as them. This is because HDRP synchronizes Light Layers and shadow Light Layers by default, so every Mesh that receives light, also casts shadows for it. To make a Mesh cast shadows without the Light also affecting its lighting, you must decouple the shadow Light Layers from that Light's Light Layers.
To do this:
- Click on a Light in the Hierarchy or the Scene view to view it in the Inspector.
- Go to the Shadows section and disable the Link Light Layers checkbox.
You can now use the Light Layers drop-down in the Shadows section to set the Light Layers that the Light uses for shadowing. You can also still use the Light Layers drop-down in the General section to set the Light Layers that the Light uses for lighting.
Renaming Light Layers
By default, in the UI for Lights, Mesh Renderers or Terrain, Light Layers are named Light Layer 1-7. To more easily differentiate between them, you can give each Light Layer a specific name. To do this, open the HDRP Global Settings, and go to Light Layer Names. Here you can set the name of each Light Layer individually.
Example scenario for Light Layers
Using cookies for light fixtures can sometimes have a negative visual effect on a bulb, such as self-shadowing or transmission contribution. You can use Light Layers to make a bulb Mesh not receive any light from the Light’s cookie, and instead receive light from a separate small Point Light.
The Light cookie incorrectly affects the transmission of this bulb’s geometry.
Assigning the bulb’s Mesh Renderer to a specific Light Layer means that the Light cookie no longer affects the bulb’s Mesh Renderer.
To restore the transmission effect, create a Point Light and assign it to the same Light Layer as the bulb’s Mesh Renderer . Now this Point Light only affects the bulb’s Mesh Renderer and does not contribute to the rest of the Scene Lighting.
For more information on this process, see Pierre Donzallaz’s expert guide on creating high quality light fixtures in Unity.