Skip to content

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

@aganm

Description

@aganm

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Up for grabs

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions