Search Unity

[RELEASED] GPU Instancer

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

  1. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    You can use the SetLODBias API method.
     
  2. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    Thanks for the info. Do you happen to have an example of how to use GPUI and DOTS together?
     
  3. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    259
    The asset that never disappoints. Thanks!
     
    LouskRad likes this.
  4. Ryan-Hayle

    Ryan-Hayle

    Joined:
    Feb 16, 2014
    Posts:
    142
    Thank you for checking, I went back and checked again and when I turned off the default option LOD Cross Fade I am able to see the trees during run-time
     
  5. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    105
    Hello.
    I've been using GPU grass on my terrain for a while now and it's been great. I recently updated the my terrain to use PBR shaders and now find there's a now visually a significant saturation and brightness difference between the GPU grass and my terrain. I noticed that when I scrub my Ambient Color value in the scene Lighting from white to black, the grass is heavily affected where as the PBR materials on my terrain are affected much less.

    I'm wondering, is there a PBR version of the foliage shader? Or is there some way to turn off or reduce the amount of Ambient Color the GPU grass will receive?
     
  6. Ryan-Hayle

    Ryan-Hayle

    Joined:
    Feb 16, 2014
    Posts:
    142
    Last edited: Oct 1, 2019
  7. shi946

    shi946

    Joined:
    Jun 3, 2019
    Posts:
    16
    Thank you for the reply. I think I now understand how nested prefabs work, but am trying to grasp the coding structure to spawn parents during runtime.

    From the asteroid video, if I made a parent called "asteroid cloud", would I have to add each of its asteroid kids into the instance list? I'm using 2018.3.14

    Does each "asteroid cloud" also need to be added to the instance list and be a registered prefab?

    Do I need to instantiate each child or can I just instantiate the parent?

    Edit: Nevermind, figured it out.
     
    Last edited: Oct 3, 2019
    LouskRad likes this.
  8. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    I'm making a VR game, and using a custom CG shader, and am getting really bad flickering on most of the geometry. Depending on what I'm looking at, it will stop flashing on and off for some things when looking at some angles, but most of the time it'll be flickering. Switching to the Standard GPUI shader solves the issue, so it seems specific to my shader. This does not occur in the Scene View at edit time.

    Excerpts from my shader:
    Code (CSharp):
    1. CGPROGRAM
    2.       #pragma vertex vert
    3.       #pragma fragment frag
    4.  
    5.       #include "UnityCG.cginc"
    6.       #include "AutoLight.cginc" // shadow helper functions and macros
    7.       #include "../GPUInstancer/Shaders/Include/GPUInstancerInclude.cginc"
    8.  
    9.       #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
    10.       #pragma multi_compile_instancing
    11.       #pragma instancing_options procedural:setupGPUI
    12.       #pragma multi_compile_fog
    13.  
    14.       #define USING_FOG (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
    My vertex data struct has
    UNITY_VERTEX_INPUT_INSTANCE_ID
    at the end. My vertex to fragment struct has
    UNITY_VERTEX_OUTPUT_STEREO
    at the end. My vertex program begins with:
    Code (CSharp):
    1. UNITY_SETUP_INSTANCE_ID(v);
    2. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    I must be missing something, what is it?
     
    Last edited: Oct 3, 2019
  9. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    It looks like this is related to Occlusion Culling, since when I disable it I don't get flickering. Disable Depth and Stencil is unchecked, what else do I need to have set in order to get a proper camera depth texture?
     
  10. Davood_Kharmanzar

    Davood_Kharmanzar

    Joined:
    Sep 20, 2017
    Posts:
    411
    @LouskRad

    is it possible to using GPUI with openGL ES 3.1 on Android 5.1 or 6.0 ... or should be Android 8.0 and above?
     
    Last edited: Oct 4, 2019
  11. LouskRad

    LouskRad

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

    We currently don't have an example, but we will look into providing one.
     
    Bas-Smit and JamesWjRose like this.
  12. LouskRad

    LouskRad

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

    The foliage shader was developed using Amplify Shader Editor. You could use that tool to modify the shader to your liking or use a custom material with a third party shader for your grass instead of the GPUI foliage shader.
     
  13. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    the custom function node unfortunately does not allow for adding the requires #pragma directives. We will look into adding one when Unity provides this option. You could copy and paste the shader code to a shader file to have the GPUI converter work on it. Another alternative would be using a third party SRP compatible shader generator such as the Amplify Shader Editor.
     
  14. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    The issue looks like caused by your shader making use of the depth texture. You can use the Debug option on the HiZOcclusionGenerator to see what final depth texture GPUI is using for it's occlusion culling process. You can see this component added to your camera at playmode.

    Also, you might need to override the built-in depth/normals shader to use one that is setup for GPUI and your shader. You can use the Internal-DepthNormalsTexture_GPUI and add a pass to it for your custom shader.
     
    hellstorm likes this.
  15. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Rather than the Android version, the issue is with the compute shader limitations of the target device. The Android 5.1 and 6.0 devices would generally have a risk of having incompatible hardware with GPUI.
     
  16. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Thanks for the reply, though unfortunately overriding the built-in shader did not solve the problem. I'm not knowingly making use of the depth texture for anything. Here's the debug output during a frame where a lot of stuff has disappeared:

    upload_2019-10-4_9-14-49.png

    When you say add a pass to your DepthNormals one, what do you mean? Right now my shader is intentionally single pass, other than shadows:

    Code (CSharp):
    1.   ENDCG
    2.     }
    3.     // shadow casting support
    4.     UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
    5.   }
    6.     //FallBack "Legacy Shaders/VertexLit"
    7. }
     
  17. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Here's the result when I look in a direction with no flickering (still messed up):

    upload_2019-10-4_10-49-46.png
     
  18. Deleted User

    Deleted User

    Guest

    Will there be a Map Magic 2 Integration?
    As you can read in there Thread does it come out in 2 - 3 Months.
     
  19. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Ah, I misread the FAQ for shaders. I need to manually paste in the shadow caster pass and add the GPUI stuff to that.

    Doing that fixed the flickering, however now I have no shadows a̶n̶d̶ ̶m̶y̶ ̶q̶u̶i̶t̶e̶ ̶s̶i̶m̶p̶l̶e̶ ̶s̶c̶e̶n̶e̶ ̶r̶e̶n̶d̶e̶r̶ ̶t̶i̶m̶e̶ ̶i̶s̶ ̶o̶v̶e̶r̶ ̶1̶0̶0̶m̶s̶.̶ ̶I̶s̶ ̶t̶h̶e̶r̶e̶ ̶a̶ ̶s̶i̶g̶n̶i̶f̶i̶c̶a̶n̶t̶ ̶o̶v̶e̶r̶h̶e̶a̶d̶ ̶f̶o̶r̶ ̶s̶e̶t̶t̶i̶n̶g̶ ̶u̶p̶ ̶p̶r̶o̶t̶o̶t̶y̶p̶e̶s̶?̶ ̶I̶ ̶h̶a̶v̶e̶ ̶3̶4̶.̶ ̶M̶y̶ ̶i̶n̶t̶e̶n̶t̶i̶o̶n̶ ̶i̶s̶ ̶t̶o̶ ̶h̶a̶v̶e̶ ̶a̶ ̶l̶a̶r̶g̶e̶r̶ ̶n̶u̶m̶b̶e̶r̶ ̶o̶f̶ ̶p̶r̶o̶t̶o̶t̶y̶p̶e̶s̶ ̶w̶i̶t̶h̶ ̶s̶e̶v̶e̶r̶a̶l̶ ̶h̶u̶n̶d̶r̶e̶d̶ ̶i̶n̶s̶t̶a̶n̶c̶e̶s̶ ̶-̶ ̶m̶a̶y̶b̶e̶ ̶i̶n̶ ̶s̶o̶m̶e̶ ̶c̶a̶s̶e̶s̶ ̶a̶ ̶t̶h̶o̶u̶s̶a̶n̶d̶ ̶o̶r̶ ̶t̶w̶o̶ ̶-̶ ̶f̶o̶r̶ ̶e̶a̶c̶h̶ ̶p̶r̶o̶t̶o̶t̶y̶p̶e̶.̶ (didn't see that a SteamVR error gave me horrible, terrible performance).

    So yeah, not sure the issue with shadows, but that's the only thing left here.

    [EDIT] Aaaand got it, switching to the included shadow caster fixed my issue. Maybe I wasn't blending properly with my own one, not sure:
    Code (CSharp):
    1.       ENDCG
    2.     }
    3.     // shadow casting support
    4.     UsePass "Hidden/GPUInstancer/ShadowsOnly/ShadowCaster"
    5.   }
    6. }
     
    Last edited: Oct 4, 2019
    hellstorm likes this.
  20. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Small doc suggestion: add that example code to the FAQ, especially since you have an included caster pass already.
     
    hellstorm likes this.
  21. secondsight_

    secondsight_

    Joined:
    Mar 2, 2014
    Posts:
    163
    So, I have bought the instancer a long time ago and tried it in a few scenes with MapMagic. All of the scene have a lot of speedtrees and dense gras. But I always struggle to make it work, although it should be easy enough, right ?

    Unity 2018.2
    MapMagic 1.9
    GPU Instacer 1.2.3

    First, importing the grass actually drops my performance ! And although all color values seem to be imported correct, some grass billboard don´t get those colors (and appear white for example).

    Second, the import of trees seem to increase performance, but the billboard colors are wrong (see palm trees in the second shot). Also, the tree billboards don´t blend but clip in.


    OFF


    ON

    I have tried different unity version and different (also new) projects. Same result.
    In Unity 2019 I even get some compile errors:


    (Unity 2019.2)

    Today I have seen that there is an update so I imported it. Result are compile errors and I cannot even build anymore. But I get a performance increase in the editor at least.


    Update

    So yeah, I have no idea what to do with this package now but I absolutly need it for my projects :)
    Since it´s so easy to use, I have no idea what I´m doing wrong.
     
  22. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    105
    Thanks for the reply @LouskRad I fired up Amplifyshader and fixed my grass issues.

    I have another question. In my game there will be hundreds of small terrain tiles. Setting up all the grass/prop detail layers to match one another is pretty time consuming. If multiple terrains can't instance a single prototype definition, is there any way I can copy all the visual data from one prototype to all my other prototypes? (size/color/asset references etc...)
     
  23. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,278
    How do I set this up to handle multiple terrains? Like Dobalina, I have hundreds (500+) of terrain tiles. Also, can I have my own foliage painter that manages the tree data (where the trees are), and uses GPU instancer to generate billboards / render?
     
    Last edited: Oct 9, 2019
  24. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Thank you for the feedback. You can also disable the Shadow with Original Shader option in the manager for the same effect without having to manually add the GPUI Shadows Only shader as a UsePass Shadowcaster pass.
     
  25. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    We are following the process and we will look into it when is released.
     
    Deleted User likes this.
  26. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    and thank you for the screens.

    Regarding performance when instancing terrain details with GPUI, you can take a look at this wiki article. If the grass does not show the colors in the manager, that is not supposed to happen. Please send us a sample project showing this so we can investigate it.

    For Billboard colors, you can adjust the brightness in the Billboard Settings section of the manager, or use a custom billboard that is not generated by GPUI.

    As for the error you got prior to updating to GPUI v1.2.4, it looks like the generators are null. We have not encountered this before. We can analyze this if you can send us a sample project. On the other hand, we fixed the errors you get with v1.2.4 and we will soon submit an update with these fixes.
     
  27. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there, and thank you for the feedback.
    Currently GPUI does not offer a way to copy settings between different prototypes, but we will look into it.
     
  28. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    For detail and tree managers, you can add one for each of your terrains. However, If you wish to use a custom prefab painter for your foliage and trees, you can paint them as prefabs and use a Prefab Manager with them instead (you can still use the billboard generator that way).

    you can take a look at this video for an example:
     
  29. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,278
    Cool! Does the same apply to details? Are the detail and tree managers just editor wrappers around prefabs, or would I lose rendering features going this route?
     
  30. secondsight_

    secondsight_

    Joined:
    Mar 2, 2014
    Posts:
    163
    I will try to make a small sample project. Can you give me an contact email for the link ?
     
  31. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    The Detail Manager features some terrain specialized techniques (e.g. partitioning) for massive numbers which can result in better memory management in scenes with extreme amount of details, but in terms of core rendering all managers share the same features.
     
  32. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Thanks. You can use support@gurbu.com
     
  33. ElevenGame

    ElevenGame

    Joined:
    Jun 13, 2016
    Posts:
    146
    Hey there, I'm using GPU Instancer with 2019.03.b06 and MapMagic. It works fine, but a part of the custom editor of MM integration is not drawing completely, as you can see on the Screenshot. Also GPUInstancerMapMagicIntegration script had some EditorUtility calls that were not within #if UNITY_EDITOR, so it wouldn't compile in a build.
    GPU_instancerMM.png
     
  34. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,278
    Hmm... I'm trying to integrate it into my foliage painter, but I don't want to instantiate prefabs, or any of that sort of thing. I'm just looking to register a prototype, and then be able to push matrices that act as the individual transforms, using that no-game object approach. In other words, just rendering, no scene prefab variant scanning, or anything like that. Currently trying to make a stripped away form of the prefab manager, and having some trouble. Any tips on how I should go about this?

    Essentially my goal is to build a GPUInstancerManager that can create a prototype based off a prefab, and then during runtime take in a list of matrices, and then render, without instantiation. I'm having so much trouble figuring out what to add and what to remove oof
     
    Last edited: Oct 10, 2019
  35. secondsight_

    secondsight_

    Joined:
    Mar 2, 2014
    Posts:
    163
    While preparing a sample project for you, I came across a new problem. Trees are not shown ingame and the editor windows shows only billboards.



    Also, I have to add ;MAPMAGIC everytime after import in the player settings in all versions I have ever used. It never registered automatically. Could that be a hint ? Anyways, should I send you this project ?
     
  36. unity_DqWOtlS6jGrEYQ

    unity_DqWOtlS6jGrEYQ

    Joined:
    Aug 27, 2019
    Posts:
    1
    There is a bug in the GPUICrowdUtility, the animationData is being set to twice the buffer size, but the if check is set up without the *2, which results in the animationData not being resized when needed and throwing out of array bound errors.

    GPUICrowdUtility.cs line 18 should look like this:
    ``` if (runtimeData.animationData == null || runtimeData.animationData.Length != runtimeData.bufferSize * 2)```.
     
  37. h00man

    h00man

    Joined:
    Apr 17, 2017
    Posts:
    54
    hi, so i've been using "directX 11 grass shader" for my project and its really great.but i dont know how to set up dx11 grass like you did in you example scene.i tried to use custom material in generate prototype section and dx11 grass material but every single grass on my terrain will be disappear. i also tried to right click on the dx11 grass material and set it up for GPU ,but dont know how to add the new material that is generated in gpui prototype manager:(
     
  38. LouskRad

    LouskRad

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

    We have fixed the map magic related compile errors in version 1.2.5, which you can currently download from the Asset Store.

    As for the editor glitch, it is probably caused by some bug from the beta version you are using. The bug will most likely be fixed in the release version of Unity, and if not, we will provide an Update.
     
    ElevenGame likes this.
  39. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    you can take a look at this wiki page for a starting point.
     
  40. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904

    Hi there,
    the reason why your instances don't show in the editor during play mode is because you have enabled the "Use selected Camera only" option. This prevents GPUI from rendering to the scene Camera:

    upload_2019-10-11_20-29-7.png

    As for why MapMagic is not adding its scripting define symbol, you can ask that to Denis.
     
  41. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Thank you for the feedback, we will look into it for the next update.
     
  42. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    Since this asset uses GPU to generate the grass, it would not be compatible with GPU Instancer.
     
  43. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    315
    Crash:

    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <a8ed250850854b439cedc18931a314fe>:0)
    System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <a8ed250850854b439cedc18931a314fe>:0)
    System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <a8ed250850854b439cedc18931a314fe>:0)
    GPUInstancer.GPUInstancerDetailManager+<MergeVisibilityBufferFromActiveCellsCoroutine>d__26.MoveNext () (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:725)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    GPUInstancer.GPUInstancerDetailManager:StartCoroutineAlt(IEnumerator) (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:566)
    GPUInstancer.GPUInstancerDetailManager:UpdateSpatialPartitioningCells(GPUInstancerCameraData) (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:157)
    GPUInstancer.GPUInstancerManager:UpdateBuffers(GPUInstancerCameraData) (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:535)
    GPUInstancer.GPUInstancerManager:LateUpdate() (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:256)

    Crashed on:
    if (cell.totalDetailCounts[r] > 0)

    I believe it's caused by disabling then reenabling the scene in some order. Could also be due to more than one terrain in the scene.
     
    Alex3333 likes this.
  44. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    This is most likely because the scene is disabled/enabled while the detail initialization thread is still running. You can try disabling the Initialize in Threads option in the Global Detail Values section of your manager(s) and see if the error persists.
     
  45. Leniaal

    Leniaal

    Joined:
    Nov 7, 2012
    Posts:
    119
    Hi there,

    I'm having issues with using Amplify Imposters and GPU Instancer. I'm using imposters as an alternative to billboards on the HDRP pipeline. The OctahedronImposterHDRP shader works great, but when being instanced by GPU Instancer I run into a couple of issues.

    The left tree is being instanced by GPUI, the right is gameobject that the instance is based on.

    2019-10-17_18-02-36.gif

    These are the settings:
    upload_2019-10-17_18-5-49.png

    As you can see, the imposter from the instanced tree does not cast a shadow, but even worse the top half that should be drawn over the skybox is being cut off.

    I don't really know where to look, any help would be greatly appreciated.
     
  46. Leniaal

    Leniaal

    Joined:
    Nov 7, 2012
    Posts:
    119
    Hi there,

    I've been able to reproduce the issue on the original model by enabling Alpha To Coverage. However I don't know how to ensure that GPU Instancer doesn't enable this option.

    2019-10-18_12-24-16.gif
     
  47. Davood_Kharmanzar

    Davood_Kharmanzar

    Joined:
    Sep 20, 2017
    Posts:
    411
    i tried that on some of android 8.1 phones ... but does not working and all of instances (with simple standard-forward shader) was disappeared :[
    i mean phones that upgraded to 8.1 officially ...
    so, its bad!! and can you provide an method that these shaders are works with andoid 6.0 phones at least?
    thanks.

    P.S: everything are working on editor and standalone build.
     
    Last edited: Oct 19, 2019
  48. therewillbebrad

    therewillbebrad

    Joined:
    Mar 2, 2018
    Posts:
    151
    Do you know of a way to get rid of the double mesh that is created whenever I apply a basic animation to a gpu instanced character. Included video shows what I'm talking about. Thanks!

     
  49. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hey there!

    I'd love to try this out or have confirmation if this will work well on Oculus Quest? I am unable to test the APK because of some SDK error (plus it's android VR, so probably wouldn't look right).

    Willing to test anything of course if you're not sure.
    Also: do you think it'll be much benefit on this platform? We only have 3 cores to play with.

    Thanks for any advice :) (On Universal Pipeline if that matters)
     
  50. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    315
    How about rather than crash, it logs an error with suggestions on what the issue might be and how to fix it?
     
    Alex3333 likes this.