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. Dismiss Notice

Big rendering performance loss from 2020.3.4 to 2021.1 (Lights / ShadowCasters)

Discussion in '2D Experimental Preview' started by AlexVillalba, Apr 22, 2021.

  1. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    334
    Hi everybody. I'm developing a game that uses a lot of 2D lights and shadow casters and I've just upgraded the project from version 2020.3.4 to 2021.1.0 (tried 2021.1.3 too, even 2021.2a) and quickly realized about the FPS drop, from +60 to 45 in non-development builds. I could not reproduce the exact scenario in a test project but I created a simple scene with:
    • 5 sprites
    • 2 sorting layers
    • 53 shadow casters
    • 9 lights
    Unity 2020.3.4
    • 140 FPS
    • 3k drawcalls (3k batches)
    • RenderPipelineManager.DoRenderLoop_Internal takes 4.67 ms
    • ShadowCaster2D.Update called 65 times takes 0.34 ms
    Unity 2021.1.0
    • 100 FPS
    • 5k drawcalls (5k batches)
    • RenderPipelineManager.DoRenderLoop_Internal takes 7.55 ms
    • ShadowCaster2D.Update called 65 times takes 2.12 ms
    I'm quite confused, we've been told that you (Unity dev team) have been prioritizing performance tasks for the last months but I'm getting these results. Am I missing something? Is there anything in the v2021 I should tweak to get the same performance as with 2020.3.4?

    I've attached the test projects.
     

    Attached Files:

    NotaNaN likes this.
  2. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    254
    I'll look into this. I just submitted some improvements to shadows only a couple days ago, and haven't really touched them much otherwise so I'm not sure why the performance degraded. I'll look into what is going on.

    If you do have performance regression in the future, definitely file a bug.
     
  3. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    334
    Sure, I already filed this bug, sorry for not mentioning it in the original post: 1331230
     
    LeonhardP likes this.
  4. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    334
  5. Chris_Chu

    Chris_Chu

    Unity Technologies

    Joined:
    Apr 19, 2018
    Posts:
    254
    I got a bug with a test project just recently. I am going to start looking into it today.
     
    AlexVillalba likes this.
  6. ttran07

    ttran07

    Joined:
    Mar 9, 2019
    Posts:
    9
    Also, is there a way to apply a single Shadow Caster on an object containing multiple sprites?

    I have an object that contains head, body, arms, legs, etc.
    And on each of those, I need to add Shadow Caster 2D on them.
    Is there a way I can have a composite of the sprite, and apply a Shadow Caster2D on the parent object only?
     
    Last edited: Jun 4, 2021
  7. ttran07

    ttran07

    Joined:
    Mar 9, 2019
    Posts:
    9
    I think the ShadowCaster2D is being calculated even when it is out of camera view.

    I put a lot miles away and it is lagging.

    I wrote a script to disable shadowcaster out of view and the perfomrance improved substantially (especially in scenes with lots of shadows.)
     
    Last edited: Jun 11, 2021
  8. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    334
    There's no way to do so in Unity at the moment. However, it's doable, I mean, I know the code of the URP and that's a feature that can be implemented, there's no technical impediment.
     
  9. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    334
    Still not solved, and I still don't dare to upgrade to 2021:(
     
  10. ttran07

    ttran07

    Joined:
    Mar 9, 2019
    Posts:
    9
  11. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    334
    I already solved the performance issues by optimizing how shadows are generated in Unity, and also applied some visual softening. But thanks for the reference, I will take it into account in case I find any new technical impediment.
    https://forum.unity.com/threads/fea...k-and-i-wish-they-were-in-the-engine.1125893/
     
  12. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    334
    Just in case somebody is waiting for this fix, they have supposedly fixed it for URP 12, the fix is under review yet.
     
    NotaNaN likes this.
  13. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    334
    The fix has been reviewed:

    "Fixed in URP 12.0.0 and 2022.1.0a6. Fixed a bug and an issue with shadow culling that were causing performance regressions"

    I'm not sure about whether I will get the fix if I download the last version of the URP 12, using a version of Unity under 2022.
     
    Garfounkel and NotaNaN like this.