Search Unity

Question Flashlight that can hide part of sprites | 2D Light + ShaderGrapf

Discussion in 'Shader Graph' started by pigwejq, Nov 13, 2020.

  1. pigwejq

    pigwejq

    Joined:
    Dec 15, 2018
    Posts:
    5
    I need to make a flashlight that can hide elements of environment in my 2D game, but i can't find any tutorial. I don't know how to describe it so I prepared a sketch of an effect (attached file). Bush under light is transparent (ex. layer ToHide) and wall is normally illuminated (ex. layer Default).
    Ref video:

    Ref video 2:


    Is it even possible if I am using 2D lights and 2D renderer?
     

    Attached Files:

  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    There's not an easy way to get light info at the moment. Apparently it's possible but fwiw last time I tried (months ago) I wasn't able to get it to work. See here:

    https://forum.unity.com/threads/exp...p-previously-lwrp.683623/page-10#post-6206682
    Someone else tried: https://forum.unity.com/threads/getting-and-using-2d-light-data-in-shadergraph.989091/

    I suspect that the strategy you'd use is to have one of the light layers be for revealing your objects.

    Another, different strategy would be like in the Lost Crypt demo with the magic wand. It updates the material for the "spirits" so they fade in/out a channel based on proximity to the magic wand. That's perfectly possible with 2D lights right now but lacks the precision of having access to light data. ca - Copy.gif
    So the lightbulb shape in your picture might be an issue. But you could fade in/out a texture in response to proximity by updating the material, if that kind of simplified solution would work for you.

    See demo here. The shader/material you want to examine is the Material_Spirit_Lit and ShaderGrapht_Spirit_Lit.
     
    Last edited: Nov 14, 2020
    pigwejq likes this.