Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

URP -> Is it possible to Calculate Shadows on dynamic object only when the object is moving ?

Discussion in 'Universal Render Pipeline' started by YHX2000, May 13, 2021.

  1. YHX2000

    YHX2000

    Joined:
    Aug 2, 2015
    Posts:
    29
    Hi I'm trying to think of some optimization. I want to make it so shadows for dynamic objects are calculated only when I'm moving the object itself and not when the object is idle.
    For example -> check game you calc shadows only you move the figures ?

    Thanks in advance !
     
  2. PacoChan

    PacoChan

    Joined:
    May 28, 2015
    Posts:
    44
    What you are referring to is commonly called shadow cache, and URP doesn't implement it. Maybe HDRP? But not sure. It would be a nice feature to ask for.
     
  3. YHX2000

    YHX2000

    Joined:
    Aug 2, 2015
    Posts:
    29
    Hi @PacoChan Thanks for reply, anyone else knows how to be implemented ?
     
  4. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,135
    I don't think it'll be trivial to do, but would require URP's shadow casting to be modified. You'd have to duplicate the behaviour of MainLightShadowCaster, and render a shadow map for stationary and dynamic objects, then combine them together before passing it to shaderland.

    You'll need a system that keeps track of which objects are stationary and moving. As well as an event for when one switches states, since this requires to re-render the "static" shadow map. Assuming it's just for one directional light, it needs to be re-renderer when it moves as well. But this is all very similar to using baked lightmaps for static objects, and realtime shadows for dynamic objects.

    HDRP uses shadow caching, and has all the bells and whistles in place. So it's technically possible to reverse engineer everything, but it's a likely ton of work and peers into the realm of making a custom URP version.
     
    JoNax97 and YHX2000 like this.