Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] GPU Instancer

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

  1. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    102
    Quick question on using the standard or generated GPUI shader on materials that are NOT used by a GPU prefab. We have some shared materials which I would set over to use the GPUI shader version but some of those materials are used by prefabs that are not included as GPUI prefabs if that makes sense. Is that going to be an issue ie are those going to run slower or higher overhead and should I move them off into their own material so they can use the standard shader etc? Thanks.
     
  2. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    102
    Additional. Using GPUI shader ie say standard does having GPU Instancing turn on have any negative effects with GPU Instancers prefabs? I have some prefabs shared right now with Veg Studio Pro and it turns on the GPU Instancing setting for instanced objects (another issue I will look at to see if this is something I would rather not be doing but still).
     
  3. mikerz1985

    mikerz1985

    Joined:
    Oct 23, 2014
    Posts:
    70
    Is it possible to create a prefab prototype at runtime?
    I have lists of transformation matrices and variation data which I'm managing, and i would like the user to be able to load a 3d model at runtime use that to render with the InitializeWithMatrix4x4Array route
     
  4. itadakiass

    itadakiass

    Joined:
    Nov 11, 2017
    Posts:
    6
    Hi, LouskRad! Thank you for your answer regarding perfomance differences with unity terrain. Ive learnt a lot from it.

    Btw, are you planning to make detail simulation work while editing the terrain? It hard to design level without actually seeing how its gonna look. Grass meshes look completely different in game in comparison to editor.
     
  5. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    65
    Hello @LouskRad I have a question about GPUI tree shaders. I'm wanting to reduce the AO darkness circled in red here. I tried looking through the shader code but it's not my area of expertise and didn't find any solution. I tried entering texture maps into all the available texture fields, though that didn't help. Is there some way I can reduce the darkness of this AO value? upload_2020-1-16_15-21-31.png
     
  6. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    74
    Hi, I am considering buying this asset but before, I just want to make sure it will fit my project, so I have two questions:
    - Will the manager pick prefabs placed in different scenes? my project is composed of dozens of scenes and some prefab instances would be placed in multiple scenes, or do I need to have one manager per scene?
    - In regards to terrain details (grass/rocks etc), unity loads and unloads batches on the fly from disk, and that generates cpu spikes very often to me. Is this asset loading and managing the details in a different fashion from Unity or the only thing that changes is the shader being used to render the details?

    Thanks for your time
     
  7. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    857
    Assets\GPUInstancer\Scripts\Editor\GPUInstancerPreviewDrawer.cs(85,45): error CS0117: 'CameraType' does not contain a definition for 'Preview'

    thoughts?
     
  8. Leniaal

    Leniaal

    Joined:
    Nov 7, 2012
    Posts:
    72
    Hi,

    I'm using VegetationStudio generate my vegetation. At the start of the game I export all the vegetation data to GPUInstancer and I disable VegetationStudio. This all works great, but I now have an issue with using a floating origin. I believe I'm doing everything correctly, but my instanced vegetation is simply no longer visible.
    upload_2020-1-18_17-29-17.png

    I checked if maybe the origin shifts before all the vegetation is instanced, but this is not the case. I also checked if the Vector3 that GPUInstancer calculates is correct, and it is.
    upload_2020-1-18_17-33-48.png
    Output:
    upload_2020-1-18_17-33-22.png

    I don't know how to debug where the problem is, any tips or ideas?

    EDIT:

    Actually my issue looks quite a lot like the issue @Fewes is having
     

    Attached Files:

    Last edited: Jan 18, 2020
  9. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,682
    @LouskRad : is GPU Instancer supposed to work in the sceneview? Because if it is supposed to I don't know how to do it.... I paint lots of trees in sceneview and it gets slow, game view shows 9000 batches, but the moment I hit play it drops to 2,000 batches (needless to say) - even at 9000 batches in gameview it's still 60+ FPS. But sceneview doesn't appear to be affected with GPU Instancer and slows down fairly bad.
     
  10. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,682
    Found the issue... Apparently with the terrain chunks I haven't touched yet it created GPUI Tree Managers for each one, I deleted the ones I wasn't using and FPS skyrocketed back up....

    Are empty Tree managers bad for performance??
     
    Last edited: Jan 19, 2020
  11. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    425
    Hi @N1warhead

    Not sure if this is of any help for you, but I'm also using multiple terrains and you can put all trees in the single Prefab Manager instead of using multiple Tree Managers. Makes the handling easier for me and perhaps would also solve your issue.
     
  12. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,682
    So you're using trees as GameObjects rather than trees on the terrains? How many roughly do you have on your map out of curiosity (just rough estimate). Just curious if it'll handle better with tens of thousands of trees as GameObjects vs Trees on Terrain.
     
  13. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    425
    Doesn't GPUI create GameObjects anyway for the Trees even when using the Terrain Manager (I'm sure sure about this). But I have not done any performance testing of Prefab vs Treemanager on multiple terrains.
     
  14. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    Hi Fewes,

    based on the screenshots everything looks like as it should be. However, we cannot reproduce neither of these issues on our tests. If you can send us a sample package showing these issues, we can analyze it to identify the problem.
     
  15. LouskRad

    LouskRad

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

    We haven't noticed a problem during import in 2019.3 (which uses asset database v2 by default). Which file in your project is causing this infinite import loop? Maybe it can give us more information on the issue.
     
  16. LouskRad

    LouskRad

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

    this might happen after a change in your project's HDRP version. The GPUInstancer/HDRP/Lit shader is auto generated, so you can try deleting that file and have GPUI re-generate the shader for the correct HDRP version in your project.
     
  17. LouskRad

    LouskRad

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

    You can safely use the GPUI versions of your shaders on the prefabs that are not used by GPUI. These auto-generated version only include the GPUI setup and that would not change anything where procedural instancing is not being used.

    GPUI completely ignores the "Enable GPU Instancing" setting on the material, so enabling/disabling it wouldn't change anything for GPUI.
     
  18. LouskRad

    LouskRad

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

    it is certainly possible. You can take a look at the "AddRuntimeCreatedGameObjects" demo scene in the package for an example.
     
    mikerz1985 likes this.
  19. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    One design decision in GPUI is that it does not handle vegetation placement. Since Unity does not provide an API to keep track of detail painting changes on the terrain, GPUI offers only an enabled/disabled simulation to use as a preview. Changing this to a real time rendering during paint workflow would require us to sacrifice a lot of editor performance or override the Unity terrain for this purpose. We do not plan to go this route with GPUI.

    Having said that, if you wish to customize this behavior, you can take a look at the StartEditorSimulation and StopEditorSimulation API methods to implement your own design logic using them.
     
  20. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    Hi Dobalina,

    The only related difference between the GPUI rendered versions of TreeCreator objects and their originals is a per instance applied ambient occlusion value. The way Unity applies this for variation can differ from how GPUI renders the trees.

    To answer your question, you can try turning off the "Ambient Occlusion" value in your original TreeCreator object, which should disable the darkening of your trees. For a general AO solution, you can then use a SSAO effect for that purpose.
     
  21. LouskRad

    LouskRad

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

    You can have a single manager and persist it throughout scenes. There are various other ways to use GPUI on a multiple scene project too, I suggest you take a look at the wiki pages for more information.

    As for terrain details; yes, they are handled by GPUI and you would not see the spikes caused by Unity patch loading/unloading.
     
  22. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    It looks like you have a class called 'CameraType' in your project which overrides the default 'CameraType' class in Unity. You can solve this by wrapping your custom class into a namespace, or changing its name.
     
  23. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    Indeed it looks like Fewes' problem. However, we were unable to replicate this problem. If you can send us a sample project showing this, we can investigate it to identify the underlying issue.
     
  24. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    Hi @N1warhead , @iddqd

    If you're looking for the Best Practice when doing this, it would be to use a Prefab Manager with a no game object workflow for all the trees.

    However, both other methods are viable, and you can use the convenient one for you without effecting the performance when using a single terrain. On a multiple terrain setup, a Prefab Manager could be a better choice since it would not have the downside of duplicating draw calls for each terrain as you would have when using a Tree Manager for each terrain.
     
    iddqd and N1warhead like this.
  25. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,682
    Thank you, i'll look into that.
     
  26. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    425
    Thanks @LouskRad

    But if our Trees need colliders, then we also need GameObjects, correct? Or is there some other clever solution to have the colliders separately?
     
  27. RetroFlight

    RetroFlight

    Joined:
    Nov 16, 2019
    Posts:
    35
    Has anyone had any luck on the Oculus Quest?

    I can get about 20,000 trees (95% billboard) through Unities standard Instancing before I start losing frame rates. It looks like it is because the batches get too high as Unity doesnt include as many objects in a batch as GPUI does. If I make the trees bunches (t trees in one mesh) I can get a lot higher tree count but at high angles it looks weird as Unity tree billboards only render from a low angle.

    If this could double or tripple the amount of trees I can get on scene for my flight sim I will jump at it.
     
  28. Bamfax

    Bamfax

    Joined:
    Jun 12, 2016
    Posts:
    52
    Hi LouskRad, Gurbu Team,

    a quick question: In XR I am getting a vertical line/area in the middle of the frustrum (along its whole depth) which is being occlusion culled (always). Also the avatar hands are occlusion culling areas they should not. This culling looks mathematically correct, seems somewhat like each hand is always occlusion culling the world from the viewpoints of both eyes.

    Cameras can be switched in the in the scene. Hi-Z Generator jumps to the active camera as intended. Project is OpenVR / Vive only, using multipass rendering.

    I am still on v1.1.3, please excuse me asking before upgrading. Do I need to upgrade to 1.3 or is that something I can fix by config?

    Many thanks again.
     
    Last edited: Jan 23, 2020
  29. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    609
    Hi @LouskRad ! you say: Automatic 2D Billboard generation system (Standard RP only)... When would it work in HDRP?

    Regards!
     
  30. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    255
    So i did a complete reimport in an empty project and this is my before and after:

    upload_2020-1-26_21-53-45.png

    This is before i start the game as soon as i start it all tree disappear expect from a few:

    upload_2020-1-26_21-54-25.png

    if i look at my terrain tree manager:

    upload_2020-1-26_21-54-50.png

    upload_2020-1-26_21-55-16.png

    Does anyone know what the problem might be?
     
  31. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    A collider pooling system for this would be ideal for extreme instance counts. Then, you can have a no game object workflow where you can have a limited number of collider only GameObjects.
     
  32. LouskRad

    LouskRad

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

    There have been various fixes/improvements regarding occlusion culling in later upgrades, especially in the v1.2 updates. I would suggest upgrading to the latest version before trying anything else.
     
  33. LouskRad

    LouskRad

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

    We currently have no plans for the near future to implement this on HDRP; but you can currently use a custom shader for this or a custom billboard/impostor.
     
  34. LouskRad

    LouskRad

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

    Are there any errors/warning messages in your console window? The tree shader might be the problem, but can't say much without seeing the error messages.
     
  35. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    255
    There are no errors in the console window :( not even warnings
     
  36. SOSolacex

    SOSolacex

    Joined:
    Jan 10, 2018
    Posts:
    25
    Hey there, I am currently having an issue where an instanced prefab look far worse when looking at them from certain angles, even if I am very close to the object.

    How do I fix this exactly?
     
  37. Leniaal

    Leniaal

    Joined:
    Nov 7, 2012
    Posts:
    72
    Ok this was a bit frustrating, but I have found the issue.

    Code (CSharp):
    1. ...
    2. foreach (GPUInstancerRuntimeData runtimeData in manager.runtimeDataList)
    3.                 {
    4.  
    5.                     if (runtimeData == null)
    6.                     {
    7.                         Debug.LogWarning("SetGlobalPositionOffset called before manager initialization. Offset will not be applied.");
    8.                         return;
    9.                     }
    10.  
    11.                     if (runtimeData.instanceCount == 0 || runtimeData.bufferSize == 0)
    12.                         return;
    13.  
    14.                     if (runtimeData.transformationMatrixVisibilityBuffer == null)
    15.                     {
    16.                         Debug.LogWarning("SetGlobalPositionOffset called before buffers are initialized. Offset will not be applied.");
    17.                         return;
    18.                     }
    19. ...
    Should be

    Code (CSharp):
    1. ...
    2. foreach (GPUInstancerRuntimeData runtimeData in manager.runtimeDataList)
    3.                 {
    4.  
    5.                     if (runtimeData == null)
    6.                     {
    7.                         Debug.LogWarning("SetGlobalPositionOffset called before manager initialization. Offset will not be applied.");
    8.                         continue;
    9.                     }
    10.  
    11.                     if (runtimeData.instanceCount == 0 || runtimeData.bufferSize == 0)
    12.                         continue;
    13.  
    14.                     if (runtimeData.transformationMatrixVisibilityBuffer == null)
    15.                     {
    16.                         Debug.LogWarning("SetGlobalPositionOffset called before buffers are initialized. Offset will not be applied.");
    17.                         continue;
    18.                     }
    19. ...
    In my case it ran into runtimeData.instanceCount == 0 so it just returned on the first RuntimeData object.

    @Fewes Maybe this fixes it for you as well.

    EDIT:

    Another suggestion, or tip to others who are using a Floating Origin. Move the code to a public function and call it from where you are moving the origin, in my case I was moving the origin in LateUpdate and so GPUInstancer responed to this a frame later.

    Code (CSharp):
    1.         public void UpdateOffset()
    2.         {
    3.             foreach (GPUInstancerManager manager in gPUIManagers)
    4.             {
    5.                 if (manager != null)
    6.                     GPUInstancerAPI.SetGlobalPositionOffset(manager, transform.position - _previousPosition);
    7.             }
    8.             _previousPosition = transform.position;
    9.         }
     
    Last edited: Jan 30, 2020
    LouskRad and hjohnsen like this.
  38. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,214
    Sometimes it happens that metafiles are corrupted/missed and when it happens, the GPUInstancer complans in a not useful way, just saying, for example:

    ArgumentNullException: Value cannot be null.
    Parameter name: key
    System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) (at <437ba245d8404784b9fbab9b439ac908>:0)
    System.Collections.Generic.Dictionary`2[TKey,TValue].ContainsKey (TKey key) (at <437ba245d8404784b9fbab9b439ac908>:0)
    GPUInstancer.GPUInstancerPrefabManager.InitializeRuntimeDataAndBuffers (System.Boolean forceNew) (at Assets/GPUInstancer/Client/Scripts/GPUInstancerPrefabManager.cs:160)
    GPUInstancer.GPUInstancerManager.OnEnable () (at Assets/GPUInstancer/Client/Scripts/Core/Contract/GPUInstancerManager.cs:205)

    Clicking on it doesn't give any clue about what the problem actual is and finding the real error is very time consuming. It would be absolutely useful if GPUInstancer could have a verify asset button that once clicked would highlight the assets with problems.

    (Another similar case is when material or shaders are not found)
     
  39. RetroFlight

    RetroFlight

    Joined:
    Nov 16, 2019
    Posts:
    35
    Is this asset compatible with Oculus Quest?
     
  40. ChaosriftGames

    ChaosriftGames

    Joined:
    Aug 25, 2017
    Posts:
    56
    Getting this error a lot. It was originally for the Legacy shaders. I fixed that. Now I'm getting it for the fix. I don't know where/which "the manager" is to get the instructions to download the fixed shaders.

    "Particles/Standard Unlit" shader is a built-in shader which is not included in GPUI package. Please download the original shader file from Unity Archive to enable auto-conversion for this shader. Check prototype details on the Manager for instructions.
     
  41. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,093
    Hi, this looks like a great system! However, we need to support computers with integrated graphics, which I understand run Instanced Indirect poorly. Is there an option in GPUI to switch to Instanced on those computers? (Veg Studio Pro has such an option, but we'd like to use GPUI for a broader range of things.)

    thanks
    Dave
     
  42. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,214
    GPUI works great on all the integrated cards from intel HD 4000 and above.
     
  43. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,093
    Thanks for the reply. Really? I was recalling @LouskRad 's comment awhile ago on this thread:

    As for lower end, integrated graphics devices - it is quite expected to see low performance on them since instancing would scale with the power of the GPU. Especially on devices where the GPU and CPU memory is shared, you would not get the desired performance increases from instancing since there is no dedicated GPU unit.
    My understanding is that Instancing could be preferable on those GPUs, though I guess I don't have a source for that (except on Macs, where it's a known issue that Indirect is dramatically slower than Instanced -- even on dedicated GPUs -- so this option would be desirable at very least for Macs.)
     
  44. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,214
    yes that's what he told me as well, but I never had problems with the GPUI compute shaders. Compute shaders are called way less frequently than, say, pixel shaders, so it's very likely you will be fill rate bound way before GPUI becomes a problem.
     
  45. SOSolacex

    SOSolacex

    Joined:
    Jan 10, 2018
    Posts:
    25

    Here, this is what I experience. Happens only on instanced prefabs.
    Tinytake Vid link
     
  46. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    Hi there, and thanks for the video.

    This might be a problem with an unintended lighting result from a frustum or occlusion culled mesh. You can test this by disabling the occlusion and frustum culling options in the manager. If the issue is gone when you do that, you can play with the culling settings to find a fitting sweetspot.
     
  47. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    Currently GPUI does not officially support the Oculus Quest. However, we have had reports from some of our users using GPUI for this platform with limited functionality. We did not run any tests on the Quest, however.
     
  48. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    Hi there, you can download the built-in shaders from Unity Archives. However, the shader you mention has its own procedural instancing setup, and therefore would not work with GPUI.
     
  49. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    818
    Hi there,
    GPUI works only by rendering with the indirect instancing API, so there is no option to switch to another method.
     
  50. ChaosriftGames

    ChaosriftGames

    Joined:
    Aug 25, 2017
    Posts:
    56
    Ah darn. Wish the error gave scene and prefab names. I got 45 to go through :p

    thanks for the reply.
     
unityunity