Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

[RELEASED] GPU Instancer

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

  1. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    You can actually enable and disable GPUI's rendering of your prototype instances to achieve this effect, but currently the API would turn the mesh renderers back on when disabling GPUI's rendering of the instances. We could solve this by adding a parameter to the enable/disable API methods. If you can send us an email, we can send you the modified API.

    We have investigated this, and we have an idea what is causing the problem. We will provide a fix for the automated buffer initializing feature when the auto add/remove feature is used, but for now, you can try increasing the Extra Buffer size to your maximum instance count, which should in effect solve the problem.

    Thank you for the video. The reason why the tri counts raise when your ships move seems to be because of the particle effects you use for your ship thrusters. As for the culled ship in the render texture, I'm not sure how you set up the render texture (which instance are you rendering there, and how), but it can be caused by various things; there can be a culling logic in the ship's shader (the one you use for the selected ship GUI), or an LOD "culled" level. It can also be occlusion culled if you have an occluder in front of the camera that GPUI is using.
     
  2. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Before the draw call and the rendering, GPUI handles visibility in compute shaders and decides which instances will be rendered. You can take a look at how GPUI's Occlusion Culling works from this wiki - other than this, there is no extra steps taken to manage overdraws.
     
  3. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Hi there,
    this could be a Unity bug, or an conflict between the way the two assets handle the editor code. We will investigate this issue, and if it is GPUI related, we will provide a fix.
     
  4. LouskRad

    LouskRad

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

    Are you instantiating your WindZone during runtime? if so, you can simply call the following after you instantiate the WindZone:

    Code (CSharp):
    1. Shader.SetGlobalVector("_Wind", GPUInstancerManager.GetWindVector());
     
  5. LouskRad

    LouskRad

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

    Looks like for some reason the "GPUInstancer/Standard (Specular setup)" shader is not being included in your build. One reason for this might be the case when you use a no-game object, no-prototype workflow. You can simply use the GPUI version of the Specular shader on your original material and make sure it is in a resources folder to solve this.
     
  6. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Well this is more than I need. I suppose this is better than any batching including the new lwrp one.

    I have another question.

    GPUI supports Lod, however beside the shadow feature, would be beneficial to actually use Lod on a x86 architecture?

    This is not GPUI related but if you have some advices, I would super appreciate it: what tool do you use to profile and debug shaders in Unity?
     
    Last edited: May 16, 2019
  7. Rewaken

    Rewaken

    Joined:
    Mar 24, 2015
    Posts:
    79
    Thanks, Do I need to submit project to you guys ?
     
  8. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    277
    Hi! Nope, windzone is in the scene.
     
  9. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Independent of the CPU architecture, the graphics cards in the end render geometry. LODs help you with lowering the final geometry that you render, so they are in principle advisable - however, please keep in mind that each LOD will increase the buffers (and draw calls), so I would recommend using them if the gain from lowering the geometry is worthwhile.

    As for profiling and debugging shaders, you can use the Frame Debugger or a separate tool like RenderDoc.
     
  10. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Hi there, and yes, it would make it faster for us to test if you can send us a sample project (excluding any third party assets, of course).
     
  11. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Are you using a Spherical WindZone? Please keep in mind that only Directional WindZones are supported out of the box. If this is not the case, please send us a small sample project demonstrating the problem so we can analyze it.
     
  12. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    thanks, I mentioned the CPU architecture meaning: "all the graphic cards that are used on this architecture" as substitute of "I understand why the LOD may be useful on mobile". Are vertices still a problem nowadays even on an Intel HD 4000? As you said LOD may have the side effect to actually use more memory right?
     
    Last edited: May 16, 2019
  13. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    77

    Hi LouskRad!

    Thank you very much, i cannot believe a missed it that darn particle system, it crippled it all, thanks again! Regarding the automated buffer initializing for now i am doing it manually increasing the extra buffer size did not helped, but i am good till the fix is coming. About the render texture i went with a static solution, recording the hologram animation of a ship into a spreadsheet and animate that instead of using a camera in an overhead position to provide real time render so i do not need to worry about any kind of culling. The important thing is that a larger engagement's FPS is not crippled by rendering any more thanks to GPUI! This tool is Fantastic and you guys are Amazing!

    Many Thanks!
     
  14. Bamfax

    Bamfax

    Joined:
    Jun 12, 2016
    Posts:
    51
    Hi LouskRad,

    thanks again for the solution, that did it.
     
  15. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    81
    Hi,

    I am trying to use GPUInstancer Integration with Map Magic, but I have a problem when using Map Magic's Shift World (floating origin) setting. The details being rendered by GPUInstancer do not follow the shifted terrains. There doesn't seem to be an option to enable floating origin on the GPUI MapMagic Integration.

    Thanks.
     
  16. Dam-Pete

    Dam-Pete

    Joined:
    Jun 11, 2010
    Posts:
    40
    Hi... Are there any plans for allowing the vegetation to interact with physics? For instance the grass reacting or being flattened by a vehicle or a character moving through it...
     
  17. LouskRad

    LouskRad

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

    thank you for this feedback. We will look into adding the floating origin feature to the MapMagic Integration as well.
     
  18. LouskRad

    LouskRad

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

    We currently do not have this in our roadmap; so at this point I cannot give you concrete information on if we will implement this - and if so when and in what form it will be implemented.
     
  19. Dam-Pete

    Dam-Pete

    Joined:
    Jun 11, 2010
    Posts:
    40
    Alright, thanks for your response. How about instantiating on runtime? I create terrains during runtime, is it possible to activate GPU Instancer on a terrain created during runtime?
     
  20. Bamfax

    Bamfax

    Joined:
    Jun 12, 2016
    Posts:
    51
    Hi LouskRad,

    thanks for taking on and always answering all our questions all the time. This is really a great help all the time!

    If I may add yet another one. I would need to increase the far clip plane of the camera referenced by GPUInstancerPrefabManager. Playing around with it, clip plane changes on the referenced camera are reflected immediately, which is awesome. What then did not seem to take effect was extending the far clip plane to something greater than ~560 units. Nothing complained, but GPUI objects did not get rendered beyond that range.

    What can I do to get the far clip plane to extend out further?

    Another topic we had touched before: Is it possible to change a prototype instancecount during runtime, in order to limit culling, occlusion, rendering to this max count of current instances of the prototype?
    Currently I am increasing prototype buffers by some blocksize (e.g. 1024) as needed and refilling computebuffers (to play it safe using a standard/common/expected workflow). It would be nicer to preallocate buffers to the maxsize (e.g. 65k) and cut off all work on the currently needed highest instance number. Calling it 'highest instance number' on purpose (and not instancecount), since I will also be carrying empty / cleared "nothing to do here" buffer idx's over to GPUI buffers.

    An idea for the end: Something I always had on my wishlist, not important but would be a nice feat: If GPUI objects could block sun flares (in a gameobjectless workflow), that would be awesome to have :).

    Thanks again for your support.
     
    Last edited: May 22, 2019
  21. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Hello, my colleagues are wondering if the following files should be versioned and shared or just kept locally.

    upload_2019-5-22_15-8-53.png
     
  22. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    I wonder if it's correct that the GPUInstancerPrefab monobehavior gets serailized in the prefab itself

    upload_2019-5-22_17-54-49.png
     
  23. itsnottme

    itsnottme

    Joined:
    Mar 8, 2017
    Posts:
    73
    Hey, would setting the prefabs to static affect the asset? Do I just set it as lightmap and reflection probe static?
     
  24. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Yes, runtime instantiation is supported. You can check the included AddRemoveTerrainsRuntime demo scene for an example usage.
     
  25. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Thanks!

    You can change the Max Distance setting of the Prototype to a number where you want distance culling to happen. Also, please make sure that you do not define a prototype with and LOD group that has a "culled" LOD level if you want to let the manager handle distance culling. If you are using a custom shader, there are some rare cases where shaders discard pixels if the rendered object is at above a distance from the camera; you might also want to make sure that your shader does not do this.

    We have actually added a new API method for this purpose recently (with v1.1.2). The SetInstanceCount API method can be used to discard instances that are indexed higher than the given index count.

    The blocking if sun flares would require colliders, and in a no-GO workflow, that would require a seperate system that manages colliders (e.g. a collider pooling system). Such a system is not currently in our roadmap, but it is also in our wishlist :)
     
  26. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    These are the data objects that hold the settings for the defined prototypes in a manager. You should keep them versioned otherwise the prototype settings will be lost and the manager will generate a new prototype with the default settings.

    It is the expected behavior, however, the GPUInstancerPrefab in your screenshot seems to have lost its prototype reference. You can take a look at this video tutorial where I also talk about this:

     
  27. LouskRad

    LouskRad

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

    settin the prefabs to static would not change anything for GPUI. To read more about the difference between (static) batching and GPU instancing, you can take a look at this wiki document.

    Also, please keep in mind that GPUI does not support baked lighting on its defined prototypes.
     
  28. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    well I guess the second is because I do everything gameobjectless?
     
  29. itsnottme

    itsnottme

    Joined:
    Mar 8, 2017
    Posts:
    73
    Oh so there is no reason at all to set it to static?
     
  30. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    If you define the prototype at runtime, the GPUInstancerPrefab script would not be added to the original prefab. It could be the case that you added the prefab to an active manager, then either deleted the prototype SO or it was not committed to the version control that you checked out your project from.
     
    sebas77 likes this.
  31. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Yes, no reason at all in terms of rendering.
     
  32. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Hi everyone.

    We have just submitted the Crowd Animations extension package to the Asset Store. It should be released after the Asset Store team is done with their reviews.
     
    ftejada and Bamfax like this.
  33. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Got you, now I know what to do. We do drag and drop it and then delete it to be sure that the shaders are converted
     
  34. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    In the scene view the grass looks like this, is it normal (I am talking about the culling)?
     

    Attached Files:

  35. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Hi Sebastiano,

    It looks like you have increased the Min. Culling distance slider:

    upload_2019-5-27_14-0-53.png

    I also mention the global version of this setting in the prefab manager video:

     
  36. Bamfax

    Bamfax

    Joined:
    Jun 12, 2016
    Posts:
    51
    LouskRad or GurhanHazinedar, may I ask you for some light into the Shader Bindings workings? I just edited my custom shader to include the GPUI code. Instancing Prefabs (gameobjectless) with this Material/Shader then gave me the error "can not find instanced shader for...". Then I did as sebas77 mentioned above (put GPUIPrefabManager and prefab instance into the scene, registered instance in GPUIPrefabManager, (had removed GPUI code I added before). Strange enough, the shader was not autoconverted.
    Then I manually included the GPUI code again, and then the "can not find instanced shader for..." error disappeared, the shader worked.
    So some question I do have :)
    - How can I let GPUI know that "this new custom shader" is already manually prepared and adapted for GPUI?
    - When is autoconversion happening?
    - Can I trigger autoconversion manually? (not needing to register objects in the scene)

    Thanks again.

    Well, one more: I just quickly tried to .SetTexture() and .SetBuffer() to the "custom now-GPUI'ized material" and noticed these did not end up in the material. You are probably cloning the prefab material before? So for adding custom ressources to a material I guess I need to go through the VariationsBuffer functions?
     
    Last edited: May 27, 2019
  37. Bamfax

    Bamfax

    Joined:
    Jun 12, 2016
    Posts:
    51
    Ok, found it:
    Now, how do I do find the correct Prefab/Prototype Material to do a .SetTexture() at runtime? Having taken a look at the Variationsbuffer docs, as this focuses .SetBuffer(), I am still looking for a way for a .SetTexture().

    Thank you once again.

    ps.:
    This works quite well. A variant with saving the additional proxy creation would surely be great, when only texture swapping is needed.
    Code (CSharp):
    1. GPUInstancerAPI.ChangeMaterial(_manager, _prototype, sameMatWithSwappedTexture);
    Using the shader now in GPUI gives a me a glitches. It is an instanced surface billboarding transparency shader. Depending on the view angle and distance, parts of the texture disappear or are looking garbled. It used to work before in another DMII environment, so I guess there is some further GPUI specifics I need to consider?
    Looks like one type of the glitches are coming unity_InstanceID flipping / not used correctly or not being picked up correctly.
     
    Last edited: May 29, 2019
  38. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Hello,

    although I am not sure what, something is broken with the gameobjecless flow: the GPU bindings result often broken on new workspaces (syncing a fresh version of the project) even if I committed all the files. People are forced to drag an drop the prefabs at least once and this is not working anymore for us, as also the building machine has the same issue.

    How to fix it?
     
  39. LouskRad

    LouskRad

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

    Adding a prefab with a material that uses the shader to a manager certainly works. However, if you've updated to the latest version, you can right click on your shader in the Project Window and choose GPU Instancer->Setup Shader For GPUI also for the same effect. If the original shader is GPUI compatible, this would be auto detected and GPUI would internally mark the shader as one that does not need conversion.

    About changing the material texture, using the ChangeMaterial API method would indeed work. As for the glitches, my guess would be that it is a shader related issue. We can take a look at the issue if you could send us a simple sample project demonstrating the glitches.
     
  40. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Are you sure that the whole GPUInstancer/Resources/Settings folder and the GPUInstancer/PrototypeData folders are both in your source control? If not, they need to be for GPUI to keep track of the prototype details, shaders being used, etc.
     
  41. Bamfax

    Bamfax

    Joined:
    Jun 12, 2016
    Posts:
    51
    Hi LouskRad,
    thanks again for your hints.

    For a .SetTexture(), what other ways could I take for setting a texture? From time to time, I need to do some .SetTexture()s quite often in my project, about every 10 frames or so. I saw that it performs quite well, but just looking for alternate ways without needing to create a proxy gameobject.

    Thank you for your offer of checking my shader. Let me have another go at it, and if I don't figure it out, I will sent it over. Much appreciated!
     
  42. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,349
    This has got to be one of the best purchases I've ever made on the Asset Store. It's very intuitive, non-destructive to objects in the scene, and above all delivers on the amazing performance promise in the videos. I was honestly a bit skeptical before buying, but the prospect of rolling my own system to improve terrain and forest rendering was proving too much of a time sink, so I jumped on this. Really glad I did. It took my dense forest scene from 5fps up to 70+ :eek:, and smoothed out all the little data hiccups and micro-stutters that normal terrain objects contribute to. Holy Smokes!

    I do have a question about multi-terrain useage however. When using this on a single terrain the performance increase is wonderful. When using on a second terrain in the same scene there is a pretty drastic fps cost as each separate manager must have it's own compute overhead. Each of my terrains has identical prototype/tree/detail objects, and I was wondering if there is a way to use one manager for multiple terrains in this case?

    Alternatively, does it make more sense to convert terrain trees into scene objects and use a scene prefab manager for those tree objects instead? This should be fairly straightforward for me to test but I wanted to get your opinion on this before writing a terrain tree-->scene object conversion tool.
     
    Akshara likes this.
  43. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    100% sure

    Edit: Every time we create a new shader, we are forced to drag and drop a prefab using it in the Prefab Manager. Loading the prefab at run-time without this step, would result in an invisible mesh. Help please.
     
    Last edited: May 31, 2019
  44. Bamfax

    Bamfax

    Joined:
    Jun 12, 2016
    Posts:
    51
    Regarding the shader, the flickering is now gone, it came because I was not using the gpuiTransformationMatrix. Adding that to the wiki would be quite useful for those which are as me that fluent writing shaders. What I am still working on is the garbled textures. Starting when rendering some more instances, (between 250-500 somewhere), UVs of some instances seem to get mixed up. UVs are also adapted based on the instanceID in the vertex shader.

    Code (CSharp):
    1. SubShader{
    2.     Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True" }
    3.     //LOD 200
    4.  
    5.     CGPROGRAM
    6.         #include "UnityCG.cginc"
    7.         #include "../../../GPUInstancer/Shaders/Include/GPUInstancerInclude.cginc"
    8.         #pragma instancing_options procedural:setupGPUI
    9.         #pragma multi_compile_instancing              
    10.  
    11.         #pragma surface surf Standard noshadow alpha:fade noshadow nofog vertex:myvert
    12.         #pragma target 3.5
    13.  
    14.         struct Input {
    15.             // someMoreVars
    16.             UNITY_VERTEX_INPUT_INSTANCE_ID
    17.         };
    18.  
    19.         void myvert(inout appdata_full v, out Input o)
    20.         {
    21.             UNITY_SETUP_INSTANCE_ID(v);
    22.             UNITY_INITIALIZE_OUTPUT(Input, o);
    23.             UNITY_TRANSFER_INSTANCE_ID(v, o);
    24.  
    25.             uint myInstanceId;
    26.  
    27.             #ifdef SHADER_API_D3D11
    28.             #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    29.                 myInstanceId= gpuiTransformationMatrix[unity_InstanceID];
    30.             #else
    31.                 myInstanceId= 0;
    32.             #endif
    33.             #endif
    34.  
    35.             // someMoreCode
    36.         }
    37.  
    38.         void surf(Input IN, inout SurfaceOutputStandard o)
    39.         {
    40.             UNITY_SETUP_INSTANCE_ID(IN);
    41.  
    42.             uint myInstanceId;
    43.  
    44.             #ifdef SHADER_API_D3D11
    45.             #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    46.                 myInstanceId= gpuiTransformationMatrix[unity_InstanceID];
    47.             #else
    48.                 myInstanceId= 0;
    49.             #endif
    50.             #endif
    51.  
    52.             // someMoreCode
    53.  
    54.             o.Albedo = color.rgb;
    55.             o.Metallic = float(0.0f);
    56.             o.Smoothness = float(0.0f);
    57.             o.Alpha = color.a;
    58.         }
     
    Last edited: May 30, 2019
  45. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    139
    Hi @LouskRad Colour variations aren't working for me in either of the Demo Scenes :-

    ColorVariations
    or
    PrefabsWithoutGameObjects

    Am running 2019.1.4 and the latest Asset Store version of GPUI in a fresh project on a Mac, there are no error messages to help diagnose.

    Any ideas?
     
    Last edited: May 31, 2019
  46. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    102
    Is there a way you can set multiple settings for one terrain? For instance i'd have two different scenes that use the same terrain but i want different detail density for the grass for each scene.

    Currently when you create a instancer detail manager it auto sets the terrain and terrain data, so since it's the same terrain for both scenes, it just auto sets the previous terrain data.
     
  47. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    102
    New Question: I know the lowest version for this is 5.6.5 but i'm sure at some point it worked in 5.6.0 and since i have a project in that version, I am looking to use this for that project.

    So the question is can i use this asset in 5.6.0 and if not right out of the box, what changes would need to be made for it to function properly?
     
  48. farzaan090

    farzaan090

    Joined:
    Jul 23, 2018
    Posts:
    15
    Is it possible to adjust the wind settings on trees and detail when using GPUI Prefab Instancer? I am placing the trees/detail onto an object, not a terrain so I am unable to use the Tree/Detail manager. However, this causes the trees to shake violently and ignore any wind settings I have in the scene itself.
     
  49. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    46
    Hi @LouskRad I have a Day/Night cycle in my game, which are two directional lights pointing in opposite directions assigned to a rotating parent.

    Here's the issue I'm seeing. As the directional lights reach a flat angle, the grass goes pretty dark despite my terrain and props lighting nicely. I was thinking a 'emissive color' or 'light wrapping' option on the foliage shader might fix this? Though I wouldn't know how to add that. Ideas?

    upload_2019-6-2_11-17-44.png
     
  50. LouskRad

    LouskRad

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

    you can refer to the demo scene in the attached package as an example usage of how you can do a .SetTexture() by accessing the internal code to make it faster.
     

    Attached Files: