Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. 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
  3. Dismiss Notice

Question How do I block light from passing through certain objects, Experimental 2D Light package

Discussion in '2D Experimental Preview' started by Kribzii, May 13, 2020.

  1. Kribzii

    Kribzii

    Joined:
    Sep 2, 2019
    Posts:
    5
    Hi,

    Does anyone know how to BLOCK point light from passing through certain objects with this package?
    Picture illustration below:



    I want the point light to not pass certain objects (Shadow Intensity set to 1.0).
    Other objects should have a Shadow Intensity of 0.5 or something..

    Can someone point me in the right direction?
     
  2. DandecatLiang

    DandecatLiang

    Joined:
    Aug 22, 2017
    Posts:
    26
    I dont think you can do this directly with the current vision of 2D lighting system.
    Creating two lights and using two different target layers should do the trick, just a little inconvenient.
     
  3. Kribzii

    Kribzii

    Joined:
    Sep 2, 2019
    Posts:
    5
    Thanks for the reply.

    Ok! that's unfortunate, do you know if they have it on the roadmap? Feels like it should be a key feature..
     
  4. DandecatLiang

    DandecatLiang

    Joined:
    Aug 22, 2017
    Posts:
    26
    I use many 2D lights in my game and feel the current 2d lighting system missing many features it should have. I think the team is working on the improvement of light render efficiency and the future roadmap is unclear. And we will wait at least some time.
     
  5. Panzer_Ihnen

    Panzer_Ihnen

    Joined:
    Jan 20, 2017
    Posts:
    7
    I can't get 2D lights react differently with different sorting layers. For example, if I have a gameobject with a sprite and a shadow caster 2D, I configure the sprite in the sorting layer A and shadow caster to affect sorting layer B. If I have two lights where both affect B, but only one to A, both produce shadows over B with the shadow caster that is in A

    https://forum.unity.com/threads/2d-lighting-cast-shadows-only-from-some-lights.885445/

    Can you help me please?
     
  6. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    It's been over a year and you probably don't need your answer anymore, but for anyone who finds this thread, you can play with the "shadow intensity" value of your light and add a shadow caster to anything you want blocking light. It's a little finnicky, but I think it does the trick for most games.

    One issue with it is it illuminates the entire object, but still blocks the shadow, but I suppose this could be solved with either normal maps or just creating an invisible separate object with a shadow caster over the object you want casting shadows.(and removing the shadow caster on the object)

    Not sure if this was added recently or the previous person just didn't know about it.
     
    Last edited: Jul 19, 2021
  7. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,522
    Yeah, this was what I said like .. two years ago.. so sad..
     
    NotaNaN and Mashimaro7 like this.
  8. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Yeah, I never used it 2 years ago, but it feels like they just abandoned the whole shadow cast system. I noticed if I shape the shadow caster at a certain angle the light will pass right through sometimes... Like, I'm talking narrowing the one end of a square, not making crazy shapes! It's sooo bugged! XD
     
  9. niwhocug

    niwhocug

    Joined:
    Jan 29, 2024
    Posts:
    4
    another 2 years passed, providing reference for others who encounter the similar situation.
    I have a solution for my case that light should blocked by wall.the following picture shows result. it's the basic idea that using filed of view as mask after light render.
    key points :
    1. render feature, a simple custom feature to get rendered fov, reference
    2. fov, raycast to generate filed of view ,reference
    3. render texture , saving mask(fov), with a camera only culling fov layer
    4. material(shader graph), working with render feature to get rendered fov and apply(mask) fov

    at starting , try shadow caster 2d with tile map(in my case), it's very poor performance(only 10+fps even freeze on 25*25 map full with wall).
    upload_2024-2-14_23-27-56.png
     
  10. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,530
    Yeah for something like this you have to go custom. 2D Renderer by itself targets a limited band of use cases.