Visitar URL original
Fix TAA reprojection with instances: previous world matrices for the linear velocity prepass by enriqxxx · Pull Request #19024 · BabylonJS/Babylon.js · GitHub
Skip to content

Fix TAA reprojection with instances: previous world matrices for the linear velocity prepass - #19024

Open
enriqxxx wants to merge 1 commit into
BabylonJS:masterfrom
enriqxxx:fix-taa-instances-velocity-linear
Open

enriqxxx wants to merge 1 commit into
BabylonJS:masterfrom
enriqxxx:fix-taa-instances-velocity-linear

Conversation

@enriqxxx

Copy link
Copy Markdown
Contributor

Fixes #19023. Forum: 64212 #23-#25.

PrepareAttributesForInstances now requests previousWorld0..3 for PREPASS_VELOCITY_LINEAR as it already does for PREPASS_VELOCITY, which is what instancesDeclaration declares and what GeometryBufferRenderer already does. Without it, TAA with reprojectHistory renders nothing on WebGPU as soon as a mesh is drawn with instances (the vertex state misses those attributes).

Tests. materialHelper.functions.test.ts checks the attribute list for hardware instances and thin instances with PREPASS_VELOCITY_LINEAR, with PREPASS_VELOCITY, and without a velocity prepass (world matrices only).

Real velocity check (9.31.1, then 9.31.1 with this change; Chromium 147, RTX 3080 Laptop GPU, WebGPU). 25 boxes move every frame under an orbiting camera, drawn as regular meshes (reference), thin instances (with a previousMatrix buffer) and createInstance(). After 60 fixed frames the linear velocity target is read back and compared with the regular meshes, pixel by pixel:

Variant 9.31.1: errors / pixels drawn With this change: errors / pixels drawn Velocity vs regular meshes (mean / max difference)
Regular meshes (reference) 0 / 29,635 0 / 29,635 reference
Thin instances 121 / 0 0 / 29,635 0 / 0
createInstance() 121 / 0 0 / 29,635 0 / 0

With this change both instanced variants write exactly the velocities of the regular meshes, pixel by pixel (all 29,635 covered pixels move). materialHelper.functions.test.ts passes, 21/21.

🤖 Generated with Claude Code

…linear velocity prepass

TAARenderingPipeline requests PREPASS_VELOCITY_LINEAR, and instancesDeclaration declares previousWorld0..3 for it, but
PrepareAttributesForInstances only pushed those attributes for PREPASS_VELOCITY. With reprojectHistory, every instanced
mesh then made the velocity prepass pipeline invalid on WebGPU ("Vertex attribute slot ... is not present in the
VertexState", the frame is dropped) and got a wrong velocity on WebGL2. GeometryBufferRenderer already checks both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Popov72

Popov72 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@Popov72 Popov72 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve

Completed a full current-PR skeptical review. The shared instance-attribute helper now matches the existing GLSL/WGSL linear-velocity declarations, with focused hardware/thin-instance and legacy/no-velocity coverage. No actionable findings. This is a read-only code-review assessment, not a claim that tests or browser measurements were independently rerun.

@bjsplat

bjsplat commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat

bjsplat commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Snapshot stored with reference name:
refs/pull/19024/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/19024/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/19024/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/19024/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/19024/merge
https://gui.babylonjs.com/?snapshot=refs/pull/19024/merge
https://nme.babylonjs.com/?snapshot=refs/pull/19024/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/19024/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@deltakosh deltakosh self-assigned this Oct 26, 2026

@deltakosh deltakosh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hello @enriqxxx,

Looks good to me!

Thanks!

@deltakosh
deltakosh enabled auto-merge (squash) October 26, 2026 16:53

This branch has not been deployed

No deployments
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.

WebGPU: TAA with reprojectHistory renders nothing when instances are drawn (previousWorld missing for PREPASS_VELOCITY_LINEAR)

4 participants