Search Unity

[RELEASED] GPU Instancer

Discussion in 'Assets and Asset Store' started by LouskRad, May 3, 2018.

  1. zetingq

    zetingq

    Joined:
    Dec 8, 2016
    Posts:
    26
    Due to project reasons, we are still unable to upgrade the version, and now we want to check where the problem is

    Only after the project EXE file is imported into the packaged scene, the frame rate is low, and there is no Profiler in the EXE, how can I troubleshoot the problem, or is there any way to verify where the problem is?
     
  2. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    I can't say when the next update will be released yet. But you should be able to fix the problem by making the following change:
    GPUInstancerTreeManagerEditor.cs line 104
    from this:
    Code (CSharp):
    1. if (newPrefabObject != null)
    to this:
    Code (CSharp):
    1. if (newPrefabObject != null && PrefabUtility.GetPrefabInstanceStatus(prefabObject) == PrefabInstanceStatus.Connected)
    This change should allow you to add variants to the Tree Manager.

    I don't know how your setup works or what you mean by "project EXE file is imported into the packaged scene". I never used such a setup, so unfortunately I can not be of help.
     
    Mamoru_Suzuki likes this.
  3. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    Hello Gurhan,

    now my next problem is, that the billboard is not properly rendered.

    - using the vegetation engine (TVE 8)
    - TVE standard lit (deferred) shader
    - using gradient feature (so the texture of the tree is yellow, but the gradient is making it purple blended to cyan)
    - in TVE i have gpu instancer support activated for this shader(s)

    - unity 2021.3.14f1
    - GPU Instancer v1.7.5

    upload_2022-12-17_19-1-25.png

    what you can see directly is that to render the billboard neither the original leaves shader from TVE (with gradient) is used, nor (but you can not easily see it in this screenshot) is the bark shader used (nor any replacement from GPUinstancer) so that the billboards have no stem (bark material is also TVE standard lit deffered).

    what can i do to change this?

    TVE has many nice features, including seasons (snow, etc) and it makes not much sense to have these features only on the close instances and then the billboards revert to default settings.

    isnt it possible to use the original prefab material to render the billboard?

    i hope you have good news!
     
  4. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    GPUI's billboard is rendered from a texture using a generic shader with basic properties, so it can not have such features.
    You should ask the shader developer about how to use billboards without loosing these features. They might also have an alternative way of simplifying meshes.
     
  5. the_unity_saga

    the_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    273
    does GPU Instancer support animations with submeshes? I read through the topic,

    I am supposed to add all child sub-meshes as their own instance under a parent transform? Or what is the work flow for this if it is supported? I will run tests in the mean time, I just wanted to ask.
    Thanks again for your on-going support and hard work dev!!
     
  6. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    Thanks for your response Gurhan, I am not sure i understand:

    1. why are the meshes rendered in editor into the billboards once not just with the normal shader they have, instead with a basic one?
    2. where could i change this (add my own code), why would this fail? what are the difficulties?
    3. i dont want to use billboards or alternative ways of simplifying meshes, i am using gpu instancer because i render an open world with multiple thousands of instances that so far only GPU instancer can handle well. please help me find a way to reach this.
    4. i was expecting this to work, obviously only static, not dynamic updated billboards, as the preview image already looks correct:

    upload_2022-12-22_0-40-45.png

    this are white rocks, for snow landscape, the prototypes in the GPU instance Tree Manager are shown with icons, these icons properly have snow. the billboards then are only dark (base texture, i guess).

    or its again the bug i reported already (above) that sometimes they get rendered very dark?

    these are the rocks (foreground) and the billboards (background) have the proper shape but are just super dark upload_2022-12-22_0-44-17.png

    the billboards look like this (PNG)
    upload_2022-12-22_0-44-28.png

    i guess the whole shader can not be rendered, maybe has base albedo not on typical unity texture slot name and thus its just rgb 128,128,128 as a result?
     
  7. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    I am not sure what you mean by "animations with submeshes". But if you are using SkinnedMeshRenderer, you need the Crowd Animations extension pack. If you mean modifying position/rotation values of the child GameObjects with MeshRenderers under a prefab, you need to make them also prefabs and add them as a prototype to be able to modify their position/rotation values.

    1&2- We need to use an unlit replacement shader to create the textures. It is mainly got to do with lighting but I can not explain all the reasons in detail, it will take too long. I am sure there are various examples/tutorials on internet if you wish to be informed.
    3- You can use GPUI with other billboards or simplified meshes. For example you can use Amplify Impostors with GPUI. Or you can make your own mesh and material and enable the Use Custom Billboard option.

    upload_2022-12-22_21-42-15.png
    As this warning message also tells, GPUI's billboards are not designed to work with every shader. It is similar to how Unity terrain billboards work. If you need a more complex billboard system, you should use another tool or make your own to create your billboards.
     
  8. MicCode

    MicCode

    Joined:
    Nov 19, 2018
    Posts:
    59
    Hi GurhanH,
    I am following the GPUI compute buffer sample and using the API GetTransformDataBuffer() to have the compute shader to set the instance transform.
    Can I also set the variationBuffer of a prototype with a compute shader as well, I am asking since I don't find a similiar API for variation buffer.
    Right now, I'm using DefineAndAddVariationFromArray() and UpdateVariationFromArray() from the CPU
     
  9. w1467660943

    w1467660943

    Joined:
    Dec 27, 2021
    Posts:
    1
    屏幕截图 2022-12-24 124237.png I'm sorry, GPU Instancer doesn't seem to improve the game FPS significantly. The average frame rate is 100 frames, which is not in line with the surge frame rate you advertised. Even my game scene is only a few trees, grass and GODRays. My computer graphics card It is 1660ti, the frame rate cannot be so low, I followed the operation of the document to optimize, it seems that it still does not work, I hope you can answer
     
  10. OmnifariousStudios

    OmnifariousStudios

    Joined:
    Mar 12, 2018
    Posts:
    48
    Hello again!

    I've been playing with the Boid - Space script, but I can't seem to change or update the scale of the space ship instances at all.

    I've been trying the same methods that are in PrefabsWithoutGameObjects, but it's still not working. Is there a special way of handling these because they're using Compute Shaders?

    Here's the code I'm trying:

    Code (CSharp):
    1.         for (int i = 0; i < _spawnArray.Length; i++)
    2.         {
    3.             _spawnArray[i] = Matrix4x4.TRS(_spawnArray[i].GetColumn(3), _spawnArray[i].rotation, Vector3.one * spawnScale);
    4.         }
    5.        
    6.         print("Spawn Array Length: " + _spawnArray.Length);
    7.        
    8.  
    9.         GPUInstancerAPI.UpdateVisibilityBufferWithMatrix4x4Array(_prefabManager, prototype, _spawnArray, 0, 0, _spawnArray.Length);

    Thanks!
     
  11. OmnifariousStudios

    OmnifariousStudios

    Joined:
    Mar 12, 2018
    Posts:
    48
    As a follow-up question, what would be the best way to "fake" collisions with a boid controlled swarm? (Because obviously using that many colliders/rigidbodies would tank performance) I'm thinking one of these:

    1. Use several physics-controlled spheres that would move with the larger groups of the swarm to simulate collisions, and disable them when the swarm is broken up or too separated. But is there a performant way to find the largest groupings of the matrix positions that these spheres could follow?

    2. If I switched to using instances instead of the no-gameobject-workflow, could a variation of the asteroids demo work, where I de-instance some of the swarm instances when inside of a trigger collider to allow for collisions?

    Thank you!
     
  12. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    There is not an API for that currently, we will look into adding it in a future update. For now you can add a method to GPUInstancerPrefabManager.cs to get the buffer, like this:
    Code (CSharp):
    1. public ComputeBuffer GetVariationBuffer<T>(GPUInstancerPrefabPrototype prototype, string bufferName) where T : struct
    2. {
    3.     foreach (IPrefabVariationData item in _variationDataList)
    4.     {
    5.         if (item.GetPrototype() == prototype && item.GetBufferName() == bufferName && item is PrefabVariationData<T> data)
    6.             return data.variationBuffer;
    7.     }
    8.     Debug.LogError(prototype + " does not contain a variation buffer with name: " + bufferName);
    9.     return null;
    10. }
    Then access the buffer like this:
    Code (CSharp):
    1. myPrefabManager.GetVariationBuffer<Vector4>(myPrototype, "myBufferName");
    Hi there,
    Please see the Best Practices documentation to learn about best practices for using GPUI that will help you get better performance. And if there is an unexpected result, please email us a support request with a sample project following this guide.

    Hi there,
    I can not say for sure without seeing the complete implementation but the Boids demo has a custom Compute Shader that modifies the matrices. So if you are using a similar method, your matrix modifications would be overridden by the Compute Shader.
    See GPUIBoids.compute line 84:
    boidsData[id.x] = TRS(currentPosition, newRotation, vector3One);

    Fastest method would depend on your requirements. For example if you don't need to access the transform data on the CPU, then Compute Shaders would be faster. If you need the data, then possibly using Jobs and Burst. But GPUI is not a physics solution and this is out of scope for this forum. It would be better to ask it on another platform/forum where more people with experience in such matters could see. You might also find various examples on GitHub that can be beneficial.
     
    MicCode likes this.
  13. MicCode

    MicCode

    Joined:
    Nov 19, 2018
    Posts:
    59
    Thank you for the response, this is just what I needed
    Another question: Is it possible to set per instance render bound data?
    I'm rendering bezier curved model by changing vertex position in the shader.
    I can render them properly by setting the bound to the max size the curve can take.
    Just wondering if there is a way to have tighter bound that fit per instance for better culling.
     
  14. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
  15. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    There is the Bounds Size Offset setting which adds the given value to the prototype bounds. So positive values will increase and negative values will reduce the size of the bounds.

    Yes, please see the demo scenes under GPUInstancer-CrowdAnimations/Demos.
     
    Abbrew likes this.
  16. Liam2349

    Liam2349

    Joined:
    Mar 10, 2016
    Posts:
    81
    Hi, I would like to render a mesh with various materials, using a URP shader graph. I've noticed the UV mapping demo. Is there any other way of doing this? I'm using the API to add GPUInstancerPrefabs at runtime. Can I provide a material somehow?

    Right now I have e.g. floor prefabs, ceiling prefabs to work around this, but they are the same mesh.

    Thanks.
     
  17. kevinsyang17

    kevinsyang17

    Joined:
    Apr 3, 2018
    Posts:
    37
    Is there a way to define a prefab as prototype to the GPUIPrefabManager through code during editor time? I have a manager that holds an array of GameObjects, I want to make it easy to define them as prototypes and added to the GPUIPrefabManager during editor time.
     
  18. RolandParachuteUK

    RolandParachuteUK

    Joined:
    Mar 12, 2018
    Posts:
    1
    Hi, we recently moved to 2022.2 with URP 14(due to some fixes in URP) and noticed that as soon as Detail Manager is added Unity crashes. There are no issues with 2022.1 URP 13. We are using GPUInstancer 1.7.5, should be latest as of now. This is not a big issue right now as we are not at the stage where environment is populated but it would be nice if there was a fix or workaround for it.

    Here is a log just before the crash
    https://pastebin.com/DGHgPUTa

    Update: seems like the issue is coming from Forward+ which we were just testing at the time
     
    Last edited: Jan 5, 2023
  19. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    Another question from my side - i still see these strange "Dark" billboards, looks like HueVariation (but in lightness, not color). i commented out all HueVariation code until i found out it is this:

    BillBoard2DRendererTree_GPUI.shader
    LINE 86
    o.Albedo = lerp (c.rgb, float3(0,0,0), normalDepth.w);


    which takes the lerping percentage from


    GPUIBillboardInclude.cginc
    LINE 76
    half depth = max(normalTexture.w - 0.35, 0);


    what exactly is this originally supposed to do?
    why is it fading to black?
    what is stored inside the normalTexture fourth component, what kind of "depth" is that?

    ----

    and perhaps related, or not: what exactly is the slider of "Terrain Normal Effect" in GPU Instancer Detail Manager supposed todo? in which line(s) of code should i see the slider value reflected?
     
  20. kevinsyang17

    kevinsyang17

    Joined:
    Apr 3, 2018
    Posts:
    37
    Is there a way to use GPUI shadow shader for URP, we need to turn off vertex animation for shadows. Also, Billboard replace on LOD doesn't work on URP? Our LOD is culled at 15%, and turned on use billboard and replace cull with billboard on GPUIPrefabManager, and Billboards are generated and can be showed from Show Billboard in GPUIPrefabManager, but billboards don't render for culled, just nothing render when distance far.
     
  21. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    GPU instancing works by rendering the same mesh and material combination multiple times. So instances of the same prototype can not have different materials. So to keep the number of draw calls low, you need to use Material Variations to have different shader properties for instances.

    There are no API methods for this. It was not safe to have an API that would add/modify assets in the project and also tempt people to add prototypes in bulk which is not a good practice (see Best Practices).
    However if you wish, you can implement an editor script to add prototypes using the GPUInstancerPrefabManagerEditor.AddPickerObject method. Depending on your needs, you might need to make a modified version. But if you have issues when using this method, you need to solve it yourself since it is not a supported usage.

    Hi there,
    We did not fully tested 2022.2 yet, there might be some new Unity features that is incompattible. If you can reproduce the issue, please make a bug report following this guide and we can investigate.

    Hi there,
    I can not remember the purpose of each line of code most of which was written years ago. Even if I did, the answers will create more "why" questions and it is not possible for me to explain GPUI source code line by line.
    If there is an issue, please email us a bug report with a sample project following this guide and we can investigate.

    As for the "Terrain Normal Effect", you can see a description for each setting when you click on the "?" button at the top right corner of the manager. It changes how much the detail instances rotate based on the terrain normal. You can also call it alignment to terrain.

    GPUI does not have a custom shadow shader for URP. You need to modify your shaders shadow pass to simplify it.
    As for Replace Culled, it might be that the instances are culled by the Max Distance setting. If this is not the case, email us a bug report with a sample project following this guide and we can investigate.
     
  22. kevinsyang17

    kevinsyang17

    Joined:
    Apr 3, 2018
    Posts:
    37
    The GPUI Billboard shader seems keeps causing Value not found exception and it seems like it's not being included. Even if I add that shader to Graphics setting include section, the Shader.Find() called by GPUI still can't find the shader for some reason.

    And for some reason even though all billboards are generated, tried regenerating, even if I turn billboard cam distance very low, billboards still don't show up and still the mesh rendering on URP
     

    Attached Files:

    Last edited: Jan 13, 2023
  23. Erlend1

    Erlend1

    Joined:
    Dec 18, 2019
    Posts:
    22
    Hello, just started using GPU instancer and its optimization is great - really like the culling and that detail (grass) preserves original colors.

    I'm experiencing an issue with shadows, though. Some shadows in the distance seem to just pop in and out of existence instead of gradually fading.
    gpu-no-shadow.jpg
    gpu-shadow.jpg

    Any ideas as to why that is happening?

    Not sure if it means anything, but currently I'm testing it with the MapMagic 2 integration.

    Without the integration I experienced an issue where the GPUI Detail and Tree Managers constantly lost the reference to the mapmagic's main terrain.

    Edit: I have "Use Culling For Shadows" unticked. Is there potentially a way to let Unity handle shadows? Since those fade in and smoothly at a distance.

    I also discovered that the amount of shadow casters fell to 500 when I didn't include the trees in a manager vs. 700 when I included them (when I use four cascading shadows). Is there a way to reduce shadow casters within the prefab/tree manager, except from disabling shadows altogether?
     
    Last edited: Jan 12, 2023
  24. Erlend1

    Erlend1

    Joined:
    Dec 18, 2019
    Posts:
    22
    A few more questions:

    1. is what's the difference (or pros and cons) of using the Tree Manager over a Prefab Manager?

    2.I use NatureManufacture trees from the Mountain Environment asset. Also, these already have billboards, so should I disable billboard generation for those?

    Update: With the MapMagic 2 integration, it seems like a Prefab and Tree Manager is created and added to the hierarchy on "Play", and billboards are generated even if I've ticked off "Generate billboards" from the MM2 integration window.

    3. The handy thing about these windows is that they show instance and draw counts... Does it matter performance-wise to have the trees on both a Prefab and Tree Manager?

    4. Not a question, but the MapMagic 2 integration window doesn't support multi-selection of prefabs, while the standard Prefab/Detail/Tree Manager windows do.
     
    Last edited: Jan 12, 2023
  25. desukarhu

    desukarhu

    Joined:
    Jun 14, 2017
    Posts:
    27
    Hey, I'm getting this error with GPUI Detail Manager when enabling "Simulate at Scene Camera" or when entering playmode:

    Code (CSharp):
    1. [Exception] ArgumentException: The total size of the compute buffer (8112981312 bytes) exceeds the maximum buffer size. Maximum supported buffer size: 2147483648 bytes.
    2. UnityEngine.ComputeBuffer..ctor() at <bdd20210bb844b2e88e1149ea99da5ef>:0
    3.  
    4. UnityEngine.ComputeBuffer..ctor() at <bdd20210bb844b2e88e1149ea99da5ef>:0
    5.  
    6. GPUInstancerDetailManager.GetComputeBufferForDetailPrototypeWithComputeShader() at /GPUInstancer/Scripts/GPUInstancerDetailManager.cs:539
    7.  
    8. GPUInstancerDetailManager+<MergeVisibilityBufferFromActiveCellsCoroutine>d__27.MoveNext() at /GPUInstancer/Scripts/GPUInstancerDetailManager.cs:762
    9.  
    10. GPUInstancerDetailManager.StartCoroutineAlt() at /GPUInstancer/Scripts/GPUInstancerDetailManager.cs:586
    11.  
    12. GPUInstancerDetailManager.UpdateSpatialPartitioningCells() at /GPUInstancer/Scripts/GPUInstancerDetailManager.cs:177
    13.  
    14. GPUInstancerManager.UpdateBuffers() at /GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:588
    15.  
    16. GPUInstancerEditorSimulator.CameraOnBeginRenderingSRP() at /GPUInstancer/Scripts/GPUInstancerEditorSimulator.cs:180
    17.  
    18. RenderPipelineManager.BeginContextRendering() at <bdd20210bb844b2e88e1149ea99da5ef>:0
    19.  
    20. RenderPipeline.BeginContextRendering() at <bdd20210bb844b2e88e1149ea99da5ef>:0
    21.  
    22. UniversalRenderPipeline.Render() at Library/PackageCache/com.unity.render-pipelines.universal@14.0.4/Runtime/UniversalRenderPipeline.cs:287
    23.  
    24. RenderPipeline.InternalRender() at <bdd20210bb844b2e88e1149ea99da5ef>:0
    25.  
    26. RenderPipelineManager.DoRenderLoop_Internal() at <bdd20210bb844b2e88e1149ea99da5ef>:0
    27.  
    28. GUIUtility.ProcessEvent()
    29.  
    What could cause this? I'm using MicroVerse to place the terrain details and using TVE shader. Unity 2022.2 and URP 14.

    Edit: Went back to my 2021.3 LTS and works perfectly.
     
    Last edited: Jan 13, 2023
  26. Secuoya_Nexus

    Secuoya_Nexus

    Joined:
    Aug 27, 2020
    Posts:
    2
    Hi GurhanH, is there a way to multiply Grass Density above 1 without modifying terrain data? It's a feature I saw in others grass instancers and it'd be really cool in here too since gass placement is procedural.

    Thanks
     
  27. CitrioN

    CitrioN

    Joined:
    Oct 6, 2016
    Posts:
    98
    Hello,

    I would like to know if there is any downside using GPU Instancer for low instance counts?
    In my particular project I can not use static or dynamic batching because my entire world is generated at runtime and all objects are dynamic. Is there any difference in (rendering) performance to be expected if I simply use GPU Instancer on all my objects/props etc compared to using the default rendering or even Unity's built-in GPU instancing? I know that in the docs it is not recommended to use it for lower instance counts but would it actually hurt in any way if I can't fall back on any other performance optimization anyway in my scenario? Wouldn't it be benefitial to have access to GPU Instancer's occlusion culling even for lower instance counts?

    Thanks
     
  28. Secuoya_Nexus

    Secuoya_Nexus

    Joined:
    Aug 27, 2020
    Posts:
    2
    Hi GurhanH, is there a way to combine shadow distance and culling in an additive way? That is, to have a radius of minimum distance where the tree shadows should always be calculated with no culling, then an outer maximum radius where the culled trees don't cast shadows, only the visible ones.

    Thanks
     
  29. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    I am not sure, but possibly some files are might have been removed/moved/modified. Try reimporting the GPU Instancer from Package Manager and also select Tools -> GPU Instancer -> Reimport Packages from the top menu and see if it solves the issue. If it does not help, please email us a bug report following this guide.

    Hi there,
    By default GPUI culls shadows for objects that are farther away than the shadow distance setting. So depending on the directional light angle and the objects size this might cause popping. To solve it, please enable the Use Custom Shadow Distance setting and set a high number.

    1. Rendering performance is the same for both managers. However Tree Manager works without GameObjects and the colliders are managed by the terrain. So it will be more optimized physics and memory wise.
    2. In most cases it is better to use the native billboards if there is one instead of GPUI's generated billboards.
    3. Managers make draw calls individually, so if you have the same prefab on both Tree Manager and Prefab Manager, each will make their own draw calls. Fewer draw calls will be better for performance.
    4. Thank you for the feedback. We will look into it.

    Hi there,
    The issue is possibly caused when the Detail Scatter Mode is set to "Coverage Mode" under Terrain Settings. This is a new feature in Unity and it is not supported by GPUI. You can set this setting to "Instance Count Mode" to fix the issue.

    Hi there,
    Density setting currently designed for only reducing the amount of instances. It can not work to increase the number of instances mainly because the buffer size is predetermined based on the detail map data so there would be insufficient memory allocation.

    Hi there,
    Having a lot of prototypes with low instance counts will have an adverse affect on performance. It is better to test and determine a minimum instance count to start using GPUI. Occlusion culling in most cases will not be beneficial with low instance counts.

    Hi there,
    There is no such feature. You would need to modify the Compute Shader to make it. See the GPUInstancer/Resources/Compute/Include/Camera.hlsl line 26 for a starting point.
     
  30. Rastapastor

    Rastapastor

    Joined:
    Jan 12, 2013
    Posts:
    589
    Do You guys get crash on Unity when adding tree manager in 2022.2.2 URP ? I use TVE(8.1 with URP 14 support) shaders for trees and wanted to add GPUI but Unity crashes each time.

    On empty scene it crashs each time i drop tree into the slot of tree manager.
     
  31. Rastapastor

    Rastapastor

    Joined:
    Jan 12, 2013
    Posts:
    589
    Also dunno if its Unity shenanigans or its GPUI thing, but minor QoL would be to be able to change multiple GPUI Detail managers setting at once...since I noticed for isntance detail render range only changes on one last selected detail manager (when working with terrain slices).

    If its possible can we have global detail manager with exposed params that updaes on all detaill managers on scene?
     
  32. Gabe851

    Gabe851

    Joined:
    May 13, 2017
    Posts:
    32
    Hello, I am using the crowd manager to display large numbers of animating instances (soldiers in a large wargame) and I would like the ability to toggle their culling manually (as is done automatically with occlusion) to implement some concealment type mechanics (ie if in the right terrain or behind a hill etc.. you cannot see them). The functionality you get with the occlusion culling would basically work for this (except also turning shadows off), but how can I manually call that on an instance? Like turning this on from script:

     
  33. shi946

    shi946

    Joined:
    Jun 3, 2019
    Posts:
    16
    I'm diggin the no-GameObject workflow + Burst. Seeing a 20X+ improvement for fully dynamic objects with colliders (city traffic). One question - scriptX has:

    public prototypeX;
    Start():
    GPUInstancerAPI.RegisterPrefabInstanceList(prefabManager, prefabset1);
    GPUInstancerAPI.InitializeGPUInstancer(prefabManager);
    GPUInstancerAPI.InitializeWithMatrix4x4Array(prefabManager, prototypeX, _matrix4x4Array.ToArray());
    Update():
    GPUInstancerAPI.UpdateVisibilityBufferWithMatrix4x4Array(prefabManager, prototypeX, _matrix4x4Array.ToArray());

    When I use multiple copies of scriptX, I get "Can not find runtime data for prototype: prototypeX" error in the update loop for the second, third, etc. scripts, where prototypeX is different for each script. Is there a way around this? Do I need to call InitializeGPUInstancer only once or something?

    I would prefer not having to put everything into one script to avoid recoding a ton of my Jobs...
     
    Last edited: Jan 30, 2023
  34. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    We did not receive crash reports from other users. It might be a Unity bug. If you can email us a sample project we can investigate.

    Detail Managers work independently and the editor does not allow multi-editing. However I shared an example script on this post a while ago for a similar need that might be of help.

    Hi there,
    You can use the AddPrefabInstance/RemovePrefabInstance or DisableIntancingForInstance/EnableInstancingForInstance API methods to show/hide instances. Make sure to set the setRenderersEnabled parameter to false so that the Unity renderers are not enabled.

    Hi there,
    RegisterPrefabInstanceList method is used for prefab instances in the scene, so it is not a No-GameObject method. You can not use the same prototype with both prefab instances and with no-GameObjects.
    Secondly, if you are using No-GameObjects, InitializeWithMatrix4x4Array does the initialization, so you do not need to call InitializeGPUInstancer method.
    Also it is not a good practice to call InitializeGPUInstancer method multiple times. You can call RegisterPrefabInstanceList and InitializeGPUInstancer method only once for all your instances, which would be much faster.
    Please see the PrefabsWithoutGameObjects demo for an example usage.
     
  35. Gabe851

    Gabe851

    Joined:
    May 13, 2017
    Posts:
    32
    Thanks! that worked for me. Would there also be a way to fade the instances in and out rather than automatically turning them on or off? Would I need a custom shader that increased/decreased opacity of the material over time?
     
  36. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Hello, I'd like to use the No-GameObject flow while still being able to paint Trees and Details over a Terrain. More specifically, I'd like to be able to see them in the Editor after they've been placed, even though at runtime the GameObject representation will be discarded while GPUI renders it with lower-level API calls. I'm not sure what the most hassle-free way of setting this up is. Right now here's what I've got:
    A prefab GameObject with just the MeshRenderer called "Boulder Visual"
    A prefab variant of "Boulder Visual" that was registered by GPUInstancer called "Boulder GPUI"
    A prefab called "Boulder Spawner" to which a script called "GPUI Spawner" is attached. This script will spawn the "Boulder GPUI" prefab variant using InitializeWithMAtrix4x4Array.
    A prefab called "Boulder" which contains "Boulder Visual" and "Boulder Spawner" as child gameobjects. "Boulder" will be painted onto the terrain as a Detail.

    The goal is to
    1. See what's being placed in the Editor
    2. Make sure that the MAnager doesn't register what's placed at runtime since I'm going for a No-GameObject Flow.
    3. Any changes to "Boulder Visual" is gracefully reflected in "Boulder GPUI" and in turn "Boulder Spawner"

    Is this the best way to go, or is there another way?
     
  37. MarcGFJ

    MarcGFJ

    Joined:
    May 16, 2019
    Posts:
    24
    Hello,
    We use GPUInstancer for a lot of things in our game, and in the profiler, we noticed on our target min-spec machine (GTX 760) that a lot of time (5.3 ms) was spent in `GPUInstancerPrefabManager.LateUpdate()` doing compute dispatches followed by many `MemoryManager.FallbackAllocation`:
    upload_2023-2-2_17-35-14.png

    upload_2023-2-2_17-36-17.png

    We had 234 prototypes during that test. Is this impact unexpected? Or do we really have to reduce the number of prototypes somehow?
    a large part of these prototypes are dynamically created in game so it's not easy to just change rendering method ahead of time.
     
    Last edited: Feb 3, 2023
  38. Gabe851

    Gabe851

    Joined:
    May 13, 2017
    Posts:
    32
    Hello, I have an additional question about crowd managed animating instanced models. Say I have human models that look like this, with separate skinned mesh renderers for different parts (ie heady, arms, body, legs, etc...), where all but one of each option is turned off for any given model (see the hierarchy on the right). (I am currently instancing these after baking them all into one mesh):


    If I were to turn on all possible options the model looks like this:

    And here's an example of just different options selected just to give an idea of potential variation in appearance of the same unit type e.g. spearman (see what is bold and what is greyed out in the hierarchy):

    My question is, because (I think...) the instancer relies on a single mesh, would there be a way to say instance this one model with all meshes turned on at once, so it can use one prototype for all variations, and then on a given soldier turn off all but one of each type (ie so it has one randomly selected head, legs, arms, etc...) so that the models in one unit all have some visual variation, but are benefitting from all being the same instanced prototype? Would this be similar to how to use a socket to switch out a weapon?

    And, on that last point, which part of the API would I use just to swap out a weapon for an instanced model? Similar to the above?

    Thanks!
     
  39. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    There is not a built-in fade in/out system. So you would need a custom solution like a special shader.

    Hi there,
    There are only a few methods you can use for the no-GO workflow, so there are not many different options there and I can not say much about specifics of your application.
    Also if you ever need to use GPUI in edit mode, you can use the StartEditorSimulation/StopEditorSimulation API methods.

    Hi there,
    We do not recommend rendering all the objects with GPUI. It is best to keep the prototype count low while rendering only the objects with high instance counts with GPUI. Please see Best Practices for more information.

    Hi there,
    There is a setting called Has Optional Renderers which allows you to enable/disable various child skinned meshes at runtime. There is also a demo scene in the package called OptionalRenderersDemo which exemplifies this.
     
  40. unity_4EA6FC13EF4E95E76A1B

    unity_4EA6FC13EF4E95E76A1B

    Joined:
    Jan 18, 2023
    Posts:
    3
    On an empty scene using 2020.3.34f1, if I add a GPUInstancerPrefabManager and press Play I get an error VALUE CANNOT BE NULL. The registeredPrefab "rpd" has a null prefabPrototype. But how is this possible I have no registered prefab. It's an empty scene. I clicked "Register Instances in Scene" to Clear() the list but it still thinks there's 1 stuck inside somehow. What gives?

    upload_2023-2-6_14-2-37.png

    if I Debug.Log() the count of the registeredPrefabs, it's zero. But at runtime it turns into 1. This is a new blank scene. ????
     
    Last edited: Feb 6, 2023
  41. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Thank you. That appears to be a static method that accepts just the manager. Does this mean I have to call InitializeWith4x4 array at Edit time, and then call StartEditorSimulation at Edit time to render the instances?
     
  42. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    90
    Getting this error as well. Ever since the latest update. Using Unity 2020.3.17f1.

    I added a prefab to the Prefab Manager even though there were none in the scene. Hit play and the error went away. Prefab Manager automatically removed the prototype (I guess because there were none in the scene?). Hit play again and still no error.
     
  43. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    I was not able to reproduce the issue, please let us know if you can find out how we can reproduce it on our side. If the issue continues, try deleting the Prefab Manager and then re-adding it to the scene. And if it does not help, please email us a bug report with a sample project following this guide so we can investigate.

    You first call the StartEditorSimulation and then the other initialize/update methods with an editor script. GPUI will start running editor updates for rendering in edit mode and it will stop when the StopEditorSimulation is called. See the attachment on this post for an example.
     
  44. Querke

    Querke

    Joined:
    Feb 21, 2013
    Posts:
    54
    Hello! It's soon been a year since my first post. Any update on this:
    Would it be possible to group all terrains into the same gameobject in the detail rendering component? I see that with the tree rendering component, the additional terrains is grouped under the same game object. This makes it much simpler to adjust settings. I got 32 terrain tiles and if I want to change a setting for my details, I have to do that change 32 times.
     
  45. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Looks perfect! Thank you
     
  46. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    is there a grass demo that runs on mobile? Anything I try with the grass demos do not display anything on my mobile device.

    Things that I would love to test on mobile:
    The Detail Instancing demo and the Add Modify Terrains Runtime. None will even load on mobile right now.

    Also, the documentation states that you need OpenglES 3.1. My Amazon Kindle Fire 7 has 3.1 and it does not display anything. Any ideas?
     
    Last edited: Feb 10, 2023
  47. Gabe851

    Gabe851

    Joined:
    May 13, 2017
    Posts:
    32
    Hi, thanks, this worked for me, but I'm having an issue where the crowd manager does not regenerate the optionally renderer-ed pieces on restart. When first loading the scene, it works fine like this:

    but then if I just restart the scene (ie click a button that just calls SceneManager.LoadScene(SceneManager.GetActiveScene().name)) then it ends up like this:

    and you can see in the game window their horsemen are gone and in the gpui crowd manager on the right the extra auto generated body part prototype prefabs are gone as well. The correct child meshes are still active game objects, but the instancing of them is gone. Do you know what would cause that?
     
  48. Gabe851

    Gabe851

    Joined:
    May 13, 2017
    Posts:
    32
    as a followup, i think this may be a bug with optional renderers? I hesitate to say that, but I added a restart button to your optionalrenderersdemoscene that just calls:
    Code (CSharp):
    1. public void RestartGame()
    2.     {
    3.         SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    4.         Time.timeScale = 1.0f;
    5.     }
    and it has the same result, all the optional renderers are lost:
    from this:

    https://imgur.com/58EeTHt
    to this:
    https://imgur.com/WfPwT56
     
  49. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    We are aware of the discomfort but we are not planning to modify the current Detail Manager since it is designed to work with one terrain and can not be easily changed. However we are working on a new system that among other things will also allow using one detail manager for multiple terrains, but it is in development.
    I recommend using simple scripts to copy settings between managers. For example, if you are using the same prototypes in multiple terrains, you can use this example script to copy prototypes between multiple detail managers. If you need help to create a script suitable for your use case, email us the details of your use case and I will help.

    Hi there,
    The Detail Instancing demo and the Add Modify Terrains Runtime demos are not suitable for mobile devices. You need to be considerate of the amount of instances/geometry when using mobile. The Detail Instancing demo has over half a million instances, which would not run on most mid/low end devices.
    Please also note that the device you are testing with has a low end GPU that you will run into limitations such as buffer size limits, memory limits etc. We recommend using GPUI with devices which has at least a mid range GPU since GPUI relies on the GPU for its operations.

    Hi there,
    and thank you for reporting the issue.
    I was able to reproduce the problem and find the source. The manager sees that it already generated the prototypes for optional renderers but the reload resets the prototypeList.
    You can solve it by adding the following code to GPUICrowdManager.cs at line 128:
    Code (CSharp):
    1. else if (smd.isOptional && smd.optionalPrototype != null && !prototypeList.Contains(smd.optionalPrototype))
    2. {
    3.     prototypeList.Add(smd.optionalPrototype);
    4.     prefabList.Add(smd.optionalPrototype.prefabObject);
    5. }
    So it should look like this:
    Code (CSharp):
    1. if (smd.isOptional && !smd.isOptionalPrototypeGenerated)
    2. {
    3.     foreach (SkinnedMeshRenderer skinnedMeshRenderer in skinnedMeshRenderers)
    4.     {
    5.         ...
    6.     }
    7. }
    8. else if (smd.isOptional && smd.optionalPrototype != null && !prototypeList.Contains(smd.optionalPrototype))
    9. {
    10.     prototypeList.Add(smd.optionalPrototype);
    11.     prefabList.Add(smd.optionalPrototype.prefabObject);
    12. }
     
  50. Gabe851

    Gabe851

    Joined:
    May 13, 2017
    Posts:
    32
    thanks so much!