Skip to content

fix: split batches by castShadow and shadowCascadeMask#8650

Merged
mvaligursky merged 1 commit intomainfrom
mv-batch-shadow-split
Apr 24, 2026
Merged

fix: split batches by castShadow and shadowCascadeMask#8650
mvaligursky merged 1 commit intomainfrom
mv-batch-shadow-split

Conversation

@mvaligursky
Copy link
Copy Markdown
Contributor

When mesh instances were merged into one batch, the resulting single MeshInstance took castShadow (and related state) only from the first source instance. Instances that matched on material, shader defines, and other batch keys but differed in shadow casting could all inherit the wrong flag, which showed up as incorrect shadow maps (see #8646).

Changes

  • Split batch groups in BatchManager.prepare when castShadow or shadowCascadeMask differs between candidates.
  • Document the new split rule in prepare JSDoc.
  • Add a unit test that two batched boxes with different castShadow produce two world-layer mesh instances with the expected flags.

API changes

  • None.

Performance

  • Slightly more batches (and draw calls) when the same batch group mixes shadow-casting and non–shadow-casting geometry; behavior matches disabling batching for those cases.

Fixed #8646

Batched geometry uses a single MeshInstance; shadow casting must match
all source instances. Fixes incorrect shadow behavior when batching
meshes that differ only in castShadow (e.g. #8646).

Fixed #8646
@mvaligursky mvaligursky self-assigned this Apr 24, 2026
@mvaligursky mvaligursky merged commit 40ec973 into main Apr 24, 2026
8 checks passed
@mvaligursky mvaligursky deleted the mv-batch-shadow-split branch April 24, 2026 14:45
mvaligursky added a commit that referenced this pull request Apr 24, 2026
Batched geometry uses a single MeshInstance; shadow casting must match
all source instances. Fixes incorrect shadow behavior when batching
meshes that differ only in castShadow (e.g. #8646).

Fixed #8646

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
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.

Batching issue with shadows

1 participant