Skip to content

WebGLRenderer: Fix pointlight shadows with reversed depth buffer.#32749

Merged
Mugen87 merged 1 commit intomrdoob:devfrom
Mugen87:dev5
Jan 14, 2026
Merged

WebGLRenderer: Fix pointlight shadows with reversed depth buffer.#32749
Mugen87 merged 1 commit intomrdoob:devfrom
Mugen87:dev5

Conversation

@Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Jan 14, 2026

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.

@github-actions
Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 355.15
84.44
355.57
84.48
+416 B
+45 B
WebGPU 621.09
172.46
621.09
172.46
+0 B
+0 B
WebGPU Nodes 619.7
172.22
619.7
172.22
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 487.39
119.33
487.81
119.38
+416 B
+42 B
WebGPU 692.03
187.85
692.03
187.85
+0 B
+0 B
WebGPU Nodes 641.83
175.02
641.83
175.02
+0 B
+0 B

@Mugen87 Mugen87 added this to the r183 milestone Jan 14, 2026
@Mugen87 Mugen87 merged commit e90650f into mrdoob:dev Jan 14, 2026
10 checks passed

float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );

#endif
Copy link
Collaborator Author

@Mugen87 Mugen87 Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant