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.

Feature Request RequestShadowMapRendering for static/dynamic objects separately?

Discussion in 'High Definition Render Pipeline' started by Matusson, Nov 13, 2021.

  1. Matusson

    Matusson

    Joined:
    Feb 7, 2020
    Posts:
    3
    I've been using mixed cached shadow maps with great performance gains, however, I do have a slight issue with it. I use a custom on-demand shadow rendering system that tracks objects in the light's area of influence and only updates when an object moves. The mixed cached shadow rendering has decreased gains from doing this, but due to the game being a mostly static experience, there are still objects that can't be marked as static but rarely move.

    I believe I could still get extra performance (and more consistent frametimes) from rendering the static shadows only once, and rendering dynamic ones when necessary, instead of every frame, but RequestShadowMapRendering updates shadows for all objects. Is there an API planned to allow rendering for only dynamic/static objects? Or is it too specific of a case?
     
    PutridEx, olavrv and Ruchir like this.
  2. olavrv

    olavrv

    Joined:
    May 26, 2015
    Posts:
    481
    This sounds like a very good idea!
     
  3. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,034
    One hacky workaround that might work is, since you already track all the objects, and know the ones that move, set any object that moved recently as "dynamic" and after a certain amount of time with no movement, remove the 'dynamic' tick from the object.

    This is assuming dynamic property can be set on and off in runtime and it works as expected.
    Although, i'm not sure how you can do that through code, I doubt there's an API for that.
     
  4. Matusson

    Matusson

    Joined:
    Feb 7, 2020
    Posts:
    3
    This does actually work, but as you mentioned it's hacky. I need to request shadow rendering on the frame the object starts moving and stops moving (as otherwise it will stay in the cached map, or won't get baked into the cached map), and the light still needs space in both the real-time atlas and cached atlas. I also experimented with disabling Always Draw Dynamic on the light but that obviously only stores the dynamic shadows for a single frame.

    I guess what I would precisely want is to cache dynamic light shadows into a separate atlas, or separate "place" in the atlas, so the two can be cached but updated independently.