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

Question Can I make 2D light affect a specific sorting order range?

Discussion in '2D' started by Tom-Kazansky, Feb 4, 2021.

  1. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    58
    Hi,
    I want to apply 2D light effects to my 2D game so it could have day/night time.
    my game is a zombie shooting genre with main character on the left side of the screen, who will fight hordes of zombies coming from the right side of the screen.
    I divide the scene into "lanes" and the zombies will spawn on these lanes.

    when I tried to apply 2D light to the game, I ran into a problem, a light from a lane will affect sprite which it wasn't supposed to affect.
    please check this image:
    upload_2021-2-4_11-21-29.png
    - the light affects the zombie A => this is expected
    - the light also affects zombie B => this is the problem, the light should not affect zombie B.
    zombie A and B have different sorting order value.
    The light can affect specific sorting layers but I don't see any option to make it affect specific sorting range (example: affect range: from -100 to 100, then sprite in sorting order 150 will not be affected)

    after searching around, I stumbled upon this post which has this result:

    I think this is what I want.
    the solution involves modifying a shader and I don't know anything about shader :(
    can anyone point me a direction to solve this?
    if modifying the shader is too hard, can I modify the 2D light script to add a range of "target sorting layers" ?

    Thank you for reading,
    Tom.
     
    aarushban likes this.
  2. aarushban

    aarushban

    Joined:
    Dec 26, 2017
    Posts:
    2
    I'm super late, but did you ever figure this out?
    I am having the same issue so just wondering! :)
     
  3. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    its not possible as said in the post without going super crazy

    as far as i know the shaders they used in graveyard keeper were never posted