[Unity]GPU Instance How to save humanoid Animator animation into pictures

reference:

  1. GitHub - tkonexhh/RenderHugeByGPUInstance
  2. Creating shaders that support GPU instancing - Unity 手册
  3. Animator-Play - Unity Screenwriting API
  4. Unity-Animator in-depth series---API detailed explanation-CSDN blog
  5. Unity gets the frame of the current animation played_Unity gets the frame of the current animation played - CSDN Blog
  6. https://www.cnblogs.com/WalkingSnail/p/15656780.html
  7. GPU Skinning accelerates skeletal animation - Zhihu
  8. UnityShader Basics (8)-Image-Shader custom function and random color-Zhihu

plan:

  1. Prepare resources:
    1. Models that comply with Humanoid standards;
    2. AnimatorController with complete animation;
  2. Write the build script:
    1. Get all clips in Animator;
    2. Play the Animator frame by frame and save the vertex data to the Texture. One row of pixels represents all the vertex data of one frame of animation, and each pixel represents the coordinates of a vertex;
    3. Save all animation data (number of lines, starting line, clip length, clip name);
  3. Write the playback shader:
    1. Add UNITY_INSTANCING related macros;
    2. Read the picture pixel data of the animation data in v2f vert(appdata v, uint vid: SV_VertexID) and convert it into vertex data. The current frame of the animation is passed in as a parameter, corresponding to the row of the picture and the vid calculation column. Use the tex2Dlod method to read Get color value = vertex coordinate;
    3. Process the vertex color in fixed4 frag(v2f i): SV_Target (used to process color dithering, which can generate models with different colors to facilitate color differentiation such as team colors or levels. If you do not need to change the color, you can leave it alone).
  4. Write playback control script:
    1. Need to be combined with shader to control the incoming parameters (current frame number)
  5. Notice:
    1. The normalizedTime parameter of the Animator.Play method represents a time offset between zero and one .
    2. The object that executes the generated script needs to be in the scene because Animator.Play needs to be called to play the frame animation.
    3. The component value of tex2Dlod parameter 2 in the shader ranges from 0 to 1, so make good use of _TexelSize.
  6. Code:
    1. https://gitee.com/grimraider/gpu-instance

Guess you like

Origin blog.csdn.net/GrimRaider/article/details/133387996