Open Miziziziz opened 2 years ago
In short, for some reason, within the lit region, screen_sample.w == 2.0, and it's messing with your logic.
I am able to work around this by modifying the shader to ignore alpha in the error calculation:
if (length(abs(key_color.xyz - screen_sample.xyz)) < 0.1)
When I output the alpha value calculation like
COLOR = vec4(key_color.w, screen_sample.w, abs(key_color.w-screen_sample.w), 1.0);
I read 255, 255, 0 outside of the light, and 255, 255, 255 within the light. This is because screen_sample.w == 2.0 Outputting screen_sample.w-2.0 as a color gives 0.
I'm not familiar with godot source yet (This is the first project I have ever opened in the engine) but I hope this investigation helps!
Godot version
v3.4.4.stable.official [419e713a2]
System information
Windows 10, Nvidia Geforce 2060
Issue description
One sprite is in the background and is lit by a light2d node. I have an unlit sprite in front set to a chroma key color, then finally a shader that reads the screen in a rect and displays black if the screen color matches the chroma key color and white if it doesn't.
As you can see in the screenshot it displays white when the chroma key sprite is over the background sprite, meaning SCREEN_TEXTURE is returning the wrong color in the shader.
possibly related to #47575
Steps to reproduce
Open example project in editor. Look at ScreenReader node material to see shader code.
Minimal reproduction project
ScreenTextureLightingBug.zip