Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle alphaToCoverage in shadow map generation #30760

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

mattverse
Copy link

Related issue: #30462

Description
When materials use alphaToCoverage shadow map used to fail to respect the transparency. This occurs because shadow generation relies on alphaTest to discard fragments, but alphaToCoverage bypasses alphaTest and uses multisampling instead. As a result, shadows render opaque even when the material appears transparent.

This PR fixes this by adding a check if original material uses alphaToCoverage then setting the shadow material's alphatest manually.

Before:
Screenshot 2025-03-20 at 12 14 15 AM

After this change has been applied:
Screenshot 2025-03-20 at 12 09 47 AM

Copy link

github-actions bot commented Mar 20, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.08
78.29
336.13
78.3
+47 B
+12 B
WebGPU 525.17
146.28
525.17
146.28
+0 B
+0 B
WebGPU Nodes 524.63
146.18
524.63
146.18
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 465.15
112.18
465.2
112.19
+47 B
+12 B
WebGPU 597.97
162.56
597.97
162.56
+0 B
+0 B
WebGPU Nodes 553.1
152.04
553.1
152.04
+0 B
+0 B

result.alphaMap = material.alphaMap;
result.alphaTest = material.alphaTest;
result.map = material.map;
if ( customMaterial === undefined ) {
Copy link
Collaborator

@Mugen87 Mugen87 Mar 23, 2025

Choose a reason for hiding this comment

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

Why did you introduce this new if statement?

Copy link
Author

Choose a reason for hiding this comment

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

Previously, when a user provided customDepthMaterial, the original code overwrote properties like alphaMap or alphaTest of the customMaterial without this if statement

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 23, 2025

Do you mind sharing a live example that demonstrates the issue? That would make it easier to verify the suggested change.

@mattverse
Copy link
Author

@Mugen87 This is a good example from the original author of the issue https://codesandbox.io/p/sandbox/exciting-water-hz8k92

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.

2 participants