Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] GPU Instancer - Crowd Animations

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

  1. LouskRad

    LouskRad

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

    Thank you for the feedback. We will fix this issue in the next update. For now, you can move the following line in the GPUICrowdManager.cs to solve the problem:

    Remove Line 425:
    425: _lastAnimateTime = Time.time;

    and add it after line 168:
    168 : }
    169: _lastAnimateTime = Time.time;
    170: base.LateUpdate(); // GPUI core rendering
    171: }

    As for the ChangeMaterial method, there is currently no implementation for this in the package, but we will look into this.
     
    Last edited: Sep 3, 2019
  2. Mimimi_Ramon

    Mimimi_Ramon

    Joined:
    Oct 5, 2017
    Posts:
    3
    Hey there,
    thank you for creating this package, it's working very well for us so far!
    But we are also having some issues. These are the ones that haven't been mentioned in this thread, as far as I know:

    1. The "transitionTime" parameter of the GPUICrowdAnimator.StartAnimation() function does not work. We fixed this by adding the following to line 78 of GPUICrowdAnimator.cs:
    Code (CSharp):
    1. newClipStartTimes[3] = currentClipStartTimes[2];
    2. newClipStartTimes[2] = currentClipStartTimes[1];
    3. newClipStartTimes[1] = currentClipStartTimes[0];

    2. Sometimes the crowd prototype assets and the crowd settings asset enter a weird state, where Unity thinks the associated script could not be compiled, even though there are no compiler errors. This causes runtime errors, because those assets can no longer be loaded. This usually only happens once per team member and can be fixed permanently by reimporting the GPUInstancer folders. I'm not entirely sure about this, but I think this happens because all the Crowd script files have the "#if GPU_INSTANCER" compiler directive at the top of the file. So during the initial import of the plugin in a teammembers unity project, the assets are imported before the flag is set, so the script files are empty. And I guess unity is still confused even once the script files are recompiled with the flag enabled.
    If my guess is correct, you could fix this by adding dummy classes for those assets for when the flag is not set.


    3. This is the only important issue for us: Blending looks very odd when the blended poses differ too much. Heres a gif of what I'm talking about:
    blending_issue_02.gif
    Please ignore the shrek colors, I'm experimenting with material variants. :)
    Notice how her right arm shrinks as the animations transition. Will this be fixed?
     
  3. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Hi, I know you mentioned about mobile support in the future but is this something definitely coming or, just a possibility?
    I need to know so that I can pre-plan stuff. If it's coming within 4-5 months timeframe, I definitely include it in the plan.
    Assuming that it's coming, what would be the minimum required spec?
    Many thanks!
     
  4. Elyaradine

    Elyaradine

    Joined:
    Aug 13, 2015
    Posts:
    27
    Picked this up to test for a game we're currently working on. I've had a brief look and like the tools, and does a lot of neat things that our in-house implementation hadn't been lacking. Some things we've been missing that'd make this more complete:

    - Cross-fade animations,
    - add events to animations, and
    - attach objects to a CrowdAnimator object, to avoid still having an active Animator. (I dunno -- perhaps there's a way to pick a specific vertex or triangle, so that transforms that apply to it get applied to an attached object?)

    We can implement all of these manually, but they're things that seem to be preventing the package from feeling fully-fledged. The rest is looking pretty great! Handing off a bunch of stuff to compute shaders looks pretty rad!
     
  5. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there, and thank you for your feedback.

    We will investigate issues 1 and 2 and add the necessary fixes to the package.

    For 3, we will investigate this issue also; however, it would help a lot if you can send us a sample package that shows this issue.
     
  6. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    the issue regarding mobile support is not one of implementation but rather one of performance. In comparison with the base GPUI package, Crowd Animations uses the GPU of the target platform even further with bone calculations, which could beat the purpose in low powered GPU systems such as mobile devices. We need to do further testing to answer your question, and we plan to start testing potential mobile strategies after CA is out of the BETA phase.
     
  7. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    and thanks for the feedback.

    If you mean animation transitions by "cross-fade animations", this is currently supported (up to 4 animations at a time).

    As for animation events and object attachment (in the crowd animator workflow), we are currently investigating potential implementations of these features, we will keep you updated.
     
  8. Elyaradine

    Elyaradine

    Joined:
    Aug 13, 2015
    Posts:
    27
    @LouskRad Oh great, thank you!

    I've been spawning things and being really impressed with how much I can throw at this! I've run into a snag, however -- for some reason I reach a cap of 10,000 and cannot spawn any more? In the demo I saw that there was a restriction to have 100 rows. Bypassing that restriction seems to cap the instance count at 10,900, after which there's massive lag.

    Can you tell me how to spawn even more instances? Is there a point at which additional instances becomes prohibitive or infeasible? (I realise this is likely dependent on hardware, but perhaps there's a maximum buffer size in the compute shaders or something?)

    [edit] It seems that animations loop regardless of what the "Loop Time" variable of the Animation Clips are. It would be useful if the vertex animation took that setting into account, and clamped their time instead of looping.
     
    Last edited: Sep 6, 2019
  9. sordidlist

    sordidlist

    Joined:
    Sep 2, 2012
    Posts:
    86
    I was working along and things were fine, then at one point I encountered this when I try to bake animation data and haven't been able to work around it:

    System.NullReferenceException: Object reference not set to an instance of an object
    at GPUInstancer.CrowdAnimations.GPUICrowdAnimationBaker.AnimationBakerStart () [0x002d4] in F:\Game\Assets\GPUInstancer-CrowdAnimations\Scripts\Editor\GPUICrowdAnimationBaker.cs:178

    I've deleted and re-imported the latest GPU Instancer and Crowd Animations plugins, but when I try to bake animations, it still fails. Unfortunately this log isn't enough info for me to debug it myself. Thanks for any tips!
     
  10. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Thanks!
    The Crowd Manager in the demo scene defines Extra Buffer Size to 10000, and initializes 900 initial instances - resulting in a 10900 cap. You can increase the slider there to increase this cap as well, but you can also use the API to manually register your instances instead of using the Auto. Add/Remove Instances feature without a limit.

    As for animation loop time, since Crowd Animator has no state machine, we decided that the default behavior would be better if animations were assumed to loop. We will look into adding an option to change this behavior.
     
    Elyaradine likes this.
  11. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Looks like the problem is related to a missing reference. Can you check the mesh references in your prefabs's skinned mesh renderer and make sure they exist?
     
  12. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    any plans to support for 2018.2.7f1? :)
     
  13. Simunek

    Simunek

    Joined:
    Jul 15, 2016
    Posts:
    49
    Hi, I have a problem, I did nothing much in my project and GPUIcrowd stopped working, the crowd manager compiles, project compiles, but randomizer cannot be loaded and I cannot add prototypes (people)

    I reimported asset and upgraded to the latest versions of GPUI and GPUcrowd... and suggestions? :/ GPUI looks fine. Thanks!
     
  14. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    CA currently works for versions 2017 LTS and up. However, we are officially supporting 2018.3 and up since we have plans to use new Unity features that can require a higher version. Also the Demo scenes are designed for the newer Unity versions.
     
  15. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    I have replied to your mail on this subject, can you please reply back with details of warning/errors.
     
  16. BartekSalata

    BartekSalata

    Joined:
    Jan 23, 2014
    Posts:
    8
    So I'm using 2019.2 with the LW render pipeline and most things are working so far... except for the LOD "test animation" button and the LOD in game button on the built in crow animations scenes (specifically, I'm playing around with the navmesh one). All of the custom shaders that come with the demo scenes fallback to the error purple shader. How would I go about converting them to work on the LWRP?

    I kind of learn by using the demos/examples and this is kinda killing me. I have to manually convert all the standard shaders to LWRP (which makes them show up normally) but any custom shader that came with the demo scenes are just borked...

    Also with regards to ASE, is there a node for it... kind of how there is a node for shadergraph? (note, I haven't looked into what that node is for... but wondering nonetheless if one like it exists for ASE).
     
    Last edited: Sep 19, 2019
  17. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    and thank you for your feedback.

    The Animations Test shader currently does not have an LWRP version. The reason why GPUI does not come with LWRP and HDRP shaders for its demos and extra tools is that the LWRP and HDRP shaders are currently under constant change by Unity. We are providing essential shaders for GPUI to work, however we will provide provide the demo and tool shaders when Unity stabilizes the SRP shaders.

    Also, there is currently no node for ASE for setting up the shader with Crowd Animations, but this is in our roadmap and we will add this feature in a future update.
     
  18. BartekSalata

    BartekSalata

    Joined:
    Jan 23, 2014
    Posts:
    8
    Understandable, but could you help me out with modifying the LOD view shader to work at least, its very helpful for visualizing and, unlike the demo scenes.... its kinda a good tool to have for any debugging/tweaking situation.

    Glad to hear it, and looking forward to this : )
     
  19. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    The LOD Debugger does not use a dedicated shader, but modifies the "_Color" property of the shader that the instances use for its effect.

    We will look into making this property parametric in the tool, so that you can use the color multiplier in your custom shaders instead of the "_Color" property. However, you can also modify the "_Color" strings (multiple) in GPUInstancerLODColorDebugger.cs to the property your shaders use for the same effect.
     
  20. BartekSalata

    BartekSalata

    Joined:
    Jan 23, 2014
    Posts:
    8
    OK cool... i just want to use the LWRP shader for it.. but it uses _BaseColor now
     
  21. Monil

    Monil

    Joined:
    Apr 24, 2012
    Posts:
    101
    Hello,
    I'm doing some tests on the animation events you've just implemented, how can I add a parameter (string, int, float, bool) to the function?
     
    Last edited: Sep 27, 2019
  22. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    currently event functions with parameters are not supported. We will look into adding parameters to the event function in a future update.
     
  23. Elyaradine

    Elyaradine

    Joined:
    Aug 13, 2015
    Posts:
    27
    Hi again!

    I started moving our internal animation system across to use Crowd Animations today. Here's a quick gif of it in action:


    In our existing system we've been using MaterialPropertyBlocks quite extensively, both for setting frame data for our animations (which, similar to your solution, were baked to textures), as well as allowing for other effects, like "getting electrocuted" or "burning up", etc.


    • Is there an existing way to do this at the moment? (i.e. have a material property that can have different values per instance. This might be for the life of the instane -- like some minor colour variation -- but might be major and change per frame -- like switching to an electrocuted state and back.)
    • I know I asked for this before, but it would be great if I could have animations optionally not loop, e.g. for things like death animations. (I'm currently considering working around it by having an event at the end of one animation to tell it to play another animation that has data that doesn't move, but it's not ideal.)
    • Being able to trigger events in animation is great! It seems to me that it would make sense to have these be settings under the prototype's settings themselves?
     
    Last edited: Oct 8, 2019
  24. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    you can take a look at the TextureVariationDemo we have added with the last update for an example of using variations with your crowd instances. The demo showcases texture variation, but you can adapt the same logic for using it with color variations. The fish in the demo use a single draw call:

    CA-Scr-MaterialVariations.png

    We are looking into no-loop animations in the Crowd Animator. For now, you can achieve this by setting the animation speed to zero at the end of your animation.

    As for the event settings location, thank you for your feedback. We will look into providing a custom editor for both these and the loop settings.
     
  25. Elyaradine

    Elyaradine

    Joined:
    Aug 13, 2015
    Posts:
    27
    Hi @LouskRad, thanks for your help!

    For some reason when I set the animation speed to zero at the end of the animation, I get some minor jittering going on.


    [edit] I've manually set the clip to a specific frame with the animation speed at zero, and that fixed that. I wonder if it was somehow between frames, so that it was alternating between one or another or something, but either way it's working now. Thanks anyway!

    [edit2] I've found that any vertex colours that are in my prefab mesh are lost in the instanced versions, so that if my shader relies on vertex colours those no longer work correctly. Is this a limitation in the instancing implementation, or can this be added?
     
    Last edited: Oct 11, 2019
  26. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Thanks for the feedback,
    There is a method called GenerateMeshWithUVs inside the GPUICrowdUtility class, which recreates the mesh before sending it to the GPU. You can add

    mesh.colors = originalMesh.colors;

    to that method to use your meshs' vertex colors. We will add this in the next update.
     
  27. Elyaradine

    Elyaradine

    Joined:
    Aug 13, 2015
    Posts:
    27
    Thanks again!

    --
    We've got a method for showing the outline of something that's been selected. We currently render the selected object using another camera with a shader that masks the object from the background, and then apply some blur-like post process to create the outline.

    We're currently using CommandBuffer.DrawRenderer() for drawing an individual thing (or group of things) to a different camera with a different material. Is there perhaps an easyish way to draw only a subset of meshes to another camera when they're being deformed with Crowd Animations?
     
  28. LouskRad

    LouskRad

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

    At this point I can't comment on an easy(ish) way to do this. We will look into providing an example on this.
     
  29. LordRobby

    LordRobby

    Joined:
    Apr 4, 2018
    Posts:
    3
    Hello,
    Nice product btw. :)
    I found out how everything works for what I need, except this one.
    How can I stop a CrowdAnimation at the end or don't let them loop, without changing the animation state?
    (For example, an attack or a dying animation)
     
  30. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    and thank you for your feedback.

    We are working on adding an option to disable looping for animations, which we aim to include with the next update.
     
  31. LordRobby

    LordRobby

    Joined:
    Apr 4, 2018
    Posts:
    3
    Hi,
    good to know. I think I can wait :)
     
  32. huntersteeger

    huntersteeger

    Joined:
    Dec 27, 2017
    Posts:
    19
    Can my instances have separate body textures?
     
  33. Elyaradine

    Elyaradine

    Joined:
    Aug 13, 2015
    Posts:
    27
    @huntersteeger In case this helps you, there's an example scene that has fish that use different textures, where you put all of the textures onto an atlas, and then offset the UV-coordinates per instance.
     
    huntersteeger likes this.
  34. Elyaradine

    Elyaradine

    Joined:
    Aug 13, 2015
    Posts:
    27
    Hi @LouskRad -- Is there support in the CrowdManager for prefabs that have submeshes (i.e. meshes that have multiple materials assigned)? When I naively added a mesh that had multiple materials, it seemed as if only one of the submeshes played its animation.
     
  35. jlreymendez

    jlreymendez

    Joined:
    Dec 11, 2012
    Posts:
    5
    Hi, after moving a project to hdrp all my crowd instances have become invisible. From the error message I see in the crowd manager and in this forum it seems to be that there are no hdrp shaders provided in the asset. Is this the case? Or am I missing something? If so, any estimates on when the asset will support hdrp?

    Thanks!
     
    Beennn likes this.
  36. boysenberry

    boysenberry

    Joined:
    Jul 28, 2014
    Posts:
    365
    I could not find anything when searching on this. Does this work with UMA 2 characters?
     
  37. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    Yes, GPUI supports submeshes. In fact the CrowdAnimationsDemoScene uses the ZomBear as an example and it has multiple materials assigned to its skinned mesh.

    If you're having trouble with this, you can send us a sample and we can investigate the skinned mesh to identify the problem.
     
    Elyaradine likes this.
  38. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    You are correct that there is no HDRP shader included in the package. We will look into providing an HDRP shader that is setup for CA in the near future.
     
    jlreymendez likes this.
  39. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    We haven't tested CA with UMA 2 yet. We will make some tests and announce the results.
     
  40. Arthur-LVGameDev

    Arthur-LVGameDev

    Joined:
    Mar 14, 2016
    Posts:
    228
    Great asset, it's really very well done from our usage thus far.

    We've got a couple of questions related to a few issues we're experiencing -- worth noting, we're using both the GPUI asset and the Crowd add-on asset, too.

    1) We're using a custom shader, along the lines of the variations sample; we have a few ComputeBuffers and TextureArrays to help us with variations. We're finding that the buffers are being 'flushed' after some undetermined amount of time, appears to occur only once, 8-9 seconds after startup. We are able to work around it by simply pushing our buffers again, on a hard-coded "delay" after startup, but it's pretty hacky and we'd love to figure out what's really going on & fix it.

    A) Any idea what's causing the buffers to be flushed?
    B) What's the proper way to retrieve the/all material(s) in use? We only have a single material (via texture arrays) but I suspect there's duplication happening or something along those lines, which might explain the issue we're seeing. Note we do handle the _GPUI duplication already -- but kind of guessing there's further complexity occuring that we may be missing & that might be causing this issue.

    Here's a bit more technical detail on this issue specifically:
    In the NoGameObject demo scene create a simple instanced shader with structured buffers and set them at Start. You can even see the colors being set for a moment before they are flushed again. Setting them in update works, but obviously that is not a valid solution, but it proves that the material instance is being accessed correctly. We are aware that GPUI creates instanced materials with "_GPUI" suffix, but we accounted for that. Aside from setting in update to make sure, we are also currently setting texture arrays at runtime (again, at the start). The peculiar thing is that although the Vector4 Array and structured buffers are flushed, the texture2DArray is not.
    Although in demo scene it happens instantly, basically at start and you can barely catch a glimpse of colors being set with a Vector4 structured buffer, in our scene with 2 prototypes they are flushed after 7-8 seconds. It might be because the prototypes are instanced (first ever drawn) 7 seconds after start, so there might be a correlation there.

    2) Multiple prototypes in one scene with animations of different clip.Length don't appear to work together correctly. One animation might work while the other freezes on a certain frame.

    Thank you -- and sincerely, really great product here. It's extremely rare to buy something on the asset store and find that the code is decent (much less good) -- it's really great to stumble upon an asset that not only does what it claims, but that also does it extremely well, with the underlying code being both well-written & optimized.

    Great job, and thank you!
     
    Last edited: Nov 4, 2019
    Elyaradine likes this.
  41. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi Arthur,
    and thank you for your detailed description and kind words.

    For (1), we have mostly seen buffer flushing issues like this, when there is a code that results in an error in the GPU - which sometimes causes the GPU to corrupt the buffer data. As for (2) we have not seen this in our tests, but the issue could be related to the specifics of the animations you are using.

    We would like to investigate these issues. It would help if you can send us a sample project that shows these two issues so we can determine the cause of the problem(s).
     
  42. Arthur-LVGameDev

    Arthur-LVGameDev

    Joined:
    Mar 14, 2016
    Posts:
    228
    I've just now sent over a minimal reproduction project for the second issue -- it reproduced pretty much immediately upon adding a second prototype. Let us know if any questions or anything we can do to help get it debugged & fixed! :)
     
    LouskRad likes this.
  43. LazyOnion

    LazyOnion

    Joined:
    Mar 6, 2018
    Posts:
    22
    Hey, awsome asset, literally opened me a new horizon on the project.

    I have a scene where I am animating a fleet of triremes and I was wondering what would you suggest to do with the animation of the oars? Should I convert them to skinned mesh renderers and use the crowd manager, or animate them by code and update the rotation on each oar through api calls?

    Editing:
    I 've managed to get the animations working with custom Update for 8704 oars and the fps is acceptable ~ 120 on a scene I was getting 250 before.

    Follow up question: Is there a way to get the active LOD lvl for an instanced prefab?
     
    Last edited: Nov 14, 2019
  44. LouskRad

    LouskRad

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

    depending on your project specifics, it might be better not to skin the oars. Simply animating them from code and updating the rotations of their GameObjects can work. You can then use a Prefab Manager with Auto. Update Transform data.

    While doing it this way, if your oars are not prefabs themselves, it might be good to use a Nested Prefabs strategy to make them GPUI prototypes.

    As for active LOD levels, there is no API call for it. These calculations are all done in the GPU, so the only way to get that info would be to read back from the GPU - but it would be very slow. If you want to have more control over your LODs, you can use your LODs as different prototypes and use the Min-Max distance setting instead. If you do this you can know which LOD is active by doing a simple distance check.
     
  45. Bigpete591

    Bigpete591

    Joined:
    May 7, 2013
    Posts:
    60
    Am I correct in assuming it's not possible to use a ragdoll when using the CrowdAnaimator and you'll have to use Mecanim?
     
    Last edited: Nov 18, 2019
  46. LouskRad

    LouskRad

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

    to clarify, ragdolls with CA is currently not supported.
     
  47. bence02

    bence02

    Joined:
    Nov 16, 2017
    Posts:
    9
    Hi,

    I need a little help. I use HDRP, but I can't code shaders, how should I modify HDRP shader to use this product, because today I bought the GPU Instancer + GPU Instancer Crowd Animation products, because I've read that same system options, so if GPU Instancer can work with HDRP, Crowd Animation can too.

    Can you help me some please? I stucked in my work, and I should go on.
     
  48. bence02

    bence02

    Joined:
    Nov 16, 2017
    Posts:
    9
    I checked, and I saw Shadergraph 4.x can work with GPU Instancer with integration package, does it works with Crowd Animation too? It would be great.
     
    Last edited: Dec 1, 2019
  49. LouskRad

    LouskRad

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

    We will update Crowd Animations with HDRP support in the next few days.

    The Shadergraph package was designed for specifically for GPUI base package, and for ShaderGraph 4.x. Since Unity does not support custom nodes with newer versions of ShaderGraph, we can't add this for Crowd Animations. We will do so when Unity provides a solution for this in the future.
     
  50. pdinklag

    pdinklag

    Joined:
    Jan 24, 2017
    Posts:
    150
    First off, thanks for this mighty tool! :)
    I have a sports audience that I used to realize with game objects, one per member. Now I am instancing the crowd using this tool and it's working very fine so far with the no-game-object workflow and also including color variants for different submeshes.

    I'm left facing one problem I can't seem to solve. In my game, there's what I call an "audience focus" point. It's a position in the scene that all crowd members should be facing. It's very expensive to rotate all members every frame, so before, I used Unity's visibility events and only rotated the visible members and only a select number of times per frame. Now, GPUI does not share (or even have) visibility information on the CPU, so I have to re-think this.

    Since I'm using custom shaders anyway, the idea I came up with is to make this focus position a global shader variable and rotate the crowd members' vertices right in the shader after animating them using GPUI. However, I can't get it to work. My shader code burns down to this:

    Code (csharp):
    1.  
    2. uniform float4 _AudienceFocus;
    3.  
    4. float4x4 yRotation(float a)
    5. {
    6.     float sina, cosa;
    7.     sincos(a, sina, cosa);
    8.     return float4x4(
    9.         cosa, 0, -sina, 0,
    10.            0, 1,     0, 0,
    11.         sina, 0,  cosa, 0,
    12.            0, 0,     0, 1);
    13. }
    14.  
    15. void processVert(inout appdata_full v, out Input o)
    16. {
    17.     GPUI_CROWD_VERTEX(v);
    18.  
    19.     // rotate towards focus
    20.     float3 localFocus = mul(unity_WorldToObject, _AudienceFocus.xyz).xyz;
    21.     float a = 0.5 * atan2(localFocus.x, localFocus.z);
    22.     float4x4 rotM = yRotation(a);
    23.  
    24.     v.vertex.xyz = mul(rotM, v.vertex.xyz);
    25.     v.normal.xyz = mul(rotM, v.normal.xyz);
    26.     v.tangent.xyz = mul(rotM, v.tangent.xyz);
    27.  
    28.     // do color variation
    29.     UNITY_INITIALIZE_OUTPUT(Input, o);
    30.  
    31.     o.uvcoord = v.texcoord;
    32.     #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    33.         o.color = getColor(gpui_InstanceID);
    34.     #else
    35.         o.color = _Color;
    36.     #endif
    37. }
    Using any fixed angle for yRotation works perfectly fine, e.g., if I hardcode a = UNITY_PI to do a 180 degree turn. However, as soon as I use the output of atan2 (which gives me the rotation angle relative to the forward Z direction), it breaks: all vertices disappear and I see no crowd members at all. Since it's nothing but a rotation, I don't really get it.

    First off, is it safe to use unity_WorldToObject here? I tried calling setupGPUI before but that didn't help, same effect. I know that the _AudienceFocus variable is set correctly and I also made sure atan2 can handle zero values properly. I don't really know how to debug this. Is vertices disappearing some kind of an error fallback, or what could be the issue here?

    EDIT:
    The issue with the crowd not showing at all seems to be if the focus point is the origin indeed.
    But I'm facing a different problem: apparently, unity_WorldToObject is the inverse transform of the crowd manager, not the individual member. Is there a way to get a member's transformation matrix? The shader must have it somewhere I'm sure?
     
    Last edited: Dec 10, 2019