Home

Awesome

UnityGpuInstancedAnimation

image

based on theory: https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch02.html
Chapter 2. Animated Crowd Rendering.

DxPortfolioProject Same technique with DirectX11 that I've developed.

Created with Unity 2017.1.3f1. (At least you need 5.4 which supports Gpu Instancing)

Gpu Instancing in Unity

https://docs.unity3d.com/Manual/GPUInstancing.html

basically, you can use Graphics.DrawMeshInstanced with your mesh data, or you can use MeshRenderer which supports instancing with some of preparations in your shader.

When you use GPU instancing, the following restrictions apply:

Unity automatically picks MeshRenderer components and Graphics.DrawMesh calls for instancing. Note that SkinnedMeshRenderer is not supported.

But, you can`t use Gpu Instancing into SkinnedMeshRenderer - which is animating. This means when you want to draw all same characters at once, Unity draws all of them one on one - such a big performance loss. So I use MeshRenderer for this time.

Theory

PROS

CONS

QuickStart

Sample Scene

With your custom FBX files

  1. Create prefab with target file.
  2. Make sure you have one SkinnedMeshRenderer on your prefab - (also counts children SkinnedMeshRenderer)
    I have no plan to support Nested SkinnedMeshRenderer.
  3. Make sure you referenced AnimatorController to your skinnedMeshRenderer`s Animator with setup-wanted animations.
  4. Click your prefab, then click top menu AnimatedMeshRendererGenerator -> MeshToAsset.
  5. Call AnimatedMeshAnimator::Play(string animationName, float offsetSeconds) on your script.
    (Warning - animationName goes to original Animator`s display name, not file name.)