Godot Version
4.6.1
Question
Hi everyone,
Having sprites that appear when under light is easy with CanvasItemMaterial “light only” mode.
But I was wondering if the inverse could be done: a sprite that disappears when receiving the light of say a PointLight2D.
My goal would be to have a top-down view where the “roof” of a building disappears when the player looks at it, revealing the interior of it.
I hope this makes sense, thank you very much for any help!
You should be able to achieve this with a light shader.
2 Likes
Hmm, that’s what I was suspecting. Shaders (and especially light shaders) still feel too intimidating for me at the moment, I’ll wait a bit.
Thank you for your help!
1 Like
If you want a simpler solution, you could just set the roofs alpha to 0 when the player gets close.
That’s what I did haha
Only edge case is when looking from a distance into the building the player looks at the roof, hence my idea to have the light remove the roof layer.
I had the same question very recently! If you aren’t using shadows, you can get this effect with the “light only” mode if you duplicate the light and inverse the alpha values. If the player’s vision is just surrounds the player in a gradient circle, you can reverse the gradient’s alpha values, set the color to white, and match the light a light layer of the roof.
This approach doesn’t work if you have shadows in the player vision and don’t want the effect inside of the shadow. The different light layers make this tricky. Might work in some cases though.
1 Like
This is what my texture for my light looked like when doing this approach. Note, the light would need to cover the entire screen (or whatever distance you can see roofs in your case.)
2 Likes
Oh wow that’s really smart! Thank you so much for this, I am going to try it now!
1 Like
Hey @salmon_jammin,
Just wanted to say that I found an alternative way: imagine you have a “roof” and a “floor” layer. To avoid messing with shaders, you can put the “floor” layer on top of the “roof” one, but have it only appear in light.
That way, you effectively have the impression of the roof disappearing when looking at it, revealing the floor.
A bit hacky but simple 
Only limitation is when the floor layer is smaller than the roof layer (for example for a tree: the “roof” is the leaves and extend over the trunk). In this case you have to hard paint the ground around the trunk in the “floor” layer to be sure that it hides the leaves.
I hope this is clear, and maybe can help others having the same need.
It seemed impossible to do this with shaders: the pipeline goes from fragment() to light(), and it seems you cannot sample the light to use it on pixels.
1 Like