godot: Screenspace quad shaders are broken
Tested versions
Reproducible in v4.3.dev.custom_build [a7b860250]
Not reproducible in v4.3.dev.custom_build [02488108a] Not reproducible in v4.3.dev5
System information
Godot v4.3.dev (d0c3dfe91) - Ubuntu 20.04.6 LTS (Focal Fossa) - X11 - Vulkan (Forward+) - dedicated AMD Radeon RX 6600 (RADV NAVI23) () - AMD Ryzen 7 5800X 8-Core Processor (16 Threads)
Issue description
Working view on 02488108a (it’s my custom commit, it’s somewhere after dev5). I lost the original working branch, just have the binary left 🤷
Broken view on master a7b860250 :
Steps to reproduce
I uploaded a test project with a simple screenspace quad depth shader. In master it only renders on skybox, in dev5 and somewhere after it it correctly renders on top of the objects.
Minimal reproduction project (MRP)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (12 by maintainers)
It indeed looks like a regression from the Reverse-Z PR. But I’m 99% certain the problem is the vertex shader since its clear that the mesh isn’t showing up at all.
edit: Yep, the problem is that the quad shader trick relies on treating the quad coordinates as clip space coordinates, so the z needs to be reversed. I.e.
POSITION = vec4(VERTEX.xy, 1.0-VERTEX.z, 1.0);worksWe will have to discuss this further with the rendering contributors. I forgot that
POSITIONallows users to write vertex positions directly in clip space. We knew there would be some compatibility breakage from the reverse-z change, but we figured it would be limited as there are few places where working in clip space is useful in user shaders. However, this shows that there is going to be more widespread breakage than we thought.One option is to automatically reverse the z-value for users. We could then document that POSITION is in a modified clip space where 0 is the near plane and 1 is the far plane. That would avoid compatibility breakage, but it would be pretty annoying in the long run
I think I understand you now. We do have a macro to tell when the user is using the compatibility renderer, but it’s not obvious. OUTPUT_IS_SRGB is true in the compatibility renderer and false otherwise. we could add a new macro CLIP_SPACE_FAR which is 0 for the Vulkan backend and -1 for OpenGL.