godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.26k stars 21.04k forks source link

SCREEN_TEXTURE missing when shader read DEPTH_TEXTURE #79134

Open yikescloud opened 1 year ago

yikescloud commented 1 year ago

Godot version

3.5 stable

System information

windows 10

Issue description

When gles2 shader has a DEPTH_TEXTURE code(what ever it runs or not), the SCREEN_TEXTURE not work. Like code below:

shader_type spatial;

uniform bool read_depth = false;

void fragment() {
    vec4 c = texture(SCREEN_TEXTURE, SCREEN_UV);
    ALBEDO = c.rgb;
    if (read_depth) {
        vec4 depth = texture(DEPTH_TEXTURE, SCREEN_UV);//you must comment this line even it not run at all.
    }
}

Steps to reproduce

Write a DEPTH_TEXTURE in shader and read SCREEN_TEXTURE in gles2.

Minimal reproduction project

GLES2DepthTexture.zip

clayjohn commented 1 year ago

Some hardware does not supporting reading from DEPTH_TEXTURE as mentioned in the docs. Some hardware supports reading from DEPTH_TEXTURE, but does not support both reading from SCREEN_TEXTURE and DEPTH_TEXTURE. In that case, an error should have been printed to the console.

Can you please let me know whether any error is printed to the console when running your MRP on your device?

On my device I can't detect any issues at all

yikescloud commented 1 year ago

Some hardware does not supporting reading from DEPTH_TEXTURE as mentioned in the docs. Some hardware supports reading from DEPTH_TEXTURE, but does not support both reading from SCREEN_TEXTURE and DEPTH_TEXTURE. In that case, an error should have been printed to the console.

Can you please let me know whether any error is printed to the console when running your MRP on your device?

On my device I can't detect any issues at all

Godot not give me any error message, from right now the only way to solve this is send viewport texture to shader as a SCREEN_TEXTURE manually. If this issue is related to the hardware, I think we can add more info to the doc to point this. image

wacyym commented 3 months ago

I encountered the same problem. There are no errors in the console, but if in the shader there is a call to both DEPTH_TEXTURE and SCREEN_TEXTURE, then SCREEN_TEXTURE equal to vec3(1.0, 1.0, 1.0)

I wonder if this is actually a GPU driver/hardware issue?

Tested on systems: 1) AMD Ryzen 3 5300U with Radeon Graphics (Vega 6) Win 10 2) RTX3080ti Laptop, Win 11 3) Mediatek Helio P65 MT6768 (Android) White SCREEN_TEXTURE on ALL devices in GLES2, but in GLES3 everything is ok.

wacyym commented 3 months ago

This problem doesn’t allow to implement decals with lighting (decal which use depth buffer + screen_texture): almost free “deferred” rendering of a very large number of light sources, and this would have been possible even on GLES2! if not for this bug, or if it had been possible was to take the depth buffer as viewport_texture (as uniform in shader)...