Search Unity

[RELEASED] GPU Instancer

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

  1. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    157
    Correct, because they are seperate products. Thanks, I have yet ot buy and will buy it in a week I think. A student
     
    LouskRad likes this.
  2. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    212
    Hi can you send me an example code of how to instantiate a prefab with the GPUInstancer Prefab manager.

    I am looking at the asteroid code and it is a little bit too complicated for me. Just show me how to instantiate any prefab through code using the GPU Prefab manager. thanks.
     
  3. LouskRad

    LouskRad

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

    I have sent you a code snippet by mail, but I will drop it here as well in case it helps anyone else.

    The simple c# script below shows how to use the GPU Instancer prefab manager with the objects you instantiate from code at runtime. You will find detailed comments in it that describe each step.

    To use this,

    (1) Add a prefab manager to your scene (GPU Instancer -> Add Prefab Manager)
    (2) Add the prefab you want to instantiate as such by dragging and dropping it from the project folder (not scene hierarchy) to the prefab manager (the "Add" field).
    (3) Add an empty game object to the scene and assign the attached script to it.
    (4) To the scripts's field in the inspector, assign the prefab from the project folder and the prefab manager from the scene hierarchy.

    That's all, you can now run and see the results.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using GPUInstancer; // important: allows access the the GPU Instancer namespace
    3. using UnityEngine;
    4.  
    5. public class SimpleInstantiationExample : MonoBehaviour
    6. {
    7.     public GPUInstancerPrefab prefab; // the prefab of the game object that that will be instantiated.
    8.                                       // This game object's prefab must be defined in an existing prefab manager in the scene.
    9.                                       // Assign it from the editor inspector window.
    10.  
    11.     public GPUInstancerPrefabManager prefabManager; // The refence to the prefab manager in the scene (must be enabled).
    12.                                                     // Assign it from the editor inspector window.
    13.  
    14.     public int instances = 10000; // the amount of instances you want to instantiate.
    15.  
    16.     void Start()
    17.     {
    18.         // Define a list of game objects you want to initialize with the prefab manager.
    19.         List<GPUInstancerPrefab> goList = new List<GPUInstancerPrefab>();
    20.  
    21.         // Your instantiation logic.
    22.         // This example just instantiates objects at random positions inside a sphere with radius of 50;
    23.         // Replace this with how you want to generate your instances. The important bit is to add them to the "goList".
    24.         for (int i = 0; i < instances; i++)
    25.         {
    26.             GPUInstancerPrefab prefabInstance = Instantiate(prefab);
    27.             prefabInstance.transform.localPosition = Random.insideUnitSphere * 50;
    28.             prefabInstance.transform.SetParent(transform);
    29.             goList.Add(prefabInstance);
    30.         }
    31.  
    32.         // The following is all the code that is necessary to use GPU Instancer with the game objects you have just instantiated
    33.         if (prefabManager != null && prefabManager.isActiveAndEnabled)
    34.         {
    35.             GPUInstancerAPI.RegisterPrefabInstanceList(prefabManager, goList); // Register the objects with the prefab manager.
    36.             GPUInstancerAPI.InitializeGPUInstancer(prefabManager); // Initialize the prefab manager
    37.         }
    38.     }
    39. }
    Please also note that you don't have to instantiate your objects from code. If you simply follow the steps (1) and (2) above, GPU Instancer will automatically work with the prefab's instances that are already in the scene.

    Also, for further info, you can check the video tutorials at:




    Especially the video titled "GPU Instancer Tutorial - Prefab Manager (Part 2) - Runtime Generated Instances" is relevant to instantiating objects from code to use with GPU Instancer.

    I hope this helps.
     
    OdderOtter, Akshara and Rowlan like this.
  4. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    If I use GPU Instancer, should I close unity's dynamic batching? Or they can work together (like all the registered prefabs will pass the dynamic batching but go into GPU Instancer instead, other unregistered prefabs can continue use unity's function)
     
  5. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    You can leave dynamic batching on. They can work together. As you said, GPU Instancer will take over rendering for the prefabs that are registered on it, and others will continue using dynamic batching.
     
  6. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    212
    Hi I tried going by your example and it gave me some idea.

    I am trying to instantiate prefabs on a planets surface.

    Here is the code that instantiates the prefabs.

    Code (CSharp):
    1. public void SpawnGPUPrefabs()
    2.         {
    3.             Vector3 position = transform.position;
    4.             Quaternion rotation = transform.rotation;
    5.             List<GPUInstancerPrefab> prefabList = new List<GPUInstancerPrefab>();
    6.  
    7.             if (prefabManager != null && prefabManager.isActiveAndEnabled)
    8.             {
    9.                 GPUInstancerAPI.RegisterPrefabInstanceList(prefabManager, prefabList); // Register the objects with the prefab manager.
    10.                 GPUInstancerAPI.InitializeGPUInstancer(prefabManager); // Initialize the prefab manager
    11.             }
    12.             for (int i = 0; i < gpuPrefabInstances.Count; i++)
    13.             {
    14.                 if (gpuPrefabInstances[i].posRots != null)
    15.                 {
    16.                     for (int j = 0; j < gpuPrefabInstances[i].posRots.Count; j++)
    17.                     {
    18.                         if (transform.rotation == Quaternion.identity)
    19.  
    20.  
    21.                             gpuPrefabInstances[i].gpuPrefab.gameObject.tag = "Objects";
    22.  
    23.                          prefabInstance = Instantiate(gpuPrefabInstances[i].gpuPrefab, gpuPrefabInstances[i].posRots[j].position + transform.position, gpuPrefabInstances[i].posRots[j].rotation * rotationX);
    24.                          prefabList.Add(prefabInstance);
    25.                     }
    26.                 }
    27.             }
    28.         }
    It instantiates the objects but is not working with GPU Instancer.

    Because I can see it is not registering under the GPU Instancer Prefab manager as counts for the instances.

    Any idea where I might be going wrong?
     
    Last edited: Jun 13, 2018
  7. LouskRad

    LouskRad

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

    The problem you have there is that you use the list before filling it. Try moving the GPU Instancer initialization code below your instantiation loop as such:

    Code (CSharp):
    1.  
    2. public void SpawnGPUPrefabs()
    3. {
    4.     Vector3 position = transform.position;
    5.     Quaternion rotation = transform.rotation;
    6.     List<GPUInstancerPrefab> prefabList = new List<GPUInstancerPrefab>();
    7.     for (int i = 0; i < gpuPrefabInstances.Count; i++)
    8.     {
    9.         if (gpuPrefabInstances[i].posRots != null)
    10.         {
    11.             for (int j = 0; j < gpuPrefabInstances[i].posRots.Count; j++)
    12.             {
    13.                 if (transform.rotation == Quaternion.identity)
    14.                     gpuPrefabInstances[i].gpuPrefab.gameObject.tag = "Objects";
    15.                 prefabInstance = Instantiate(gpuPrefabInstances[i].gpuPrefab, gpuPrefabInstances[i].posRots[j].position + transform.position, gpuPrefabInstances[i].posRots[j].rotation * rotationX);
    16.                 prefabList.Add(prefabInstance);
    17.             }
    18.         }
    19.     }
    20.     if (prefabManager != null && prefabManager.isActiveAndEnabled)
    21.     {
    22.         GPUInstancerAPI.RegisterPrefabInstanceList(prefabManager, prefabList); // Register the objects with the prefab manager.
    23.         GPUInstancerAPI.InitializeGPUInstancer(prefabManager); // Initialize the prefab manager
    24.     }
    25. }
    26.  
     
  8. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    212
    Hi yes I figured it out...fantastic asset my friend, I am getting 70 fps with thousands and thousands of rocks in my scene.

    When do you plan on implementing this with speedtree?
     
  9. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    212
    Also what is the max amount of prototypes you can have in the Prefab manager?
     
  10. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Thanks!

    SpeedTree integration will come soon with an update that adds support collectively for all Unity terrain supported tree types, but it's currently under development so I can't give you an exact date.

    There is no set limit to the amount of prototypes. You can add as many as you wish.
     
    Last edited: Jun 13, 2018
  11. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    This sounds pretty useful for my building system :)
    upload_2018-6-13_22-38-43.png
    Now I can let players build a whole village without frame dropping.
     
  12. FuzzyShan

    FuzzyShan

    Joined:
    Jul 30, 2012
    Posts:
    182
    Basically, what you are saying is that anything that uses Unity Terrain's stuff we can either go with your special terrain system or Vegetation Studio, where everything else can just use your prefab instancing... with this, are we in par with Unreal engine 4 regarding to vegations/rocks stuff?
     
  13. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Is this compatible with Unity 2018.1? Will this work with the Community Ocean Shader by further optimizing it?
     
  14. LouskRad

    LouskRad

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

    I'm not %100 sure if I understand your question; let me try to explain:

    If you mean UE4's Foliage Instanced Meshes, then yes, it would be fair to say that using GPU Instancer could bring the Unity terrains on par with how that system internally works. I'm not am expert, but as far as I know UE4 groups together certain batches of vegetation and instances each batch within a single draw call. If this is what you had in mind, we have a similiar approach for vegetation in GPU Instancer where we use partitioning over the unity terrain detail data and instance those partitions in groups. As opposed to UE4 however, we handle LODs in a per instance basis (instead of a per batch basis), so you can use LODed foliage as you normally would use LOD groups in Unity. Also, auto texture quadding allows you to use your grass textures as cross quadded meshes, I'm not sure if UE4 does this.

    Notice, however, that while doing this, GPU Instancer does not take over and replace Unity's terrain system - we only take over the rendering. What this means is that you use Unity terrains as you normally would (i.e. paint your details, using it's tools, etc.), and when you run the game, GPU Instancer uses the data from that terrain and renders the foliage with respect to the settings you defined in our Detail Manager. So if you disable the detail manager (can do this even at runtime), you would see that Unity takes back over its' terrain's rendering as if nothing changed.

    Also, I believe the prefab instancing part of GPU Instancer can be thought of similar tho what you have in UE4 as Hierarchical Instanced Static Meshes. Again, I'm no expert on UE4, but with GPU Instancer, all the culling operations and LOD switching, etc. are taken care of in the GPU.

    I'm not sure if I answered your question with this, but for further clarification on GPU Instancer I can direct you to this thread post.

    Also, the tutorial videos that are mentioned in the post you've quoted are now available and you can watch them from this link.
     
    FuzzyShan likes this.
  15. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi,

    Yes, GPU Instancer works with all Unity versions from 5.6 on including Unity 2018.1. You can use it with the Community Ocean Shader. It would work out of the box for static objects and improve the performance; but if you would like to use it for objects with the Buoyancy script, it wouldn't work out of the box since the Buoyancy script makes use of Rigidbodies in each update. You could still use GPU Instancer with them (by using our modification collider) but it would need some scripting on the Buoyancy script before it can work.
     
  16. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    I've got another question: if I've already registered a prefab into GPU instancer, but I'll need items around the player to be physical accurate, does GPU instancer have a function to auto deactivate the instancing around the player or it can only simulate the physics around player like what we can see in the asteroid demo?
     
  17. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi, Sure thing.

    For auto de-instancing, you can use the GPUInstancerModificationCollider the same way it's shown in the asteroid demo. How to use this is also demonstrated in this tutorial video. This component disables instancing for the objects that fall under its trigger collider. It will also add back any rigidbodies you had on the original prefab - so it's not a simulation but giving it back to Unity for physics.

    Note that you can also disable instancing per instance using the API methods DisableIntancingForInstance and
    EnableInstancingForInstance (http://www.gurbu.com/apidocumentation) - which will also hand the instance back to unity and take it back.
     
  18. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Ok, anything that uses Rigidbodies in each update will require additional scripting. Can you provide some info on how extensive the coding will need to be to make that work?

    By any chance, would you know if this will work with Voxels for Unity: Rasterizer? I got that tool but haven't gotten the chance to use it because it is so resource intensive. I plan to use this with that for a converted terrain mesh with a lot of voxel cubes.
     
  19. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi again,

    Yes, any script that makes use of rigidbodies each frame will require additional programming, but please note that if it will update rigidbodies each frame without any conditions (as is the case of the Buoyancy script), you would not see much of a performance increase. On the other hand, if you only want to use objects with rigidbodies as the camera gets near them, you do not need any extra scripting for it.

    As for the Voxels for Unity asset, I have not used it, but from the asset store description it looks like it does mesh combining for the assets that share the same materials behind the scenes. If this is the case, it would not be compatible with GPU Instancer since there would be no prefab instances you could instance.
     
  20. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Voxels for Unity converts a single mesh into a set of separate small meshes based on a predefined smaller single mesh that you want it to be made of (e.g. cube, cylinder, sphere). If needed, these meshes can then be converted into a prefab in the Editor. Alright, I think I get how GPU Instancer works now and will check if I can make use of it. I'm still comparing how it differs with World Streamer. But this one looks easier to implement. Thanks for your time!
     
    Last edited: Jun 16, 2018
  21. TCROC

    TCROC

    Joined:
    Aug 15, 2015
    Posts:
    230
    Hello I am very interested in this asset. I have a few questions tho:

    1.) Does this asset support multiple rigidbodies on the children within a prefab.

    2.) Does this asset support rigidbodies connected by joints? (I have plants that are connected by joints and rigged with bones. Hence the reason children have rigidbodies in the first question).

    3.) Does this asset support multiple cameras at once. My game will have a split screen feature.

    4.) Can you GPU instance prefabs that are children of other prefabs?
    ex.) Vegetation and animals on planets. I want to render the planets when looking at it from far away but only if it is in the camera's view. I want to render the vegetation and creatures that are children of the planet when I get close enough and if they are in the camera's view).
     
  22. LouskRad

    LouskRad

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

    GPU Instancer does not implement physics for the instanced objects. Currently, the way GPU Instancer allows for prefab instances with rigidbodies is by disabling instancing on the instances that you want to use rigidbodies on at a certain area. This is done either by using a collider that disables instancing (turning on rigidbodies) or by disabling instancing directly for some instances through our API.

    Multiple cameras are currently not supported since frustum and distance culling features work on a single camera setup. Different managers can be assigned different cameras, so you can use two cameras if you have different prototypes assigned for them - but you can't use a split screen setup where both cameras render the same objects.

    Prefab hierarchies are supported. GPU Instancer will handle all children in the hierarchy and take care of any transform offsets while rendering. The frustum and distance culling features also make it possible to render the instances when only in camera's view and at a viewing distance that you set.

    However, what you're asking also sounds similar to nested prefabs, and Unity hasn't still implemented a solution for this. If you make the planet (with all the animal and vegetation prefabs under it) a prefab, then you would loose the prefab references for those animals and vegetation. Also, please note that if the animals and creatures in your question use skinned mesh renderers, support for that is currently not available but will come later on with the 1.0 release.
     
  23. Akshara

    Akshara

    Joined:
    Apr 9, 2014
    Posts:
    100
    Just picked this up today. Wow on that VR demo... in the 100,000 scene, disabled was averaging 47ms or 11fps with a mountain range of red spikes in the SteamVR Frame Timing tool - while enabled went to 0.47ms with a calm rolling sea of green. That's crazy, man. I'd watched through the video tutorials first, yet that demo was extremely convincing. Wish that more asset developers would offer VR demos like this.

    Congratulations, gentlemen! This opens up so many possibilities, it's the kind of tool that makes me want to design for its unique capabilities. Thank you for creating this and for making this opportunity available.
     
    GurhanH and LouskRad like this.
  24. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Thanks a lot! Indeed, the whole project was done with the idea of improving performance and stability where it could be done. The plan for the next steps is to further improve this by implementing various other techniques such as hi-z occlusion culling, an imposter system, collider pooling, etc.)

    Your feedback means a lot to us, we're glad that you find GPU Instancer helpful :)
     
  25. ikemen_blueD

    ikemen_blueD

    Joined:
    Jan 19, 2013
    Posts:
    341
    any plans on GPU Skinned Mesh renderers yet? I found no productive solution for this yet, specially I really need this feature though :)
     
  26. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Skinned mesh support is scheduled for our 1.0 update. However, the other items on that list are scheduled for prior to the 1.0 update. We have working prototypes for all of these, but I cannot give you exact dates since feature update times also depend on testing results :)
     
  27. FuzzyShan

    FuzzyShan

    Joined:
    Jul 30, 2012
    Posts:
    182
    I downloaded this, i saw the shader implementation for gpu instancer, which is quiet simple, Is it possible to support these shaders in conjunction with HD render pipeline, both uses compute shader, which would make things look awesome and performance great.
     
  28. kyleshell

    kyleshell

    Joined:
    Jul 28, 2017
    Posts:
    10
    Hey, just wanted to drop this method of replacing tons of game objects with prefabs if anyone wants to speed up their work flow with this asset. This would namely be used for any pre-existing projects that haven't fully used a prefab method when creating their game, but need to in order to fully utilize this asset. Saved me several hours of manually replacing game objects, and should be a standard unity feature in my opinion. https://unity3d.college/2017/09/07/replace-gameobjects-or-prefabs-with-another-prefab/
     
    LouskRad likes this.
  29. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    It is possible to use SRP with GPU Instancer. SRP shader conversion is currently not automatic however, you can take a look at this forum post for an example of how you can modify your SRP shaders to work with GPU Instancer. This example is for the Light Weight pipeline, but it is the same principle if you want to use HDRP shaders.
     
  30. OP3NGL

    OP3NGL

    Joined:
    Dec 10, 2013
    Posts:
    267
    do u guys have performance specs for VR?
     
  31. LouskRad

    LouskRad

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

    We don't have a VR specific performance chart; but you can find a general one at this link. Also, if you want to test GPU Instancer in VR, you can download a demo build from this link.
     
  32. lolclol

    lolclol

    Joined:
    Jan 24, 2013
    Posts:
    212
    I want to see how this perform on open gl es 3.1 mobile device since i am interested to buy this awesome kit.

    Thanks
     
  33. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Thanks :)

    We currently don't have any android demo builds, but I will let you know when we upload one.
     
    Last edited: Jun 21, 2018
    lolclol likes this.
  34. lolclol

    lolclol

    Joined:
    Jan 24, 2013
    Posts:
    212
    IF you build an android demo for us please also provide us how you did it inside unity . oh boy i see sales in future if this runs at 30 fps on mobile devices. :D:cool::);)
     
  35. kyleshell

    kyleshell

    Joined:
    Jul 28, 2017
    Posts:
    10
    Hi, so I have just added asynchronous and additive scene loading and unloading into my project to split up my large scene into smaller scenes. I used the Additive Scene Manager asset (https://assetstore.unity.com/packages/tools/utilities/additive-scene-manager-73891) and was wondering if you think it is possible or reasonable to try to integrate GPU Instancer with this.

    Essentially, the asset is used to load entire scenes into the original scene in a single frame and without breaking any object positions or states, besides when it deletes entire zones that are far away from the player. I know I have to manually add, remove, and register the prefabs following this transition, but was wondering how this could work so that the prefabs are instanced into the right places, and with the least overhead.

    The asset has a setting to manually bake all of the scenes as if they're one scene if that matters at all. Another solution I was thinking might work is associating each scene with separate prefab managers that all function simultaneously and are disabled when the corresponding scene is deleted, if that's even possible. Just any advice on where to get started with allowing these two features to work simultaneously would be helpful.
     
    Last edited: Jun 21, 2018
  36. LouskRad

    LouskRad

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

    I do not know this asset, but you can use GPU Instancer with an additive scene setup. All you need to do is to register your prefab instances in a list that you serialize in the inspector for each additive scene. You can have a prefab manager in the first scene only, then in the start method of a MonoBehaviour in each additive scene, you can register these lists and initialize GPU Instancer. You can add the following script to all your additive scenes (not to the first scene with the manager) and it will do this for you:

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3.  
    4. namespace GPUInstancer.Extras
    5. {
    6.     public class GPUIRegisterPrefabInstances : MonoBehaviour
    7.     {
    8.         // Keeping a static reference to the manager so it can be shared between scenes.
    9.         public static GPUInstancerPrefabManager prefabManager;
    10.         // The list of prefab instances in scene
    11.         public List<GPUInstancerPrefab> prefabInstanceList;
    12.  
    13.  
    14.         // In this example we fill the list in the Reset method which works when adding the component for the first time (or using the reset command in the inspector).
    15.         // You can fill the list in any way you want.
    16.         public void Reset()
    17.         {
    18.             // Add prefabs in the scene to the list
    19.             prefabInstanceList = new List<GPUInstancerPrefab>(FindObjectsOfType<GPUInstancerPrefab>());
    20.         }
    21.  
    22.         void Start()
    23.         {
    24.             // Find the prefab manager and set it to the static property
    25.             if(prefabManager == null && GPUInstancerAPI.GetActiveManagers() != null)
    26.             {
    27.                 GPUInstancerManager manager = GPUInstancerAPI.GetActiveManagers().Find(m => m is GPUInstancerPrefabManager);
    28.                 prefabManager = (GPUInstancerPrefabManager)manager;
    29.             }
    30.  
    31.             // Register the prefab instance list to the manager
    32.             if (prefabManager != null && prefabManager.isActiveAndEnabled)
    33.             {
    34.                 GPUInstancerAPI.RegisterPrefabInstanceList(prefabManager, prefabInstanceList);
    35.                 GPUInstancerAPI.InitializeGPUInstancer(prefabManager);
    36.             }
    37.         }
    38.     }
    39. }
     
    OdderOtter likes this.
  37. kyleshell

    kyleshell

    Joined:
    Jul 28, 2017
    Posts:
    10
    Hey, thanks for the helpful reply. This code got me pretty close and I've toyed with it for awhile, but it doesn't seem to work for this particular situation. I'm generally pretty confused about this. I put the above script on an empty game object in each additional scene and the script you wrote made the lists for each scene automatically (the Original Scene being an exception). The Prefab Manager is placed in the Original Scene with just the player object and camera as you suggested. The Prefab Manager starts with 8 prefabs and 0 instances for each prefab.

    I load the first instanced scene using OnTriggerEnter() and the above script should run during the start method because the game object it is attached to is loaded. However, the GPUI GUI tool is showing that 0 prefabs are being instanced after I load a new scene that should have registered the instances. Additionally, it has added some instances into the prefab manager count, but the values are not nearly high enough for what the real list entails (about 100 instances total when it should be about 2000). My hunch was that either the entire scene wasn't loaded before it tries to instance the objects or that GPU Instancer was trying to do it in a single frame and failing.

    So yeah, the Prefab Manager is kind of responding and the GUI tool isn't responding at all.

    So, at first, I tried to delay the Start method code using a simple timer script to make sure that the scene loaded completely before the GPUIRegisterPrefabInstances script ever occurs (I tried both Start() and OnEnable() for this). But it simply isn't instancing all of the prefabs or perhaps any prefabs, if the GUI tool is to be believed. It's a very odd conundrum, because your script seems like it should easily work.

    So yeah, not sure if I'm going to be able to integrate GPU Instancer before my demo deadline in a few weeks. The game runs reasonably fast without it, but obviously I want to push the performance as far as it will go. Perhaps there is something I am missing.

    Is there a way to trigger the above Start method using a coroutine? That might fix what appears to be a script that is getting cut off before it finishes. I know because I was dumb enough to add an Update () method to your script instead of start, and it just kept multiplying the instance count that was already there (aka only instancing top of the list instead of freezing to instance the entire list each frame). Hope this all makes sense.
     
    Last edited: Jun 23, 2018
  38. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi Kyle,

    I think this happens because there are not any instances in the initial scene, so some required buffers and lists are not being initialized. We will look into it and fix it in the next update if there are any problems.

    This is not a proper solution but since you are in a hurry. Can you try adding at least one instance of each prefab to the initial scene where you have the Prefab Manager and press "Register Prefabs in Scene" button on the manager? You can set their scales to 0 so they will not be rendered. Let us know if this solves your problem.
     
  39. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Hi,
    I'm watching GPU Instancer's tutorial videos right now. I noticed that for the detail manager, it chooses a terrain tile to manage the grass. So will this function work on multiple terrains? What about run-time generated terrain tiles (using other assets like MapMagic to generate the game world procedurally.
     
  40. LouskRad

    LouskRad

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

    For multiple terrains, you can add as many detail managers as there are terrains in your scenes. For runtime generated terrains, you can add the managers from code and initialize GPU Instancer through our API. For an example of this, you can take a look at the AddModifyTerrainsRuntimeDemo scene. As for Map Magic integration, we will be submitting an update in a few days that will include this feature as well.
     
  41. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Great, add a manager to each terrain tile is easy. Does the hierarchy level of the detail manager matters? Say if I put each one under the terrain tile, will it work as the same?

    BTW, dose the detail manager breeze the grass by the intensity of unity's wind zone? Or it's a stationary movement?
     
    Last edited: Jun 23, 2018
  42. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Yes, it works the same with any hierarchy you use. Where you put the manager does not matter. You can add it on/under the Terrain GameObject or on a separate GameObject.
    If you are enabling/disabling your terrains at runtime, I recommend to add the Detail Manager under your terrain. So it will be automatically enabled/disabled with your terrain without additional code.

    Grass wind is not connected with the wind zone. It works with the settings defined on the prototype with the included Foliage shader. There are settings for both idle sway and wind waves. You can check the setting descriptions on our getting started page.
     
    Last edited: Jun 23, 2018
  43. kyleshell

    kyleshell

    Joined:
    Jul 28, 2017
    Posts:
    10
    I tried to do the fix that you suggested and also restarted the first list that I am testing. Unfortunately, it's having weird side effects. In the GUI tool it says that there are 8 prefabs and 8 instances. But the rendered instance value is 19 whenever I look in the direction of the instances that I placed in the original scene. Also, this is the error that the console sends once immediately following the loading of the scene:

    ArgumentNullException: Argument cannot be null.
    Parameter name: key
    System.Collections.Generic.Dictionary`2[GPUInstancer.GPUInstancerPrototype,System.Collections.Generic.List`1[GPUInstancer.GPUInstancerPrefab]].get_Item (GPUInstancer.GPUInstancerPrototype key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:136)

    Seems it might be a list problem? The prefab manager is still registering random values, but they don't seem to be initialized into the scene.
     
  44. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    It looks like prototype references were lost, but I can't be sure without seeing the details. I sent you a mail with a script that can identify the problem in your case.
     
  45. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    157
    I am a little bit confused. Can this be used for static, since it says since you are using GPU Instancing it does not apply for static objects. But when using static, it batches.
     
  46. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    To clarify, you can use GPU Instancer with prefab instances that are marked static in your scenes. The issue is, Unity's static batching and GPU Instancer's instancing won't work together at the same time for the same objects.

    So If you have static prefab instances in your scene, which are also defined and registered in your prefab manager, GPU Instancer will work with these objects instead of static batching.

    Also, have in mind that the lightmaps on your static objects won't be reflected in the GPU Instancer prefabs.

    Of course, static batching will work normally on everything else that are not defined in a GPU Instancer manager.

    I hope this clarifies a bit more.
     
  47. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    157
    So if I bake the lighing, GPU Instancer Prefab wil not apply - so no global illumination, etc. I am sorry, I just want to be clear. I have to learn to balance between these two before I start building my level.
     
  48. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    157
    Also there is no way to tile the same material on different objects, correct? Also, there is no way to manually add variation to each object without code. Doing it through code will be horrendous, since I will have to have somoething unique of the model.

    But your asset is awesome.
     
  49. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    The rendering mode also matters. Lighting with all light types that work in real time GI will work on GPU Instancer prototypes when you use real time GI in deferred rendering. It also works with directional lights on forward rendering. However, baked GI in general and lights that are not directional in forward rendering won't currently work out of the box.

    If you mean to tile, for example a texture on different instances using world position, you can have a material with a custom shader that does this (e.g. our foliage shader does this with color). GPU Instancer will work with such a shader.

    The most common way to reduce your draw calls to a single draw call but also keep variations on the material is through the usage of Material Property Blocks. GPU Instancer does not use MPBs specifically, but instead supports a similar buffered approach through the API. In both versions however, you will need to do this through code.

    GPU Instancer indeed reduces all its complex operations to a few clicks, but in the case of material variations, there are use case specific options like which material properties or rules need to be varied, so we can not generalize this.

    Thanks!
     
  50. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    I have game objects (items) instantiated and deleted from the scene by our own codes, I see that new generated objects should be added into the manager, but what about the deleted objects, do I have to remove them from the manager as well?