Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I prevent that an object is affected by self shadow of another object in Unity (2D Light)?

Discussion in '2D' started by Umpfi, Jan 18, 2022.

  1. Umpfi

    Umpfi

    Joined:
    Dec 13, 2013
    Posts:
    1
    Hi,

    I'm trying to recreate my old 2D top down game (developed with Monogame) in Unity.


    I use the 2D Light (URP) with the "self shadow" feature, since an object that is illuminated in 2D from above will naturally appear darker than if it is illuminated from below (front).

    But exactly with this function, I have a problem. An NPC which overlaps with an object with "self shadow" is also darkened (see screenshot in the head area)


    You can see the shadow from the pillar on the head.


    I had exactly the same problem in my old engine. I solved it by excluding the NPCs from the shadow cast and taking the shadow value of one pixel between the feet as the basis for the brightness of the entire NPC. I found an old picture of this problem:

    On the left, the same problem I have in Unity. On the right is the desired result.

    Is there an "easy" way to fix this by using layers or something? Or will I have to go the same way as back then and use the shader to solve this? Would be happy for every hint.

    Cheers,
    Umpfi