godotengine / godotengine/godot
Light behaves unexpectedly when using a screen-space material
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible on v4.3.stable.mono.official [77dcf97d8]
### System information
Godot v4.3.stable.mono - EndeavourOS #1 SMP PREEMPT_DYNAMIC Fri, 27 Dec 2024 14:24:37 +0000 - Wayland - Vulkan (Forward+) - dedicated AMD Radeon RX 7800 XT (RADV NAVI32) - AMD Ryzen 5 3600 6-Core Processor (12 Threads)
### Issue description
When assigning the albedo as the screen color for a mesh through the "Next Pass" or "Material Overlay" properties, it causes light to behave weirdly with the Forward+ renderer. In the case of regular lights, it seems to intensify the attenuation of the light while darkening non-lit parts (it's a bit hard to tell exactly what happens). For negative lights, it causes sufficiently bright spots to "wrap around" into being fully lit (white) rather than dark.
Worth noting is that with the Compatibility renderer, the issue is not present for negative lights (regular lights still exhibit very similar "intensifying").
No shader, regular lights:

Shader present, regular lights:

No shader, negative lights:

Shader present, negative lights:

While the shader code is in the MRP, I'll paste it here since it's so tiny:
```glsl
shader_type spatial;
uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, filter_linear;
void fragment() {
vec3 screen_color = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
ALBEDO = screen_color;
}
```
### Steps to reproduce
1. Add a shader that assigns the screen color to albedo as the Material Overlay or Next pass of any mesh
2. Add some lights
3. Observe unexpected light behavior
### Minimal reproduction project (MRP)
[light-screen-texture-demo.zip](https://github.com/user-attachments/files/18428830/light-screen-texture-demo.zip)
Contributor guide
Research direction
Start with the linked minimal reproduction project and reproduce the screen-texture shader with regular and negative lights in the Forward+ and Compatibility renderers. Trace the rendering path for Material Overlay or Next Pass screen-space materials; done means assigning screen color to ALBEDO no longer changes light attenuation, darkening, or negative-light behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- godot
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100