Mask an illuminated sprite

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Andrea

Hello,
how can I completely mask a sprite who is illuminated by another lightsource?

Right now I am using a Light2D in mask mode, and a Light2D in add mode, the mask works in the non-illuminated area, but I can still see through in the illuminated areas.
Is there a way to change it?

:bust_in_silhouette: Reply From: 2D

If you utilize the light mask property of the sprite and the item cull mask property of the light2d you can determine which light the sprite is affected by.

In the images below, the sprite is on light mask 2. The white light (mask) has item cull mask set to 1,2 in both images. The red light (add) has item cull mask set to 2 in the top image and 1 in the bottom image.


I think your pictures highlighted the problem: i need to have the sprite BOTH illuminated (like in picture 1) and masked (like in picture2).
But if the light-add-mode is affecting the sprite, the mask wont cover it anymore (exactly what´s happening in picture 1).
I´m struggling with this problem since a while, help!!

Andrea | 2018-03-17 13:47

Is this related to your sound in shadow post?

link

If so, can you send me a stripped down project with your player, light, and occluder.

2D||!2D | 2018-03-17 15:04

Yes it is! Honestly I´ve tried so many combinations of cull/mask/visibility layers that i did not managed to find what combination generates the behaviour i described in this post.
I send to you the project as it is right now, from my understanding it should work, but obviously it doesnt!

https://drive.google.com/open?id=19pXNBjU_D3WX2zYxSddE6r1uQsIZnWjw

Basically every light (add) is on the layer 2, while the field of view (mask) is on layer 1.
Every sprite light-mask is both on layer 1 and 2.
It works fine if you run the two effects separately, it behaves oddly when you put them together (to do that, open the character scene and toggle visibility of the “Perception” node)

Andrea | 2018-03-17 17:06

I believe that you want to make the foot prints “glow” when not in the players FOV light? The foot prints will be created by the zombies only?

2D||!2D | 2018-03-17 23:23

That´s exactly my plan, but it is secondary to find a way to make the illumination/field of view system works properly (many object will create sound-prints, but mostly the zombies)

Andrea | 2018-03-19 07:26

Oddly enough I discovered while working on this that I am having a similar issue in my project as yours. I believe what you want is not achievable OOTB, but will have yo be handled in the fragment and light shader. I will follow up with you when I figure out a solution.

2D||!2D | 2018-03-19 23:02

Thank you very much for you efforts :slight_smile: I´ll wait for updates then!

Andrea | 2018-03-22 06:42