Light complete Sprite2D if it touches lightsource

Godot Version




I am creating an isometric 2D game. I have a PointLight2D that illuminates the scene. I want my character to be lit when the feet touch the light. For example:
If the character is below the light source and only the top half of the sprite is in the light, the whole sprite should stay dark.
If the character is above the light and the feet touch the light, the whole character should be lit with the light value that touches the feet (including the part of the sprite that is still in the dark).

How it looks now vs how it should look like:

I am trying to solve this with a shader. My idea is, that I check a few points on the bottom of the sprite if they are black and if at least one of them isn’t, each pixel is lit up.

Is it even possible to achieve this with shaders? If not I will just add area2Ds to the lights and check if the LightOccluder of the character is in the light area to change the light mask or something like that. I’d just have loved to find another solution.

I guess it doesn’t work because the texture function only get the values of the texture before it is lit and not actually the texture as it was displayed on the screen in the last frame. Also during writing this I realized that even if my code worked, my character would never be able to turn black again. So my attempt is flawed anyway.

void light() {
	vec4 point1 = texture(TEXTURE, vec2(0.2,0.3));
	vec4 point2 = texture(TEXTURE, vec2(0.2,0.7));
	vec4 point3 = texture(TEXTURE, vec2(0.4,0.3));
	vec4 point4 = texture(TEXTURE, vec2(0.4,0.7));
	vec3 black = vec3(0.0,0.0,0.0);
	if(point1.rgb != black || point2.rgb != black || point2.rgb != black || point2.rgb != black)
		LIGHT = vec4(1.0, 1.0, 1.0, 1.0);
	} else {

This is my first project in Godot and the first time programming in a few years so I am not familiar with shaders at all. I am thankful for any helpful hint.

what happen if the light shine a box on the right and left? will it be lit too? anything under the player is dark?
if that so, then just check position Y of player and the box to determine which box should be whole black

I don’t think that would work. The light is a circle, so Y coordinates aren’t enough.

Maybe another way to explain what I want: The whole character should be lit with the light value that the first row of pixels on the bottom side of their sprite gets. Because it is isometric, you have to imagine a person going closer to a campfire. Their whole body will be lit evenly. The light won’t go to their shoulder and then just keep the head in the dark because they aren’t close enough.

The same happens when someone enters from the side. The light won’t just light their left shoulder while the right shoulder will be in the dark when they are looking at the fire. Instead the whole front of the person will be in the affected by the light the same way.