Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z coordinate in shaders is not the same across Compatibility and Forward+/Mobile #100310

Open
aganm opened this issue Dec 12, 2024 · 1 comment
Open

Comments

@aganm
Copy link
Contributor

aganm commented Dec 12, 2024

Tested versions

Tested and reproducible in Godot 4.3 stable and Godot 4.4 dev6.

System information

Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated Radeon RX 580 Series (Advanced Micro Devices, Inc.; 31.0.21912.14)

Issue description

This issue explains the problem tiffany352/godot-starlight#2

To sum it up, the background shader gets rendered on top of a cube object as you can see in this image, notice the little white spots on top of the cube:

Image

The problem has been identified with this line:

https://github.com/tiffany352/godot-starlight/blob/bc7a4cc22b53fc42986a6c9c0fe369f86b8f3a9d/addons/starlight/Star.gdshader#L65

The solution is to change the way the background shader handles depth.

For me, this solution works for Compatibility renderer:

POSITION.z = -1.0 * projected.w;

Godot v4.3.stable - Windows 10.0.19045 - GLES3 (Compatibility) - Radeon RX 580 Series (Advanced Micro Devices, Inc.; 31.0.21912.14)

But Forward+/Mobile, I need to do that instead:

POSITION.z = 1.0 / projected.w;

Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated Radeon RX 580 Series (Advanced Micro Devices, Inc.; 31.0.21912.14)

Steps to reproduce

Open https://github.com/tiffany352/godot-starlight in Godot 4.3 and move the 3d viewport camera in front of the cube object in the scene, and observe how the background renders on the cube. Switch renderer between Forward+/Mobile and Compatibility.

Minimal reproduction project (MRP)

https://github.com/tiffany352/godot-starlight

@tetrapod00
Copy link
Contributor

I believe this is a documentation issue. I don't quite understand all the details well enough to fully explain them, but there are differences in the internal coordinate spaces of the Compatibility and the Forward+/Mobile renderers that won't be changed for compatibility reasons. One of those differences is the z value of the far clip plane. godotengine/godot-proposals#10273 gets into it a little.

In 4.4 we now have access to CLIP_SPACE_FAR (#95057) and preprocessor defines (#98549), so you now have the tools to write shaders that will work in all renderers.

In this case, if the comment is accurate and the goal is to always render at the far clip plane, you might be able to use:
POSITION.z = CLIP_SPACE_FAR;

I think that the existing docs issue godotengine/godot-docs#10204 in theory covers this case. But we should probably leave this issue open, to track specifically documenting the far clip z value.

@clayjohn clayjohn moved this from For team assessment to Up for grabs in Rendering Issue Triage Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Up for grabs
Development

No branches or pull requests

4 participants