godotengine / godotengine/godot

Light behaves unexpectedly when using a screen-space material

Open
#101,600 0 comments 0 reactions 0 assignees View on GitHub
bug confirmed topic:rendering
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:
![Image](https://github.com/user-attachments/assets/680e7cd1-15a0-4c80-b697-5e4acb792cd4)

Shader present, regular lights:
![Image](https://github.com/user-attachments/assets/522dcb57-8502-4fb9-8f17-364bf63092db)

No shader, negative lights:
![Image](https://github.com/user-attachments/assets/19e8dd9c-5842-4467-b2ec-b2ac7f571690)

Shader present, negative lights:
![Image](https://github.com/user-attachments/assets/7f28b1bb-1ec2-41ee-9b39-b94a23a5699b)

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.