WebGPURenderer: Align depth range of WebGPU and WebGL backends #28065
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When overriding the
depthPixelBase
, both backends display different behaviors related to their distinct depth ranges, with WebGPU being[0, 1]
and WebGL being[-1, 1]
.It seems that without extensions such as
EXT_depth_clamp
, WebGL internally clamps these values to the range [0, 1] during the rasterization process. So, I believe that it wouldn't be wrong to handle it internally, ensuring that if a user overrides the depth of a material, both backends will show the same result.Edit: Or should we do the opposite and handle WebGL depth range first? I'm not sure, it seems that the case is very variable on if we want to handle it manually. For example the issue I was solving there was that using
0.5 * modelViewMatrix.z / modelViewMatrix.w + 0.5
breaks in WebGPU as it should bemodelViewMatrix.z / modelViewMatrix.w
.This contribution is funded by Utsubo