# Optimize 2D lights in URP

> Reduce the number of light textures, shadow textures, and shader variants Unity uses to render your 2D lights.

Reduce the number of light textures, shadow textures, and shader variants Unity uses to render your 2D lights.

## Use the Light Batching Debugger

The **Light Batching Debugger** window shows which lights and shadows prevent Unity from batching your sorting layers together, so you can change your lights and settings to reduce the number of light and shadow textures Unity renders.

If two or more [sorting layers](/engine/6000.7/manual/unity2d/sprite/sort-sprites/sorting-group-reference.md) of GameObjects need exactly the same lights, Unity can render them using a single light texture and shadow texture instead of multiple textures. This process is called light batching and improves performance. For more information about light and shadow textures, refer to [Introduction to 2D lighting](/engine/6000.7/manual/unity2d/2d-urp/2d-index/lights-2d-intro.md).

### Batch lights and shadows

To merge two batches by making sure they use exactly the same lights, use the **Light Batching Debugger** window.

Follow these steps:

1. From the main menu, select **Window** > **2D** > **Light Batching Debugger**.
2. In the left-hand panel, select two batches to check how the 2D lights and shadows differ between the two batches.
3. Select each light in the **Lights** list, then set its **Target Sorting Layers** property to match the **Layer Names**.
4. Select each GameObject in the **Shadow Casters** list, then, in its **Shadow Caster 2D** component, set its **Target Sorting Layers** property to match the **Layer Names**.

For example, in the screenshot in the [Light Batching Debugger window reference](#lighting-batching-debugger-window-reference) section, **Light A** exists in **Batch 0** but not in **Batch 1**. To merge the batches, set the **Target Sorting Layers** of **Light A** to both the **BG** and **Default** layers.

### Minimize render textures

To reduce how much Unity writes to light and shadow textures, use one or more of the following approaches:

* To reduce the size of light textures, use the **Render Scale** property of the [2D Renderer asset](/engine/6000.7/manual/unity2d/2d-urp/2drenderer-data-overview.md).
* If you have a lot of sorting layers that each have their own set of lights, increase the **Max Light Render Textures** in the [2D Renderer asset](/engine/6000.7/manual/unity2d/2d-urp/2drenderer-data-overview.md) so Unity can pre-render all the light textures in one go. This can increase the amount of memory Unity uses.
* To reduce the number of light textures, use fewer different **Blend Style** values in the [2D lights](/engine/6000.7/manual/unity2d/2d-urp/2d-index/2dlight-properties.md) in your scene. Each different blend style you use creates a new light render texture. The best practice is to use only one or two different blend styles in a scene.

### Light Batching Debugger window reference


**The Light Batching Debugger window with the batch panel on the left (A), and the main area on the right (B).:**
![](/api/media?file=/engine/6000.7/media/images/light-batching-debugger-3.PNG)

* A: The list of 2D light batches. Each batch represents one light texture. The **Layers** column lists which sorting layers Unity draws using the light texture.
* B: The main area. When you select two batches, this area lists which lights or shadows prevent Unity merging the batches. In the example, **Light A** needs its own light texture because it targets only the **BG** sorting layer rather than both the **BG** and **Default** sorting layers.

## Strip unused 2D shader variants

If your project uses 2D lights, you can strip the 2D light shader variants your scenes don't use. Follow these steps:

1. From the main menu, go to **Edit** > Editor.
2. Select the **Graphics** tab.
3. Go to **Pipeline Specific Settings** > **URP**.
4. In the **Additional Shader Stripping Settings** section, enable **Strip 2D Unused Variants**.

Unity analyzes the scenes included in your build and keeps only the 2D light shader variants those scenes use. This setting is disabled by default.

## Additional resources

* [Custom rendering and post-processing for 2D in URP](/engine/6000.7/manual/unity2d/2d-urp/scriptable-renderer-features-2d.md)
* [2D Renderer asset component reference for URP](/engine/6000.7/manual/unity2d/2d-urp/2drenderer-data-overview.md)
