Search Unity

Shadowcaster Optimizer

Discussion in 'Assets and Asset Store' started by chassets, Jul 3, 2019.

  1. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    243
    Hi!

    I've been working on a litte tool to reduce shadowcaster count in a scene when using a realtime light or realtime shadows near the player in a baked scene - you can precompute this with the click of a button, or alter the settings to your liking.

    I've done some real-world test with some of my scenes now, and most of the time the number of shadowcasters can be reduced significantly, depending on the scene layout of course. Here's a comparison screenshot:

    before.png

    Before it has 773 shadowcasters, afterwards 381 - so it saved roughly 50% in this scene:

    after.png

    You can alter the accuracy values for each light type, so that you can further remove shadowcaster count by ignoring small meshes' shadows that don't contribute much to the overall visuals.
    This works for directional, point and spot lights.

    If this is of any interest to anyone, I'm going to release it in the asset store.
    If you have any input or questions, I'd be glad to hear it.

    Thanks and have a nice day,
    CH
     
    Neviah likes this.
  2. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,912
    How does it work? :)
     
  3. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    243
    It simply precomputes which renderers will be lit by the lights in your scene, without being in the shadow of other renderers (completely).

    If you move your lights though, you'd need to recalculate again - but the precomputation works pretty fast as far as I can tell from my scenes ( I've used my own 3d art packs for testing purposes: https://assetstore.unity.com/packages/3d/environments/landscapes/lowpoly-style-ultra-pack-108275). But you wouldn't do that every frame of course :D

    But most of the time in my projects I have a static directional sun and use either realtime shadows or baked shadows with realtime shadows near my player, so I guess this will help a fair bit.
     
    Last edited: Jul 3, 2019
    Peter77 likes this.
  4. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    243
    debugmode.PNG

    I've added a debug visualisation for each light type - in this example, the flower circled in red casts a shadow, but the flowers in the blue are in the shadow of the stone and thus their shadow is set to none.
     
    Peter77 likes this.
  5. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    243
    Made another test with my biggest 3d asset (huge scene, lots and lots of 3d objects) - also turned shadow distance far up.
    before2.PNG

    This time 2999 versus 1514 shadowcasters, so again 50% less.
    after2.PNG
    If I drag the accuracy slider a bit down, I can get easily down to ~1k shadowcasters without being very noticable.

    after2_2.PNG
    I'll improve the UI a bit, but I think afterwards I'll be ready to release this.
     
  6. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    243
    • I've added an important feature: you can choose to only precalculate static objects.

    For example: If you have a spaceship that is controlled by your player in an asteroid field, this ship will not affect shadowcaster optimization calculations - the asteroids in the ships' shadow will still cast shadows - the ship is invisible to the lighting precalculation.

    • Also you can now choose to only calculate the optimization for specific objects that you have selected.
    • You can either use all shadowcasting lights in the scene or only those lights you choose.