Search Unity

Feature Request Multipath ShadowCaster2Ds (like PolygonCollider2D)

Discussion in '2D Experimental Preview' started by ThundThund, Jun 4, 2021.

  1. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    The 2D lighting / shadow casting system is quite slow, it eats up most of the CPU time per frame in my game. A way to optimize it would be to generate 1 mesh formed by several shapes instead of having to add a ShadowCaster2D to every shape, which generates unnecessary separate drawcalls in the 2D Renderer. The inspector should allow to define such separate shapes of the same mesh.
    This could be done even automatically by the CompositeShadowCaster2D, without needing multiple paths.
     
    GliderGuy likes this.
  2. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    Nevermind, I've just implemented it by myself :)
    I've reduced the frame rendering time, in my game, according to the stats window:
    CPU -9ms
    Render thread: -6ms.
    In general, it's a performance increase of ~40%.

    Limitation: Shadow casters in the group must be static with respect to their brothers.
     
    GliderGuy likes this.
  3. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    My demonstration:


    I think this should be included as a built-in feature, every project that uses ShadowCaster2Ds will need it for sure.
     
unityunity