godotengine / godotengine/godot
Depth buffer resolution is unexpectedly small when sampled in spatial shader
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Noticed in: v4.2.1.stable (when porting a working project from 3.x)
Also found when testing: v4.0.0, v4.2.2-rc2, v4.3-dev1, v4.3-dev2
**Partially fixed in: v4.3-dev3 and later** (Forward+ renderer is fixed, Mobile renderer still has same issue)
### System information
Godot v4.2.1.stable - macOS 14.3.1 - Vulkan (Forward+) - dedicated AMD Radeon Pro 555X - Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12 Threads)
### Issue description
On my system (macOS, Intel CPU, AMD GPU), 3D shaders which sample the depth buffer have visual artifacts that suggest that the depth buffer being rendered at a much lower resolution than the main camera.
Here's a scene with a plane above a torus. The plane has a simple shader attached (included in sample project zip, see below) which samples the depth buffer and uses it to set the albedo. The result appears chunky, with depth buffer resolution appearing ~8x less in both dimensions than the main camera's output.
https://github.com/godotengine/godot/assets/5893857/4cc0dcb1-3e74-4bfb-8130-5493855c088a
A similar effect can be seen when using the Proximity Fade property on the standard material.
https://github.com/godotengine/godot/assets/5893857/39e35225-7a84-4780-963e-948844142557
I encountered this when porting a shader that uses the depth buffer from Godot 3.4 to Godot 4.2.1. That shader worked as expected on the same computer under that version of Godot (and the GLES 2 backend) - i.e. the depth texture was the same resolution as the scene.
### Steps to reproduce
I can repro this on my machine with either the Forward+ or Mobile rendering method. I guess depth buffer sampling isn't supported in Compatibility mode so this bug isn't relevant there.
### Minimal reproduction project (MRP)
This test project contains the scene shown above. It's configured with the standard material with the proximity fade property enabled. The shader code shown above is also included.
[DepthBufferBugRepro.zip](https://github.com/godotengine/godot/files/14662273/DepthBufferBugRepro.zip)
Contributor guide
Research direction
Start with the attached DepthBufferBugRepro.zip and reproduce the issue in both Forward+ and Mobile renderers, focusing on spatial shader depth-buffer sampling and standard-material proximity fade. Done means the sampled depth buffer matches the main camera resolution in the affected renderer while preserving the already fixed Forward+ behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100