WebGPURenderer: Fix shadow comparison on Adreno GPUs.#32547
Closed
mrdoob wants to merge 2 commits into
Closed
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Collaborator
Collaborator
|
So the artifacts do no appear when using WebGL 2 backend, right? |
Collaborator
Yes! |
Collaborator
|
it seems that is related with 'depthTexture.compareFunction = LessCompare' I got it working here., but Chrome debugging is crashing for me; I just need to double-check it. |
Collaborator
Owner
Author
|
Good try Claude, good try 😁 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Seems like the WebGPU backend shadows code produces artifacts on some Samsung devices:
https://x.com/alekswritescode/status/1999543059697057811
https://x.com/Andersonmancini/status/1999549976733528494
https://x.com/nctisz/status/1999480697497833669
https://x.com/ErikSombroek/status/1999445729698554099
https://x.com/the_best_codes/status/1999526930538787278
I currently do not have any of those devices at hand, but I thought I could share the issue with Claude to see if it could figure it out.
Here's what Claude found and the proposed solution 🤞
Description
Fixes shadow rendering issues on Android devices with Adreno GPUs (Samsung Galaxy S23/S25/Fold7, Xiaomi 10T Pro, etc.) when using WebGPURenderer.
Problem
The
depth24plusformat in WebGPU can be backed by eitherdepth24unormordepth32float, with different clamping behavior fortextureSampleCompare:depth24unorm: reference values are auto-clamped to [0,1]depth32float: reference values are NOT clampedOn Adreno GPUs,
depth24plusappears to usedepth32float. When shadow coordinate Z goes slightly out of range (due to bias or precision), the comparison produces incorrect results.See: gpuweb/gpuweb#4653
Solution
Clamp the shadow comparison reference value to [0,1] using
.saturate()for consistent behavior across all GPU implementations.