Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Mixed cached shadows for directional light broken when shadow cascade count is greater than 1

Discussion in 'High Definition Render Pipeline' started by mgeorgedeveloper, May 30, 2023.

  1. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    317
    Hi,

    I have a simple setup here with three cubes set as static shadow casters.
    I'm using 4 shadow cascades in the Shadows volume override.
    There is single realtime directional light.

    1.
    With cascades enabled and the shadow update mode of the light set to Every Frame, everything works as expected.

    2.
    But if I change the shadow update mode to OnEnable, the cached shadow map initially appears correctly, but if I walk around its clear that the cached shadow map is totally broken, and even the realtime shadow from the character goes missing in places.

    3.
    However - if I set shadow cascade count to 1, then the mixed cached shadows work perfectly.

    Is there a known bug currently (I'm on Unity 2022.2.12) that prevents mixed cached shadows to work alongside shadow cascades?

    1. All real-time shadows, cascades on.
    hdrp-mixed-cached-off.png

    2. Mixed cached shadows, cascades on. hdrp-mixed-cached-broken.png

    3. Mixed cached shadows, cascades off.
    hdrp-mixed-cached-ok.png


    Settings:
    hdrp-mixed-cached-shadow-settings.png

    hdrp-mixed-cached-sun-settings.png


    Thanks for any help or ideas!
     
  2. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    851
    Don't you need to set update mode to "on Demand" to correctly use mixed cached shadows?
    Edit: OnEnable should also work. Only important to set "always draw dynamic" for the real time ones
     
  3. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    317
    That's right - for a simple test without the scripting side in place, I use OnEnable and I just disable/enable the light to manually update the cached shadow. The whole thing works perfectly so long as I don't enable cascades. Once you enable cascades, the whole thing breaks.
     
  4. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    851
    Should be a straightforward bug report, if it's easy reproducible!
     
  5. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    317
    Yes, I will drop a bug report after letting this thread simmer for a week. Just want to be sure I'm not doing something wrong in relation to cascades + cached.

    BTW - forgot to mention in case this is useful: I'm using Unity 2022.2.12
     
    Qleenie likes this.
  6. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    143
    Did you manage to get a reply or any idea what's going on?
     
    mgeorgedeveloper likes this.
  7. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    317
    It eventually dawned on me that cascaded shadows are view-dependent, because each cascade distance is determined from the camera's point of view. What is rendered into each cascade, depends on the light direction and the camera position and direction. So in my mind, caching would be impossible and nonsensical unless the camera is static.

    I can't exactly explain why it seems to work with cascade count = 1, because the contents of the shadow map would still be view-dependent... so I guess it will break as well, if you travel far enough after the caching is complete.

    I'm surprised the editor UI allows mixed caching for the directional light at all. Maybe someone from Unity can cast more light on this, no pun intended.
     
  8. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    143
    But directional light shadow is view dependent the same way even without cascades, no? You can travel kilometers under one directional light. And even if you turn your camera, you get different shadow map in frame debugger.

    Anyway, I fail to understand how to properly utilize cached directional shadows, with or without mixed, with or without cascades. This feature was added in 2022 but documentation doesn't help understanding it.
     
    mgeorgedeveloper likes this.
  9. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    317
    Yes I'm a little baffled - at first I thought it was just a general bug, then I realised that the view position/direction dependence means that it doesn't even make sense at all for caching to work, and finally I was left confused about why it seems to work without cascades. So who knows o_O:confused:
     
  10. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    851
    Did you do a bug report about this? I guess it's supposed to work, as it was announced as a feature in 2022.
     
  11. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    317
    Didn't get around to reporting a bug yet.
     
  12. frg_kova

    frg_kova

    Joined:
    Jul 16, 2015
    Posts:
    16
    the docs say it, maybe they corrected it
     
  13. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    143
    This is in 2021.3 HDRP 12. In HDRP 14 the doc says
    So it's a feature, but apparently one of those unusable Unity's features.
     
  14. frg_kova

    frg_kova

    Joined:
    Jul 16, 2015
    Posts:
    16
    You're right it's from HDRP 13+, this is from What's new section in HDRP
     
  15. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    851
    I did a bug report about this broken feature. It's a bit strange that it is so easy to reproduce. Either we don't understand this feature correctly, or no one tested it before release, as it plainly does not seem to work.
    Artifacts also appear with only one cascade, they are just not that big than with more cascades.
     
    Genebris likes this.