Skip to content

Latest commit

 

History

History
88 lines (53 loc) · 6.28 KB

README.md

File metadata and controls

88 lines (53 loc) · 6.28 KB

unity-animation-to-texture

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

Performance Improvement

7 times faster performance with 2,500 animated models, going from 10fps (100ms) to 70fps (14ms).

How it works

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.

How to use

animation-to-texture.mp4
  1. SkinnedMesh model, that has Animator and AnimatorController with animation clips.
  1. Attach the AnimationToTextureDataGenerator to the gameObject. (Recommended attaching it to the root gameObject)
  1. Assign the root gameObject to the 'Target GameObject' field.
  1. Click the ‘SetupGenerator’ button to obtain reference components automatically.
  1. Verify that references are imported properly: Animator, SkinnedMeshRenderer and AnimationClipNames. (Maximum 4 animation clips are supported)
  1. Click 'Add Renderer after generation' if you want it to be set automatically, then click the 'GenerateAnimationData' button to generate animation data.
  1. Generated data will be shown below the button.
  1. Play to test. The Animator and SkinnedMeshRenderer components will be disabled, and the MeshRenderer will be enabled automatically by AnimationToTextureRenderer.
  1. You can test animation clips through buttons in AnimationToTextureRenderer.
    Use AnimationToTextureRenderer.PlayAnimationClip(int clipIndex) to play animation clips in C# scripts.

Shader

There are two shader examples,

HLSL

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);

ShaderGraph

Retrieve the TextureAnimationSubGraph subgraph and connect it to the Position and Normal in the Vertex block.