A tool for baking SkinnedMesh animation clip data into textures, including vertex positions and normals.
Demo (Available on Web, Mobile and MetaQuest - Powered by Spatial Creator Toolkit)
https://www.spatial.io/s/Animation-To-Texture-Demo-6599ea775c6853df735e9cd7
7 times faster performance with 2,500 animated models, going from 10fps (100ms) to 70fps (14ms).
This tool gets animation clips from AnimatorController, bakes vertex position and normal into textures and update position and normal in vertex shader.
Texture width is vertex count, and height is frame count of the animation clips. Thus, maintaining a low vertex count for the model can save a significant amount of texture memory.
animation-to-texture.mp4
- SkinnedMesh model, that has Animator and AnimatorController with animation clips.
- Attach the AnimationToTextureDataGenerator to the gameObject. (Recommended attaching it to the root gameObject)
- Assign the root gameObject to the 'Target GameObject' field.
- Click the ‘SetupGenerator’ button to obtain reference components automatically.
- Verify that references are imported properly: Animator, SkinnedMeshRenderer and AnimationClipNames. (Maximum 4 animation clips are supported)
- Click 'Add Renderer after generation' if you want it to be set automatically, then click the 'GenerateAnimationData' button to generate animation data.
- Generated data will be shown below the button.
- Play to test. The Animator and SkinnedMeshRenderer components will be disabled, and the MeshRenderer will be enabled automatically by AnimationToTextureRenderer.
- You can test animation clips through buttons in AnimationToTextureRenderer.
Use AnimationToTextureRenderer.PlayAnimationClip(int clipIndex) to play animation clips in C# scripts.
There are two shader examples,
- HLSL example: TextureAnimationExampleShader
- ShaderGraph example: TextureAnimationShaderGraphExample
Include TextureAnimation.hlsl in your shader. (example)
#include "./TextureAnimation.hlsl" // Make sure the path is correct
and get position and normal by using TEXTURE_ANIMATION_OUTPUT(positionOS, normalOS, vertexID)
in vertex shader. (example)
float3 positionOS;
float3 normalOS;
TEXTURE_ANIMATION_OUTPUT(positionOS, normalOS, vertexID);
Retrieve the TextureAnimationSubGraph subgraph and connect it to the Position and Normal in the Vertex block.