How to skip 2D Renderer Normal map pass when using SpriteMask

I was experiencing some slow frame render times when using the 2D renderer with lights, and noticed that in some scenes I was seeing almost double the amount of draw calls because of the the normal map pass for 2D lights.

I would like to prevent this normal map pass from rendering, as I am only using global 2D lights, and no normal maps/secondary textures are assigned to sprites.

I noticed that if a SpriteMask is used in the scene, then the normal map pass will always render even if there are no normal maps present, or lights with normal map rendering enabled. This is happening on line 224 of .../Runtime/2D/Passes/Render2DLightingPass.cs which reads:

if (layerBatch.lightStats.totalNormalMapUsage > 0 ||
                        (hasSpriteMask && i == 0) ||
                        (hasSpriteMask && i + 1 == batchCount))

notice the use of hasSpriteMask which is a cached value from line 197:

// Account for Sprite Mask and normal map usage where the first and last layer has to render the stencil pass
bool hasSpriteMask = UnityEngine.SpriteMaskUtility.HasSpriteMaskInScene();

If I manually modify Render2DLightingPass and force the normal pass to not render, my project visually looks exactly the same.

Is there a way to use SpriteMasks, but still avoid rendering this normal map pass? Is there a specific reason why SpriteMasks force the normal pass to render?

Any insight is much appreciated. Thank you!

Just wondering if there are any 2D renderer experts that may have some more details on how this works currently, or if there are options for controlling, or working around this limitation.

I found that this was fixed (by being removed) in this commit: [6000][UUM-72414][UUM-72180] Fix blend issues in rendergraph pipeline · Unity-Technologies/Graphics@e608f8f · GitHub

It looks like this is being applied to Unity 6, will this bug fix be back-ported to 2022.3?

Here’s the issue tracker which shows it is: Unity Issue Tracker - Sprite Masks affect Sprite Renderers outside their range when a Light2D is present with specific Target Sorting Layers selected

Looks like it landed in 2022.3.35f1 (latest LTS is 2022.3.38f1)

This is for UUM-72180 so I’ll check UUM-72414 with the 2D graphics devs to see how it’s related for you but it does look like the same change that was backported.

Excellent ok, thank you for the information.
If the same set of changes applied for UUM-72414 then I believe that would fix my issue.
Manually modifying these files in the same way does indeed skip rendering the 2d normal pass.

Additionally, I was using unity 2022.3.34f1 just one version before the fix/change was implemented.
Thanks again for looking into this.

1 Like