Search Unity

[BETA RELEASE] GPU Instancer - Crowd Animations

Discussion in 'Assets and Asset Store' started by LouskRad, Apr 29, 2019.

  1. RonanBurgess

    RonanBurgess

    Joined:
    Apr 20, 2013
    Posts:
    105
    Hi
    Can you say something more about the Crowd Animator workflow and maybe give some examples of the API?
    How easy is it to blend the transitions from one animation to the next?
    How do you know when an animation has finished? Are there callbacks?
    Thanks
     
  2. padhont

    padhont

    Joined:
    Oct 1, 2015
    Posts:
    15
    Hi there!

    Great tool, but I have found a small issue.
    When using the same prefabs in multiple scenes, whenever you switch scenes these prefabs break and no CrowdAnimator will be created.
    While debugging the code I found a static Dictionary in the GPUInstancerPrefabRuntimeHandler class, that has the prefab prototype as key, and the prefab manager as value, the problem seems to be that when switching scenes this dictionary doesn't get cleared, but since the prefab manager was destroyed the link is gone even though a new prefab manager exists in the next scene.

    When setting the dictionary to null when a new scene is loaded, this seems to resolve the issue but I am uncertain if this could break anything else?

    Anyways, if I missed something let me know, I am also curious why you save prefab data on the prefab itself and in the scene (with the prefab/crowd manager) and not in a scriptable object?

    Great work on the tool! It has saved me and our team a lot of time :)
     
  3. DigitalGlass

    DigitalGlass

    Joined:
    May 12, 2009
    Posts:
    86
    The description mentions that the LOD needs to share the same bones. Is this only if we want the LODs to share the same gpu skinning? What if for LOD0 I want to have a more detailed skeleton with ik and physics simulations, crowd rendering for LOD 1-3 and then billboards for LOD 4?
     
  4. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    We have not investigated World Creator 2, and as such a possible integration is not currently in our roadmap. However, if this asset creates a Unity terrain in editor time (such as Gaia does) an integration might not be necessary to use it together with GPUI.
     
  5. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,
    You can take a look at the API documentation from this wiki page. The package also includes demo scenes that show how to use the Crowd Animator.

    Animation events are not supported with the Crowd Animator, however. Since the Crowd Animator works completely in the GPU, there are no callbacks to any CPU resources. Currently, to detect the end of an animation when using this workflow, you can track animation time.
     
  6. DavyM

    DavyM

    Joined:
    Jun 13, 2018
    Posts:
    4
    World Creator 2 is a standalone program, so there is my answer for now. Hopefully some day it gets integrated.

    Thanks.
     
  7. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,
    and thank you for reporting this issue, we will look into it and add the fix for this in the next GPUI update. Setting the dictionary to null (or better yet clearing it) would work fine.

    GPUI keeps track of its prototypes with the prefab/crowd script it adds on their prototypes. The prototype data is referenced by this script and it is indeed held in scriptable objects (under /GPUInstancer/PrototypeData), but the script serves various other purposes as well.
     
  8. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    This case would work with a custom LOD setup where you define only LOD 1-3 (and if you wish, 4) as separate prototypes and manage their visibility yourself. However, doing this out of the box with a default Unity LOD Group setup is currently not supported.
     
    DigitalGlass likes this.
  9. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    46
    Hi, just purchase this asset, thank you for creating it and GPUI.
    The first post states "Crowd Animations works by baking the bone data of animation clips into a texture and reading that texture in Compute Shaders to feed skinning data to the rendering pipeline for indirect skinned-mesh instancing."

    Should we assume that each animation that is baked will increase GPU RAM usage, is there any data/limit on how many animations can be baked?
    Do animations take up a lot of GPU RAM? As its just the bone data i assume that the poly/vert count of the model doesn't effect the RAM usage?
    So then is it possible to know the RAM usage per frame of animation?

    So baking a lot of animations will have no runtime performance degradation only increased GPU RAM footprint?
     
    Last edited: Jul 2, 2019
  10. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    214
    Hey guys.

    Quick question does the crowd work with ootii motion controller ? :)
     
  11. RonanBurgess

    RonanBurgess

    Joined:
    Apr 20, 2013
    Posts:
    105

    Thanks for the explanation. From what I can see from the wiki you can define a starttime when playing a single animation clip and when blending multiple clips you can define the blending weights.
    But I dont see how you could blend a transition from one clip to another. For example if halfway through an animation you need to start to blend in a death animation, increasing the weight of the death animation over a transition time.
    Is there some way to do that using the API?
    Thanks
     
  12. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,
    the GPU ram usage for a prototype's animation depends on the rig of the model, and the length of the total baked animations.

    You can generally refer to this formula for an exact calculation:
    total bytes for all animations = total frame * total bone count * 64 (matrix size) [rounded to the next power of two].

    For an example of complex model with many animations, the Ellen example in the demo scene (33 animations, 60 fps):

    2594 (total frames) * 85 (bone count of the Ellen rig) * 64 = 14,111,360 bytes.
    Rounded, this takes 16 MB GPU Ram.

    For an example of a lighter model, the ZomBear example in the demo scene (3 animations, 60fps):

    763 (total frames) * 17 (bone count of the Ellen rig) * 64 = 830,144 bytes.
    Rounded, this is a 1 MB footprint.

    Please note that this is not completely an additional GPU memory usage, since Unity itself uses GPU ram for these operations when not using GPUI. So you can think of these numbers as a replacement of what Unity already uses.

    Please also note that various other operations that GPUI does in the GPU also have footprints, but they should be negligible.
     
  13. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,
    we have not tested this asset specifically, but CA would not work out of the box with any asset that does additional bone modifications during animations (since the animations are baked).
     
  14. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Currently there is no API method for such a timed transition, but you can use blend weights for a transition effect by updating the animation weghts using the SetAnimationWeights API method, for example, in a coroutine.
     
  15. RonanBurgess

    RonanBurgess

    Joined:
    Apr 20, 2013
    Posts:
    105
    But is it possible to have a different start time for two animation clips which are being blended together? So when you are 50% through the first animation you blend in the start of the second animation? Its not clear to me from the wiki whether you can do that. I only see StartTime as a parameter for the StartAnimation method for a single clip, not the blend.
     
  16. Nihilus0

    Nihilus0

    Joined:
    Jan 25, 2017
    Posts:
    52
    LouskRad,
    Hi, I haven't bought yet. Before purchasing, I have a question.
    Is possible change for each same model? Its all very well rendering 10,000 instances of the same model, but even if the animation of each is independent, they all look the same.

    For example, is it possible to apply different colors use 'Color tinting' to the same models?
    20190704_051407_4.jpg 20190704_051407_3.jpg
    Or can different textures be applied to the same models?
    20190704_051407_5.jpg
    Or can different parts(Helmets, Weapons, Tools, Clothes, etc.) be equip in different patterns on the same models?
    20190704_051407_2.jpg 20190704_051407_1.jpg
    [These ideas came from 'Ultimate Epic Battle Simulator'and 'Left4Dead Gradient Mapping', 'Total War'.]

    Even if these features are not implemented, I would like to know the potential of an asset that can easily implemented from buyers.

    Thanks.

    P.S. I am not an English speaker. I used a translator. I am sorry my poor English.
     
    Last edited: Jul 4, 2019
  17. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    We will add API methods in the next update for both getting/setting animation times and for animation transitions.
     
  18. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,
    Instance based variations are indeed possible. They can be done using a "variation buffer" on you shaders. An example seen is included showing this for mesh renderers in the base GPUI package, and we will also add an example scene that showcases its usage in skinned mesh renderers as well.

    Please note, however, that even though shader property variations are possible, you would not be able to vary the vertex colors of your meshes, since GPU instancing works for the same exact meshes only.
     
    Nihilus0 likes this.
  19. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    214
    So this would mean that final ik (inverse kinematics will not be possible) ?
     
  20. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    205
    Does this support 2 cameras simultaneously? Having a skinned mesh, with about 10 different animations. And a collider with a few scripts?.
     
  21. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    It would not be ideal performance-wise to use a complex kinematics system with the instances of a crowd - however you can use instance based enabling/disabling of GPUI to use various assets on your instances when, say, they are close to the camera.
     
  22. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Yes:

    You can add 2 Crowd Managers with the same prototype, set the respective camera to each and choose the "Use selected camera only" option to render the instances in both cameras simultaneously.

    You can also use colliders and scripts on your instances.
     
  23. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    61
    It doesn't work. The crowd is not visible when the scene starts and Mesh Animator works much better compared to this.
     
  24. Sisay

    Sisay

    Joined:
    Dec 6, 2012
    Posts:
    7
    no work in hdrp ;/
     
  25. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Can you give a little more detail, please:

    - Do you see any errors/warnings in the console window?
    - Which Unity version and render pipeline are you using?
    - Which platform are you targeting?
    - Did you follow the setup guide in the readme documentation (e.g. import GPUI before Crowd Animations)?

    Also, can you please send a screenshot of the Crowd Manager during runtime.
     
  26. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Yes, HDRP is currently not supported. We will look into its support in a future update.
     
  27. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    61
    - No errors
    - Unity 2018.4.3f1
    - Windows (VR)
    - Yes, i have imported GPUI and then Crowd animations
    - Crowd is not visible
     

    Attached Files:

  28. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Can you select a single prototype from the manager (not multiple) and look at the warning/error message that shows in the manager? There is one since the frames of prototype icons show red in your screenshot. You have also turned off console warnings so that you don't see GPUI warning you of the problem (there are 55 warnings in your screenshot).

    Most likely, the issue is that your prefabs use a custom and/or built-in shader that is not setup for CA. If that is the case, you can set your crowd materials to use the Standard Shader, or look at this wiki article for information on setting up your shader with CA.
     
  29. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    61
     

    Attached Files:

  30. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    61
    I have modified the shader but now the crowd is in T pose.
     

    Attached Files:

  31. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    You haven't made the vertex function modification. You need to call the GPUI_CROWD_VERTEX(v); method to use baked animation data in this function. Here is the working version of this shader.
     

    Attached Files:

  32. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    61
    Thank you for your help but i have a much better performance with Mesh Animator. I will continue to use GPU Instancer for static objects.
     
  33. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    135
    Hi,

    I just bought this nice tool to complement GPU instancer.

    Is there any doc or info available somewhere?
    I made some quick tests and I can easily add prototypes to the crowd manager but
    I couldn't find how to randomize the frames for my own prototypes and how I decide how they are spawned.

    If you could point me to the right direction this would be greatly appreciated. :)
     
  34. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    46
    Hi,
    Just been doing some super simple tests with GPUI Crowd Manager.
    But may have found a bug/issue.

    I am rendering 10,000 models with the following settings:
    Auto select Camera true
    Use Frustum culling true
    use Occlusion culling true
    runtime settings
    Enabled runtime modifcation true
    add/reove instances true
    extra buffer size 10000
    auto add/remove instance true


    Setting build quality settings to high and disabling v-sync

    In editor (1080p window) i am getting:
    221 FPS with a frame time of 4.7ms

    In build (1080p windows) i am getting:
    106 FPS with a frame time of 9.6ms

    So half the performance in a build then in the Edtior.

    I am pretty sure i am using the same quality settings and its a fair test, nothing else going on in scene, just GPUI crowds.

    Just to rule out any other build settings being a fault, with everything else the same, but rendering the 10,000 units with another method other then GPUI crowds
    Edtior
    Non in camera view = 230fps 4.2ms
    All in camera view = 85fps 12ms
    Build
    Non in camera view = 800fps 1.1ms
    All in camera view = 94fps 10.6ms

    So does appear to be issue with GPUI crowds in builds. (Target build platform is windows) Or i have some incorrect settings with GPUI crowds.

    Note if i change Runtime settings to auto update transform to true and set all transforms to move i see:
    editor 50fps in view 50fps out of view
    build 96fps in view 96fps out of view
    Which appears to remove the bug where Editor is faster then build, then i appear to be losing culling support when transforms are set to auto update, not sure if that is a runtime limitation or not by design?

    Note - just to say that i have gone back to this after getting some sleep, and does appear to be the case. If Auto update transform data is disabled, Editor runs at about twice the speed of a build

    -- Edit
    Hi, as i am in need of so many Units and concerned that my bug post was something i did wrong i have used your NoGameObjectsDemoSceneHandler.cs as base for using the no-GameObject workflow.
    With nothing else in scene, and just Initialize the manager with the created matrix i am seeing the following.

    Rendering 10,000 units Editor = all in view = 160fps, none in view = 250fps
    Rendering 20,000 units Editor = all in view = 100fps, none in view = 250fps
    Rendering 30,000 units Editor = all in view = 73fps, none in view = 250fps
    Rendering 30,000 units Build = all in view = 57fps, none in view = 176fps – Worse performance in build.
     
    Last edited: Jul 21, 2019
  35. ssh0494

    ssh0494

    Joined:
    Apr 12, 2019
    Posts:
    1
    Hello developer (sorry that i'm not good at english lol)
    i found the error in your program, so i need your help. please give me a solution. lol

    i clicked all checkboxes in Crowd Manager's Runtimesetting, and i adapted the code below to the object
    the code is....

    ////////////////////////////////////////////////////////
    public class AI_Test: MonoBehaviour
    {
    public AnimationClip [] clip; // 0: run, 1: die
    GPUICrowdPrefab pref;
    private void Awake ()
    {
    pref = GetComponent <GPUICrowdPrefab> ();
    }
    private void Start ()
    {
    transform.position = new Vector3 (Random.Range (-10, 10), 0, Random.Range (-10, 10));
    StartCoroutine (Start_Ani ());
    }
    IEnumerator Start_Ani ()
    {
    GPUICrowdAPI.StartAnimation (pref, clip [0]); // run
    float rand = Random.Range (5f, 16f);
    yield return new WaitForSeconds (rand);
    GPUICrowdAPI.StartAnimation (pref, clip [1]); // die
    float Die_Start_Time = clip [1] .length;
    yield return new WaitForSeconds (Die_Start_Time - Time.deltaTime - 0.03f);
    GPUICrowdAPI.StartAnimation (pref, clip [1], Die_Start_Time - Time.deltaTime - 0.03f, 0, 0);
    yield return new WaitForSeconds (2f);
    Destroy (gameObject);
    }
    }
    ///////////////////////////////////////


    but when i run this for test, i found the problem.

    when i created 10 objects per 10 seconds for testing
    It does not matter if all of the objects in the current scene are deleted within 10 seconds of the next creation time,
    but if there are reamaining objets(at least one) which are not deleted in that 10 seconds, the bug is occured
    The bug is that when the next object is created, the last command "GPUICrowdAPI.StartAnimation (pref, clip [1], Die_Start_Time - Time.deltaTime - 0.03f, 0, 0);" Is still being executed. it skips the command in the priority order "GPUICrowdAPI.StartAnimation (pref, clip [0]); // run".

    i experienced great efficiency in using your program! so i extend my deepest gratitude to you!
    because i'm not good at wrtting the english, i'm worrying that exact meaning is delivered to you.
    i'll wait for you answer, have a good day.
     
  36. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,

    you can check the Crowd Animator section of the GPUI API documentation for information on the Crowd Manager API. For various components (such as the randomizer) you can take a look at the Crowd Manager getting started wiki.
     
  37. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,
    and thank you for the detailed breakdown.

    We have tested this with the included regular and no-game object demo scenes, and we cannot see this difference. Which FPS counter are you using? and which Unity version are you seeing this on?

    We can make further detailed tests to identify this problem if you can provide us with a sample project where you see this.
     
  38. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,
    and thank you for reporting this.

    We have investigated the code that is related to the "Auto. Add/Remove Instances" feature, and we have found a bug there. This bug causes a loss of sync with the animator in some cases when instances are removed with this feature. We will add a fix for this in the next update.
     
  39. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    135
    I didn't realize there was a complete manual on Wiki. I will read it first and come back if I have more questions.

    Thank you! :)
     
    LouskRad likes this.
  40. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    46
    I am so sorry to waste your time, as i have retested tonight, but what i found was interesting.
    Editor all in view 166fps none in view 200fps
    Build all in view 135fps none in view 400fps
    So its odd that again i find worse performance in Build, i have a dual monitor setup so i ran the Editor on one monitor and the build on the other, side by side, so performance should be equal, however it became noticeable as to why it wasn't. The quality level was difference between the edtior window and the build window. I found this online
    "the build/player saves and restores the last selected quality level. Means, after the first start it does not pick up the setting selected in the editor anymore. You need to delete the quality level entry from the windows registry to make the build pick up the editor setting again."
     
    LouskRad likes this.
  41. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi everyone,

    We have published an update for the Crowd Animations, along with a new version of GPUI: v1.2.1. With this update we did major refactoring of the code base for better compatibility with different target platforms.

    Please note that before updating Crowd Animations to 0.8.3, you need to first update GPUI to v1.2.1.
     
  42. JarrydFP

    JarrydFP

    Joined:
    Oct 6, 2017
    Posts:
    3
    Hey @LouskRad great work on the asset, GPUI was a big help on my project and this crowd addon seems to work pretty well.

    I'm having issues with some strange results when using colour variations on crowd prefabs. The context is I want to randomise the skin and some clothing colours on NPC's, which seems like the perfect use case for your StructuredBuffer variation system. Unfortunately it looks like my colours are being washed out/changed at some point in the process which is leading to incorrect results.

    To isolate the problem I've removed everything in the shaders apart from the raw colour value. In the attached screenshot all three characters are using the same skin colour, but the middle character is running via GPUI and the other two are using regular skinned meshes. The colour looks washed out and much lighter than it should be. I'm also using the same system on the red shirt the middle character is wearing - you can see the same non-GPUI material on the right character looks much more vibrant.

    Some steps I've taken:
    -Added a GetVariationData method the prefab manager and confirmed that the colour values match up (they do)
    -Confirmed that the Variation system seems to work ok for non crowd meshes (the colour change demo in regular GPUI still works fine with accurate colour reproduction)

    This is the skin shader being used for the GPUI character:
    Code (CSharp):
    1. SubShader
    2.     {
    3.         Tags{ "RenderType" = "Opaque"  "Queue" = "Geometry+0" "IsEmissive" = "true"  }
    4.         Cull Back
    5.         CGPROGRAM
    6.         #include "UnityCG.cginc"
    7.         #include "./../../Third Party/GPUInstancer/Shaders/Include/GPUInstancerInclude.cginc"
    8.         #pragma instancing_options procedural:setupGPUI
    9.         #pragma multi_compile_instancing
    10.         #include "../../Third Party/GPUInstancer-CrowdAnimations/Shaders/Include/GPUICrowdInclude.cginc"
    11.  
    12.         #pragma multi_compile _ GPUI_CA_BINDPOSEOFFSET
    13.        
    14.         #pragma target 3.0
    15.         #pragma surface surf Standard keepalpha addshadow fullforwardshadows
    16.         #pragma vertex vert
    17.  
    18.        
    19.         struct Input
    20.         {
    21.             float2 uv_texcoord;
    22.             float3 worldPos;
    23.         };
    24.  
    25.        
    26.         #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED      
    27.             StructuredBuffer<float4> colorBuffer;
    28.         #endif
    29.  
    30.         void surf( Input i , inout SurfaceOutputStandard o )
    31.         {
    32.             float4 color = (1,1,1,1);
    33.             #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    34.                 uint index = gpuiTransformationMatrix[unity_InstanceID];
    35.                 color = colorBuffer[index];
    36.             #endif
    37.  
    38.             o.Albedo = color.rgb;
    39.         }
    40.  
    41.         appdata_full vert(inout appdata_full v)
    42.         {
    43.             appdata_full o;
    44.             UNITY_SETUP_INSTANCE_ID(v);
    45.             GPUI_CROWD_VERTEX(v);
    46.             return o;
    47.         }
    48.  
    49.         ENDCG
    50.     }
    51.     Fallback "Diffuse"
    52.     CustomEditor "ASEMaterialInspector"
    And this is the shader being used on the regular skinned mesh character:
    Code (CSharp):
    1. Properties
    2.     {
    3.         _Color("Color", Color) = (1,1,1,1)
    4.     }
    5.  
    6.     SubShader
    7.     {
    8.         Tags{ "RenderType" = "Opaque"  "Queue" = "Geometry+0" "IsEmissive" = "true"  }
    9.         Cull Back
    10.         CGPROGRAM
    11.         #pragma target 3.0
    12.         #pragma surface surf Standard keepalpha addshadow fullforwardshadows
    13.         struct Input
    14.         {
    15.             float2 uv_texcoord;
    16.             float3 worldPos;
    17.         };
    18.  
    19.         uniform float4 _Color;
    20.  
    21.  
    22.         void surf( Input i , inout SurfaceOutputStandard o )
    23.         {
    24.  
    25.             o.Albedo = _Color.rgb;
    26.         }
    27.  
    28.         ENDCG
    29.     }
    30.     Fallback "Diffuse"
    31.     CustomEditor "ASEMaterialInspector"
    Any help would be appreciated!
     

    Attached Files:

  43. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,
    it looks like the shader has been setup correctly. Assuming you are sending the desired colors to this shader correctly, it might be an issue of Gamma vs. Linear color space. If this is the case, you can try adjusting for the color space with something similar to this:

    Code (CSharp):
    1. if (QualitySettings.activeColorSpace == ColorSpace.Linear)
    2. {
    3.                 defaultColor = defaultColor.linear;
    4. }
     
  44. JarrydFP

    JarrydFP

    Joined:
    Oct 6, 2017
    Posts:
    3
    Yep, it was a colour space issue. Thanks for the help!
     
  45. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    46
    Hi,
    With regards to working with Crowd Animator workflow I know that you have given us the API documentation page and the included demo scene, and you have stated:

    “Animation events are not supported with the Crowd Animator, however. Since the Crowd Animator works completely in the GPU, there are no callbacks to any CPU resources. Currently, to detect the end of an animation when using this workflow, you can track animation time.”

    Which seems fair enough. I was wondering if there will be any more API features added in the future to deal with play back of non looping animations, such as a single attack animation?

    What i am doing presently is some simple testing which looks like
    if (input==3 && !playingAttack)
    {
    playingAttack = true;
    GPUICrowdAPI.StartAnimation(pref, clip[3]); //attack
    StartCoroutine(CancelAttackAni());
    }

    IEnumerator CancelAttackAni()
    {
    yield return waitTime; //0.9f works best
    GPUICrowdAPI.StartAnimation(pref, clip[lastValidanimationLoop]);
    playingAttack = false;
    }

    Is there a better way to handle cases like these where you only want to play a single loop of a animation and then return?
     
  46. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,
    We are planning ways to handle cases like this, by either API methods or by some tool, simple component system, etc.

    As for a current solution, instance based coroutines such as your example would indeed work, but in terms of performance (if there are a lot of instances using the attack animation at the same time), it would be better to loop through your instances (that are running the attack animation) and start the previous animation for them in a single place (like a manager, as opposed to creating a coroutine per instance).

    For example:

    Code (CSharp):
    1.  
    2. // Instance
    3. if (input==3 && !playingAttack)
    4. {
    5.     playingAttack = true;
    6.     GPUICrowdAPI.StartAnimation(pref, clip[3]); //attack
    7.     MyManager.attackers.Add(pref);
    8.     MyManager.attackerTimes.Add(Time.time);
    9. }
    10.  
    11. // MyManager
    12. List<GPUICrowdPrefab> attackers = new List<GPUICrowdPrefab>();
    13. List<float> attackerTimes = new List<float>();
    14. void Update()
    15. {
    16.     float currentTime = Time.time;
    17.     int attackerCount = attackers.Count;
    18.    
    19.     for(int i = 0; i < attackerCount; i++)
    20.     {
    21.         if (attackerTimes[i] < currentTime - 0.9f)
    22.         {
    23.             GPUICrowdAPI.StartAnimation(attackers[i], clip[lastValidanimationLoop]);
    24.             attackers.RemoveAt(i);
    25.             attackerTimes.RemoveAt(i);
    26.             attackerCount--;
    27.             i--;
    28.         }
    29.     }
    30. }
    31.  
     
  47. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi everyone,

    I just wanted to let you know that the GPU Instancer team will be on a summer break until August 31st. We will be answering all the questions and support requests after the break.
     
  48. lodendsg

    lodendsg

    Joined:
    Sep 1, 2012
    Posts:
    181
    We are investigating solutions looking for something to fit our needs.
    Our project is aimed at Unity 2019, HDRP and we will be using DOTS/ECS heavily
    Our project calls for rendering thousands to 10s of thousands of RTS like units being 3D animated models
    Could GPU Instancer Crowd Animations help here?
    Can you tell us a bit more about how your handling instance rendering of animated meshes e.g. are you baking the meshes and swaping them out or baking the animations to a texture for use with a custom shader? ... or yet another approch?
     
  49. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    46
    Hello, I know that your on your summer break, but upon your return or for anyone else comming across this I have found a bug in the latest version of GPUI v1.2.2 and GPUIC v0.8.4 that is not present in GPUI v1.2.0 and GPUIC v0.8.2

    If you are using the crowd animator work flow, and have more then 1 GPUICrowdPref in the scene, only the first pref will animate, the second GPUICrowdPref in the scene will be frozen on its first frame.

    Also would it be possible to change the material of a GPUICrowdPrefab?
    Something akin to
    public static void ChangeMaterial(GPUInstancerManager manager, GPUInstancerPrototype prototype, Material material, int lodLevel = 0, int rendererIndex = 0, int subMeshIndex = 0)

    I understand that this may not be possible, but my use case is, i have a unit that the player can spawn, but i wish to allow the user to choose the color of the unit, i dont believe there is anyway currently to update the material of a CrowdPrefab at runTime. The only work around i can see for now is to create 8 GPUICrowdPrefab for each possible color. I know we can tint the CrowdPrefabs with the UpdateVariation buffer but this wouldn't look correct in this case.
     
    Last edited: Aug 8, 2019
  50. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    542
    Hi there,

    Crowd Animations does not do mesh swapping. Rather, the bone informations in the animations are baked into textures and handled with Compute Shaders at runtime to modify the vertices, resulting in the animation. This is built on top of the GPU Instancer, so all the culling and instancing features also are at work during this process.