Search Issue Tracker

By Design

Votes

0

Found in

2022.3.59f1

6000.0.41f1

6000.1.0b10

6000.2.0a6

Issue ID

UUM-99845

Regression

No

Incorrect Shader keyword activation for Shadows when no Light is present in URP

-

Reproduction steps:
1. Open the attached “IN-97004.zip” project
2. Open the “SampleScene”
3. Select the “Directional Light” GameObject from the Hierarchy
4. Enable the Light Component in the Inspector
5. Observe that the shaders are correctly displayed in the Scene
6. Disable the Light Component
7. Observe the Scene

Expected result: All the shaders are correctly displayed (all shadow-related keywords are disabled or both enabled)
Actual result: Pink shader is visible in the Scene view due to Unity enabling _MAIN_LIGHT_SHADOWS but disabling _SHADOWS_SOFT and causing shader errors

Reproducible with: 2022.3.59f1, 6000.0.41f1, 6000.1.0b10, 6000.2.0a6

Reproducible on: Windows 11
Not reproducible on: no other environment tested

Notes:
- Selecting the “RPAsset.asset” under Assets/Settings/RPAssets and disabling “Cast Shadow” also resolves the pink shader
- This causes issues when using custom shaders that depend on both shadow-related keywords being either both enabled or both disabled

  1. Resolution Note:

    Hi, I've taken a look at the project. This behaviour is as designed.

    To provide some context for this behaviour:
    In order to speed up build times, we try to remove the OFF variant for main light shadows. Since your URP asset has main light shadows enabled, we remove the OFF variant and select only _MAIN_LIGHT_SHADOWS and _MAIN_LIGHT_SHADOWS_CASCADE as they can be changed at runtime.

    This is not the case for the _SHADOWS_SOFT keyword, where it will disable at runtime if there are no lights visible by the camera that cast soft shadows.

    This means you would have to write your shaders without the assumption that _SHADOWS_SOFT would be enabled.

    You can rewrite these lines from the 'ShaderVariants.shader' in your reproduction project:
    #pragma multi_compile_fragment _ _MAIN_LIGHT_SHADOWS
    #pragma multi_compile_fragment _ _SHADOWS_SOFT
    to this:
    #pragma multi_compile_fragment _MAIN_LIGHT_SHADOWS
    #pragma multi_compile_fragment _SHADOWS_SOFT
    Which would remove this assumption.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.