Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[RELEASED] GPU Instancer

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

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,859
    i guess you are referring to the "AfsGrassShader". but which script do you mean? the "CombineChildren" script?
    you do not need the "CombineChildren" script in case you use gpu instancer – however even if it is applied gpu instancer should work properly.
    you do have to have an instance of the afs setup script in your scene of course as this will control the wind.
    tested with unity 5.6.3.
     
    UnityRocksAlt likes this.
  2. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    156
    I am using AFS/Foilage Shader and in Unity 2017.4.2f
     
    Last edited: Aug 21, 2018
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,859
    that should not make much difference...
     
  4. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    156
    It does not work, what should I do?
     
  5. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    156
    Should I send you a sample, give me your email address. IS it because of Touch Bending Collision Script?
     
    Last edited: Aug 21, 2018
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,859
    oh, you are using touch bending. i thought you were talking about the grass shader...
    touch bending is not supposed to work out of the box - as it uses a custom materialpropertyblock. it requires DefinePrototypeVariationBuffer as mentioned by @GurhanHazinedar.
     
  7. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    156
    Exactly, so since I am not a shader programmer, but I am a programmer can you guide me or do it yourself? As you are the programmer for this shader, you would know.

    I think you should, your asset is really the best for grass bending. Making it compatible with GPU Instancer would be perfect.
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,859
    it involves c# scripting: you will have to use the gpu instancer's api to set the touch bending matrix – somehow tweaking the tochbending listener script.
    the shader itself only needs some minor changes: it has to read its matrix from a compute buffer using an index. i haven't looked into any details and won't be able to do so within the next days, sorry.

    however it might be the easiest way to simply disable gpu instancing on the plant which shall perform touchbending using DisableIntancingForInstance and EnableInstancingForInstance. according to the gpu instancer's api docs you can use a collider as trigger which would be perfect in case of touch bending.
     
    Last edited: Aug 22, 2018
  9. LouskRad

    LouskRad

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

    That wouldn't work since those two methods are designed for prefab instancing and they require a GPUInstancerPrefabManager. Detail instancing has various other terrain related optimizations and uses specialized compute shaders; and currently instance based enabling/disabling is not supported for detail instancing.

    However, we would be happy to collaborate on an integration of your shader with GPUI if you wish and would have the time.
     
  10. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    156
    Thanks, I would al so like to say sometimes, when an instance is put into your GPUPrefab, the object is simply notpresent (as MeshRenderer is disabled using GPUI's). Can you tell me why that happens?
     
  11. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    GPUI turns off the Mesh Renderer components of the prefabs that are registered in the manager and instead takes over their rendering using Unity's DrawMeshInstancedIndirect API. Most of the other components on the objects, such as scripts, colliders, etc. will remain however, so the object is present as far as its components are concerned.

    I hope this answers your question.
     
  12. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    156
    Thanks, I knew that. I meant even though the GPUInstancer takes it, it becomes invisible.
     
  13. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    The only times the GPUI instances should become invisible should be when they are culled - either when out of camera frustum, occluded, or distance culled. This is to help increase performance. If your objects are culled when they are not supposed to, you could make sure the camera is set correctly in the manager.

    If the camera is correct, and you still have an invisible object which is inside the camera frustum and not occluded (and inside the max distance defined for that prototype) - well, this should not happen. If this is the case, please write us at support@gurbu.com with the specifics of your scene and we can investigate this.
     
  14. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    By the way, I assumed you were using a detail manager for your grass when I said @larsbertram1 's collider suggestion would not work. If you are using a prefab manager, however, it would indeed work. You can take a look at the asteroids scene for an example of using the modification collider to turn off GPUI instancing inside a collider. Also, this tutorial video can give you more information on how to do this.
     
  15. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    156
    :(
    I was using Prefab Manager and it does not work.
     
  16. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Did you follow the steps from the tutorial video? Can you please make sure you are enabling runtime modifications for your desired prototype in the manager and check if your collider object has the GPUInstancerModificationCollider script attached?
     
  17. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,859
    hi louskrad,

    actually touch bending needs you to place individual game objects as it is triggered by colliders – just like you have already realized. so i hope it won't be a big deal to take all touched object out of the list of gpu instancer drawn instances and put it back when the touch bending animation has ended.
     
  18. ohbado

    ohbado

    Joined:
    Aug 13, 2014
    Posts:
    37
    Hello.
    GPU Instancer is a very good asset. But there is a problem.
    Using my shader, the prefab is black.
    Do you have a good idea?
    2018-08-23 07-29-14.png
     
  19. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there, and thanks!

    Are you using a vertex shader? If so, you might need to add the line

    Code (CSharp):
    1. UNITY_SETUP_INSTANCE_ID(v);
    to the beginning of your vertex function where v is your input.

    Please let us know if this solves the issue.
     
  20. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    156
    I added the Collider Modification Script to the Player, now as soon as the player leaves the the foilage, the foilage suddenly resets. If I add the modification script to the foilage, GPUI breaks.
     
    Last edited: Aug 23, 2018
  21. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    488
    We will be looking into making a compatible version after 0.9.0 update. Right now, there is not much we can do to provide an integration without a compatibilty update for GPUI and AFS.
     
  22. Alex3333

    Alex3333

    Joined:
    Dec 29, 2014
    Posts:
    342
    Good afternoon. I have several dozen terranes in the scene. Will your system work with a large number of cards? I also have a player spawn later. he is not immediately on the stage. The player can also get into the car. After that, the player's camera is turned off and the camera of the machine turns on. Waiting for your reply.
     
  23. LouskRad

    LouskRad

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

    GPUI works with multiple terrains. It also works with camera switching, and the included detail demo scene exemplifies how to do this - you just call the API to set the switched camera.

    Also, if you mean to instance cars, please note that skinned mesh support is currently not implemented and will be added in a future update. However, you can update transform data for your prototypes through our API, and a feature that will auto-update transforms will also be added in the next update.
     
  24. Raystorm

    Raystorm

    Joined:
    Mar 28, 2016
    Posts:
    9
    is there a way to have culling for objects that are not instanced?
    also, in the future, will object with rigidbody get instanced (at the very least, rigidbody for skinned mesh)? because i want to use rigidbody for enemies when skinned mesh is supported.
     
  25. LouskRad

    LouskRad

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

    GPUI does the necessary calculations for all sorts of culling on the GPU while rendering the registered instance prototypes. Since the non-instanced objects don't pass through this pipeline, it is not possible to use the GPUI systems to cull them. However, since GPUI does not touch anything other then its registered prototypes, you can use other usual methods to cull the objects that are not instanced; for example Unity's default frustum culling will still work, and you can bake the usual occlusion culling maps, etc.

    Full rigidbody support will come in the next update where we will introduce a feature that auto-updates transform data for instanced prototypes. This will also extend to skinned meshes when we implement them with a later update.

    Currently, however, objects with rigidbodies are also supported to an extent. As you can see in the Asteroids demo, you can turn off instancing inside a collider (e.g. around the space ship) to use rigidbody physics inside it. When the objects are again outside this collider, and when their rigidbodies go to sleep (i.e. when they stop), instancing is automatically turned back on them. Using this current feature is as simple as adding a script and a collider to a gameobject to define the zone for this. You can take a look at this video for an example of how to do this.
     
  26. wuxian0711

    wuxian0711

    Joined:
    May 2, 2018
    Posts:
    4
    Create empty project with unity 2018.2.7f1, import GPUInstance.package.
    then I switch project to android,set graphics api to vulkan for both pc and android in playersetting. also open [vulkan in editor]
    after that , I run the DetailInstancingDemo in editor mode,all models in scene is broken.
    and I will get many error in console like this:

    There are more uavs (9) than the maximum supported (8) in ComputeShader 'CSInstancedRenderingVisibilityKernel' kernel 'CSInstancedRenderingVisibilityKernelLOD3'.
    UnityEngine.Resources:Load(String)
    GPUInstancer.GPUInstancerManager:Awake() (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:79)
    GPUInstancer.GPUInstancerDetailManager:Awake() (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:31)

    when I build apk and run in android phone(support vulkan),I see nothing but skybox.
     
  27. wuxian0711

    wuxian0711

    Joined:
    May 2, 2018
    Posts:
    4
    or you should provide some video for how to build for android/ios?
     
  28. wuxian0711

    wuxian0711

    Joined:
    May 2, 2018
    Posts:
    4
    When I change some code in GPUInstancerConstants.cs
    like this: from #elif !UNITY_EDITOR && UNITY_ANDROID to #elif UNITY_ANDROID
    add

    #if SHARED_API_MOBILE && SHADER_API_VULKAN
    #define NUM_THREADS 8
    #else

    into *.compute file
    It works for android<vulkan>run in editor mode,but not work for apk run in android devices which support vulkan
     
  29. wuxian0711

    wuxian0711

    Joined:
    May 2, 2018
    Posts:
    4
    by the way, my mobile phone can run your demobuilds correctly
     
  30. LouskRad

    LouskRad

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

    For the Vulkan API, this error seems to be a Unity issue where it also takes unused UAVs into consideration. We will add this to the fixes for the next GPUI update, but for now, if you can send us a mail to support@gurbu.com, we can send you a package which can fix this issue.

    You should not need to modify any special build settings when targeting the Vulkan API. However, when building to the GLES 3.1, you need to tell the editor specifically that you are targeting the 3.1 platforms. You can do this by enabling the "Require ES3.1" checkbox under Edit->Project Settings->Player->Other Settings as seen below:

    requires31.png

    Also, when the target graphics API is OpenGL ES, the Unity Editor by default switches to an emulation mode. However, it currently can not emulate GLES 3.1. It emulates GLES 3.0 which does not support Compute Shaders. So currently it is not possible to test GPU Instancer with GLES 3.1 inside the Unity Editor. The only way is to get a build and test it on the Android device and use "No Emulation" while testing on Unity Editor (which will use your default graphics API in the editor):

    no_emulation.png

    Hope this helps.
     
  31. kokimoki

    kokimoki

    Joined:
    Jun 20, 2018
    Posts:
    4
    Hello, what you've done looks great! I apologize for the question .. I downloaded your demo but the results seem different to me ... do not get me wrong - the results are amazing ... they are just 4-5 times lower than your benchmark ...
    MySpec 2x Intel Xeon 5620 2.4mhz 8core 16 threads (8 years old) ,... NvidiaGeForce 1070Ti, 12 gb ddr3
    I tried every scene, ... read all comments in the forum, ... tried to be out of asteroids ring (do not compute physics),... with and without occlusion culling, ...on 10k asteroid scene you have 425fps ,..i have max 80fps,... at 200k asteroid you have 160fps,... and I maximum 70fps, ...
    I apologize if my question is very relative I just wonder from what may come thise difference?
    Thanks in advance.
     
  32. LouskRad

    LouskRad

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

    Thanks for your interest in GPUI. The results you are getting are indeed strange - with a 1070Ti, you should be getting a lot more than those numbers. Here are a few questions:

    (1) what is the resolution you are running the demo with? The benchmarks were done with 1080p (1920x1080) resolution.

    (2) do you see the expected difference with GPUI on and off?

    (3) were there any background processes when you ran the demo?

    also, what is the operating system you are using? (Although it should not make a difference).

    If you wish, you can send us further details of your tests at support@gurbu.com and we can investigate this.
     
  33. Sholms

    Sholms

    Joined:
    Nov 15, 2014
    Posts:
    81
    GurhanH likes this.
  34. tripodsgames

    tripodsgames

    Joined:
    Mar 19, 2016
    Posts:
    4
    Is V-Sync disabled?
     

    Attached Files:

  35. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    374
    Hi.

    After many attempts ... I give up. :(

    I followed the tutorial "GPU Instancer Tutorial - Prefab Manager (Part 1) - Prefabs in the Scene" with 2 prefabs that are NATURE plants. Very simple

    I have distributed in my scene 5,000 units distributed in no more than 200 meters.

    I followed the steps (very simple, very basic) and when I press PLAY none of those plants appear. All the empty land.

    I have looked for solutions, I have varied parameters ... and nothing. The same is true that these types of prefabs are not valid, although they do create prototypes for me.

    I do not know how to continue. I need help, thanks.
     
  36. LouskRad

    LouskRad

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

    Thanks for sharing this! We will take a look at the code and give feedback if needed.
     
  37. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Well, I was assuming @kokimoki was talking about the numbers from our demo builds, but if these numbers are from the editor, it indeed looks like v-sync is on for the project. Good catch!
     
  38. LouskRad

    LouskRad

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

    Here are a few questions for us to understand the problem so we may help you:

    (1) Do you see any warning or error messages in the console window (either when adding the prefabs to the manager or when entering the play mode)?

    (2) I'm assuming you are using the Prefab Manager since you mention the video tutorial, but just to make sure, are you using the Prefab Manager or the Detail Manager?

    (3) What shader(s) are you using in your Nature plant prefabs? are they custom shaders or Unity built in shaders?

    Also, if you wish, you can send us a detailed explanation of the steps you take to add the prototypes, any error messages, etc. at suppot@gurbu.com and we can investigate the issue from there.
     
  39. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    374
    3

    Change shader to Unity built. Ok. But... are very ugly. I will have to look for other plants.
    51.000 plant 12FPS without GPU Instancer to 22FPS with it. It is not expected, but good.

    Thanks.
     
  40. therewillbebrad

    therewillbebrad

    Joined:
    Mar 2, 2018
    Posts:
    151
    Has anyone tried this with amplify impostors?
     
  41. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    OK, this shows the issue is with the shader - but you should not have to switch to a Unity built in shader. GPUI can convert most shaders automatically, but looks like with your shader this could not be the case. May I ask what kind of a shader is it? A vertex/fragment shader or a surface shader? If you could give us some details about this shader, we can probably help you to make it work with GPUI.

    Also, please have in mind that ultimately the kind of prefabs you use will effect the final FPS output. The power of GPUI partly comes from eliminating the bottleneck that occurs when sending data from the CPU to the GPU with each draw call. GPUI minimizes these draw calls to a single draw call per every mesh-material combination - and uses indirect GPU Instancing techniques and compute shaders to do so - which is ostensibly a better solution than static batching, etc. However, you are ultimately limited by the power of your GPU when rendering the geometry. This means the total amount of triangles on the screen are still being rendered as good as the GPU that is rendering them. This is where GPUI's frustum and occlusion culling features come into play, both of which aim to reduce the rendered tri-count by ignoring unnecessary instances. If you use GPUI having this in mind, and design your scenes accordingly, you should get a lot more FPS from scenes.

    In short, you can get a lot more FPS from those 51k plants if you use prefabs with reasonable triangle counts and/or have LODs on them - and design your scenes to make good use of the GPU occlusion culling feature, etc. For further information on the occlusion culling feature, for example, you can take a look at this video tutorial on the occlusion culling feature. Also, please have in mind that the you can also use the detail manager for your terrains and have plant prefabs defined on it as well, and that the detail manager is designed specially for nature prefabs - and has some extra optimizations for their use-case scenarios (like spatial partitioning, etc).
     
    Barritico likes this.
  42. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Well, we have an eye on this as well. We will make some tests in the near future and share the results with you - and we might actually be considering an integration with this asset depending on the results of these tests.
     
    Neviah likes this.
  43. Amplify_Ricardo

    Amplify_Ricardo

    Joined:
    Jul 19, 2013
    Posts:
    2,387
    Be sure to let us know if you need anything ;)
     
    Neviah, LouskRad and GurhanH like this.
  44. Ramulos

    Ramulos

    Joined:
    Feb 19, 2017
    Posts:
    57
    +1 vote for amplify imposters integration
     
  45. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    511
    I am interested to utilize the Occlusion Culling possibilities of this product. Reading the documentation it seems you can only apply pre-created prefabs to this solution. Is it possible to take a procedural created game object and add it to the system for instancing and occlusion culling on the GPU?
     
  46. LouskRad

    LouskRad

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

    Thank you for your interest. This feature has been requested before, and we will be adding the required methods for using runtime generated game objects without pre-made prefabs to our API in a future update. The Occlusion Culling feature works on top of our rendering pipeline, so no additional work needs to be done there.

    However, it is still possible to use a workaround to achieve this, and you can take a look at the following code for an example:

    Code (CSharp):
    1. using GPUInstancer;
    2. using UnityEngine;
    3. public class AddRuntimeCreatedGameObjects : MonoBehaviour
    4. {
    5.     // Reference to the Prefab Manager in scene (no prefabs need to be defined on it, preferably disabled)
    6.     public GPUInstancerPrefabManager prefabManager;
    7.  
    8.     private void Start()
    9.     {
    10.         // Disable the manager
    11.         prefabManager.enabled = false;
    12.  
    13.         // Create a dummy go to create a prototype from
    14.         GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
    15.        
    16.         // Add the prefab as a prototype to the manager
    17.         prefabManager.prefabList.Add(go);
    18.  
    19.         // Generate prototypes for the prefabs
    20.         prefabManager.GeneratePrototypes();
    21.  
    22.         // Your instantiation logic. Uses the dummy go to identify the newly generated prototype.
    23.         // This example just instantiates objects at random positions inside a sphere with radius of 50;
    24.         // Replace this with how you want to generate your instances.
    25.         for (int i = 0; i < 1000; i++)
    26.             Instantiate(go, Random.insideUnitSphere * 10, Quaternion.identity);
    27.  
    28.         // Register the created instances in the scene to the manager
    29.         prefabManager.RegisterPrefabsInScene();
    30.  
    31.         // Enable Prefab Manager
    32.         prefabManager.enabled = true;
    33.     }
    34. }
    This creates a game object and uses that game object to define a prototype, rather than a pre-made prefab.
     
  47. LouskRad

    LouskRad

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

    As promised, we have just made some tests with Amplify Impostors, and the results are exciting. GPUI's shader conversion works out of the box for the impostors (both ASE shaders and default), and all the culling features work as intended. Here are some screenshots:

    ~27500 impostors rendered with GPUI (~1200 FPS on GeForce GTX 1060):

    AmplifyImpostorsGPUI_ON.JPG

    Occlusion and Frustum culling:

    upload_2018-9-24_23-46-41.png

    @Harekelas, @Ramulos, @therewillbebrad, @Amplify_Ricardo
     
  48. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    862
    Great to know they work fine together!
     
  49. Black_Raptor

    Black_Raptor

    Joined:
    Nov 3, 2014
    Posts:
    175
    I i have an problem when i spawn my camera after my terrain generation, GPU Instancer didn't gound my camera, and i dont understand the tutorial about Runtime Generation. Someone could help me please :) ?




    EDIT 1 : I fix the first problem ( Now GPUInster found my camera and work correctly )but now i have this error :

     
    Last edited: Sep 27, 2018
  50. LouskRad

    LouskRad

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

    If you spawn (or change) the camera that you want to use GPUI with at runtime, you can use the API to tell GPUI which camera to use. All you need to do is to call:

    Code (CSharp):
    1. GPUInstancerAPI.SetCamera(camera);
    Where "camera" is the camera component of the game object with your spawned camera. You can call this after the line where you spawn (or change) your camera.

    Please also note that you need to add reference to the GPUInstancer namespace for this to work in your script:

    Code (CSharp):
    1. using GPUInstancer;