light_mode shadow_only material in godot 4 for 2D light

414 Views Asked by At

I want to make a 2D object that becomes transparent when light hits it. This is completely opposite to the light_only light mode. To be honest light_only doesn't work in Godot 4.0, it's fixed in 4.1

In Godot 3 I would use shader with AT_LIGHT_PASS. But in Godot 4 AT_LIGHT_PASS always get false. Also I was trying to use light() in Godot shaders but it's only adds on COLOR, so I can't set alpha 0.0 on LIGHT to make texture transparent.

1

There are 1 best solutions below

0
On

I found solution

shader_type canvas_item;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture;
uniform vec4 on_light_color : source_color;

void light(){
    LIGHT = texture(SCREEN_TEXTURE, SCREEN_UV);
}