godotengine / godot

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

GLES2 referencing `DEPTH_TEXTURE` in shader corrupts `SCREEN_TEXTURE` #47179

Open Axciton opened 3 years ago

Axciton commented 3 years ago

Godot version:

v3.2.3.stable.mono.official

OS/device including version:

Windows 10. OpenGL ES 2.0 Renderer: GeForce RTX 2070 Super/PCIe/SSE2

Issue description:

For 3D graphics and GLES2 if you reference DEPTH_TEXTURE in shader in anyway SCREEN_TEXTURE becomes completely white. The simplest example is: shader with code

shader_type spatial;

void fragment() {
    ALBEDO=texture(SCREEN_TEXTURE,SCREEN_UV).rgb;
}

allows objects to be visible behind the mesh. But when any reference in code to the DEPTH_TEXTURE is made for example

shader_type spatial;

void fragment() {
    texture(DEPTH_TEXTURE,UV);
    ALBEDO=texture(SCREEN_TEXTURE,SCREEN_UV).rgb;
}

mesh becomes white. According to Godot documentation, DEPTH_TEXTURE and SCREEN_TEXTURE should be independent. The issue occurs only with GLES2, while GLES3 renders correctly.

Minimal reproduction project:

gles2bug.zip

clayjohn commented 3 years ago

Are you sure nothing gets printed out? A warning should print saying that using both SCREEN_TEXTURE and DEPTH_TEXTURE in the same shader is unsupported. https://github.com/godotengine/godot/blob/f50c8062dd9389a76986307402bc8c4538d51f1e/drivers/gles2/rasterizer_storage_gles2.cpp#L1564

Axciton commented 3 years ago

Thanks for the reply. No warning printed. My output looks like this

--- Debugging process started ---
Godot Engine v3.2.3.stable.mono.official - https://godotengine.org
OpenGL ES 2.0 Renderer: GeForce RTX 2070 Super/PCIe/SSE2
OpenGL ES 2.0 Batching: ON

--- Debugging process stopped ---

I've checked also Log file and Debugger, no warning and no message there about SCREEN_TEXTURE and DEPTH_TEXTURE. Have you tried running the attached minimal reproduction project? Do you get the message?

If this behavior is intentional "Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in GLES2" should be added to the "gles2_gles3_differences" tutorial.

clayjohn commented 3 years ago

A note for potential contributors, this issue has 2 actionable items:

  1. We need to investigate why the warning isn't getting printed in this test case
  2. We need to update the documentation to specify that GLES2 only supports using the DEPTH_TEXTURE or the SCREEN_TEXTURE in a given shader