Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Feature Request Multipath ShadowCaster2Ds (like PolygonCollider2D)

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

  1. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    346
    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.
     
    NotaNaN likes this.
  2. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    346
    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.
     
    NotaNaN likes this.
  3. AlexVillalba

    AlexVillalba

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


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