Repository navigation
Meshes that deform are skinned on the GPU - #181
Merged
Merged
Conversation
…hored tangent follows its joints Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A new shared pose sent every triangle of its mesh: 180 bytes each, skinned on the CPU. Now the CPU sends the pose's matrices and a compute pass skins the mesh from its model's corners: triangles, shading attributes, BLAS input. The CPU keeps no triangles of such a pose; a click or a query skins the mesh when it asks. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A posed model the scene did not call movable was moved by skinning it again where it stands. One that is an instance of a deforming mesh was not moved at all: no pose had changed, and nothing rebuilt. Its move is recorded as a move now; the renderer moves an instance and skins world-space triangles again. The test's fixture: 72 triangles (two blocks of the pass), a joint turned about an axis that is neither the normals' nor the tangents', a node that mirrors its mesh, a clip that turns it back. The test: two model files in two poses (two sources, two jobs), a model moved alone, posed and moved at once, after the scene's buffers grew, and a pose that mirrors other primitives. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A mesh's triangles were in its model's order, and first in the GPU's, in every scene the tests had: corners left in the model's order, and a job counted from the pool's start, passed. The fixture's materials now go light, grey, light, and the scene has a rect light's card before the meshes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
A new pose of a mesh that deforms was skinned on the CPU and every triangle of it sent again: 180 bytes each (its vertices, its shading attributes, the BLAS's input). Now the CPU sends the pose's matrices and a compute pass skins the mesh where it lies.
shaders/skin.wgsl,Gpu::skin): a triangle an invocation, from its model's corners as the file has them (position, normal, tangent, four matrices and weights; one copy a model, whatever its poses) and the pose's matrices (a skin's joints, and the nodes of primitives beside it), into the triangles, the attributes' normals, tangent and texel density, and the BLAS's input. The commit builds the mesh's BLAS after it, as before.Still on the CPU: a posed model alone in its pose (world-space triangles: the next step makes it a mesh of its own), and every pose under software traversal.
A fault found on the way, older than this
A posed model the scene did not call movable was moved by skinning it again where it stands, so its move was recorded as a new pose. One that is an instance of a mesh that deforms was then not moved at all: no pose had changed, and nothing rebuilt. A posed model's move is a move now: the renderer moves an instance, and skins world-space triangles again. The test of it was 3.6 steps from a build's picture before.
Measured
A crowd of 150 walkers in 8 shared poses, hardware traversal, the two builds in turn after a run thrown away:
With every walker a mesh of its own (a switch of an experiment, not in the tree): the CPU's frame is 24 ms with the CPU skin (15 ms of it upload: 40 fps) and 7.4 ms with the pass (60 fps).
GPU time a frame at 1080p on twelve scenes (the crowd among them), two alternated pairs against main after a run thrown away: all within 0.7 %; the two scenes with posed models again at the last commit: within 0.4 %. The quality figures against the offline references are main's.
Checks
tests/render/data/skin-blend.glb: more triangles than a block of the pass, vertices two joints hold, weights that do not sum to one, a primitive with tangents, one without normals, a joint turned about an axis that is neither the normals' nor the tangents', a mesh on a node beside the skin that mirrors it, materials in an order the mesh does not keep), with world-space triangles before the meshes'; the previous frame's vertices, the mesh as the CPU has it when asked, the picture against a build's; a model moved alone, posed and moved at once, posed after the scene's buffers grew; a pose that mirrors other primitives, by a rebuild; the corners placed by the palette on the CPU against the model's triangles; the shader valid as WGSL.🤖 Generated with Claude Code
Note
Medium Risk
Touches live pose updates, GPU buffer layout, and picking correctness on the hardware-RT path, though coverage is strong (GPU vs CPU readback, mutation tests).
Overview
Deforming mesh poses are skinned on the GPU instead of re-skinning on the CPU and re-uploading every triangle (vertices, attributes, BLAS input). Each frame the CPU only uploads joint palette matrices;
shaders/skin.wgslandGpu::skinrun a compute pass (one invocation per triangle) from shared per-model corners (Scene::skin_sources,SkinCorner) into scene verts,TriAttr, and BLAS geometry before BLAS rebuild.Scene prep adds
skin_sourcesand extendsPoseGroupwith palette layout and mirror metadata; poses that change triangle order via mirroring still force a rebuild. Picking /node_trisno longer rely on a full CPU copy of posed triangles—they on-demand CPU-skin via newmesh_triswhen needed.Bugfix: moving a non-movable posed model is recorded as
moved(instance transform), not as a new pose, so shared deforming instances actually update when only the transform changes. Tangents on skinned vertices now follow joint blending like normals.Documentation and broad tests compare GPU buffers word-for-word to CPU skin, including move/pose combos and buffer regrowth.
Reviewed by Cursor Bugbot for commit 622bf0f. Bugbot is set up for automated code reviews on this repo. Configure here.