Repository navigation
Batch: Only update the previous matrices texture when the matrices change. - #35057
Merged
Merged
Conversation
…ange. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
📦 Bundle sizeFull ESM build including core, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Mugen87
approved these changes
Oct 17, 2026
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.
Fixed #35042.
Description
When a
BatchedMeshis rendered with velocity (TRAA, motion blur), theOnAfterObjectUpdatecallback inBatch.jscopies_matricesTextureintopreviousMatricesTextureand setsneedsUpdateafter every draw, so the whole matrices texture is copied on the CPU and uploaded again each frame even when nothing moved.This PR keeps the source texture and its
versionin the cached previous-matrices data and only copies when either has changed. The copy runs after the draw, so when the version is unchanged the previous texture already holds the current matrices and skipping is safe. The texture reference is part of the check so a different_matricesTextureis never treated as unchanged.previousMatricesTextureis now also markedneedsUpdatewhen it's created. Before, its first upload happened only after the first draw, so the first frame read an empty texture and produced velocity for every static instance.Tested with a page that renders a 3-instance
BatchedMeshintomrt( { output, velocity } )for 9 frames, moving one instance on frames 2 and 5, with both the WebGPU and WebGL backends:previousMatricesTextureuploads: 8 → 3 (creation + the frame after each move).npm run linton the changed file andnpm run test-unitpass. E2E forwebgpu_mesh_batch,webgpu_shadowmap_array,webgpu_postprocessing_motion_blur,webgl_mesh_batchandwebgl_batch_lod_bvhshow no diff.Unrelated, but found while testing: calling
setInstanceCount()with a larger count after the first frame throwsRangeError: offset is out of boundsin this callback, becausegetPreviousNode()returns the cachedpreviousMatricesTexturesized for the old_matricesTexture. This PR doesn't change that behavior; I can open a separate issue/PR for it.🤖 Generated with Claude Code