Search Unity

Question _MainLightShadowmapTexture uninitalized in additive scene until a shadow is cast

Discussion in 'Shaders' started by chrismarch, Feb 19, 2021.

  1. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    I've got a custom shader that basically URP BakedLit with realtime shadows, and I've noticed that
    MainLightRealtimeShadow (Library/PackageCache/com.unity.render-pipelines.universal@7.5.1/ShaderLibrary/Shadows.hlsl), which samples the shadow map in the title, returns values from previous renders, or maybe just garbage, in an additive scene with no shadow casters. When the first shadow caster is rendered, then the MainLightRealtimeShadow values are fine. So, I can just add a Shadows Only quad to make this seeming optimization headache go away, but it feels like a hack...
    I see the bug in Unity Editor 2019.4.16f1 and builds.