Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

HDRP: How to trigger shadow map calculation via script?

Discussion in 'Graphics Experimental Previews' started by Cell-i-Zenit, Mar 7, 2020.

  1. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    290
    Hi,

    currently i have real time shadow map calculation activated, but i only need the "updating" in a really specific time frame so i would like to trigger it myself (choosing "On Demand" in settings).

    But i cannot find how i can trigger it.

    Can you help me?
     
  2. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    715
  3. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    290
    Thanks this helped @alexandre-fiset

    But there is something off. If i enable the realtime shadows everything looks as expected and the shadows look like they should.

    But if i stop doing this and choosing the ondemand version, the shadows only look good when i trigger the shadow generation "manually" each frame. The moment i stop triggering it, it starts to look bad and "random blobs of shadow" appear on the ground. I also noticed that all other shadows are disappearing.

    Is this triggering only happening for this single frame? If yes, is there a way to "remember" the latest shadow map somehow?


    Here a picture how it looks like WITHOUT triggering the shadow map generation each frame
    https://imgur.com/a/titI1i5
     
  4. fairchild670

    fairchild670

    Joined:
    Dec 3, 2012
    Posts:
    69
    Not sure if you've figured this out already, but apparently OnDemand shadow maps are generated according to the camera frustum at the time of the request. At least this is the behavior I've noticed while changing the camera view and calling the HDAdditionalLightData.RequestShadowMapRendering() function.

    There is a thread out there where this is sort of documented, but I can't seem to find it just yet.
     
    PutridEx likes this.
  5. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    In Unity 2020.3.34 this problem persists...

    Any idea?
     
  6. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    715
    Well to me it works fine.

    I use HDAdditionalLightData.RequestShadowMapRendering() a few frames after loading a scene, then for some lights I update them each frame when moving an object or by passing under.

    You need a Cache Atlas big enough to fit the cached shadows. In 2020.3.34, shadow caching is for punctual and area lights. The directionnal itself works with OnDemand but per its non-cached shadows nature you might need to update it more frequently.
     
  7. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    I tried to set Cached Shadow Atlas Resolution to 16384, but the problem persists...

    wrong shadows.PNG correct shadows.PNG
     
  8. jsr2k1

    jsr2k1

    Joined:
    Aug 11, 2010
    Posts:
    118
    Problem solved!

    It is not possible to update shadows and reflection probes during the same frame properly.
    So I have to update shadows, wait for one frame, and then update reflection probes.
     
    XaneFeather likes this.