WebGLRenderer: Fix pointlight shadows with reversed depth buffer.#32749
Merged
Mugen87 merged 1 commit intomrdoob:devfrom Jan 14, 2026
Merged
WebGLRenderer: Fix pointlight shadows with reversed depth buffer.#32749Mugen87 merged 1 commit intomrdoob:devfrom
Mugen87 merged 1 commit intomrdoob:devfrom
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Mugen87
commented
Jan 14, 2026
|
|
||
| float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) ); | ||
|
|
||
| #endif |
Collaborator
Author
There was a problem hiding this comment.
FYI: In this BasicShadowMap version, we could also keep the "viewZ to perspective depth" formula as it is and just do this instead:
float depth = textureCube( shadowMap, bd3D ).r;
#ifdef USE_REVERSED_DEPTH_BUFFER
depth = 1.0 - depth;
#endif
shadow = step( dp, depth );
However, that does not work for PCF where we don't directly sample the shadow map but use a compare operation.
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.
Related issue: #31661
Description
The PR fixes the viewZ to perspective depth computation for point light shadows with Basic and PCF shadow maps when reversed depth buffer is used.
It would also be possible to just add
dp = 1.0 - dp;but that would be an additional computation that we can save by using an updated formula for reversed depth buffer in the first place.Note: This is something we can later hide in the
viewZToPerspectiveDepth()TSL function.