Search Unity

[RELEASED] GPU Instancer

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

  1. Shii

    Shii

    Joined:
    Nov 23, 2014
    Posts:
    31
    Yes I have Test Both Eyes for VR Occ. Culling option enabled and this issue has nothing to do with Unity version or Unity camera projection matrices bug.
    I analyzed the code and found that GPU Instancer calculates Frustum culling with matrix from Main Camera position when Occlusion Culling is disabled and it using only left eye position for Frustum culling calculation when Occlusion culling is enabled. I emailed you more details and code examples with a fix.
     
  2. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    95
    Hello!

    We're getting quite poor CPU performance from GPUInstancerManager.LateUpdate...

    Our use case is to render basically everything through GPUI, which is really fast, unless we add a lot of prototypes.
    We have hundreds of prefabs setup, most with LODS.
     
  3. theunknownuserx

    theunknownuserx

    Joined:
    Mar 22, 2018
    Posts:
    6
    Hello nice Asset, but can you please add posiblity to add deatial manager under Unity Terrain as child!!!!!

    , cuz if splitting Terrain into Scenes for loading on demand, the connection between Terrain is lost. Thank you!

    p.s: One click button to remove detail managers from all terrains will be good aswell for testing purpose!
     
  4. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    We are looking for ways to improve CPU performance with high number of prototypes, however high CPU usage is mainly caused by Compute shader calls which run single threaded. It is better to reduce the amount of prototypes starting with the ones that have the lowest instance counts. In most cases rendering everything with GPU Instancer is not a good practice, since it is not designed for this purpose. You should only use it for objects that have high instance counts.

    Hi there,
    thank you for the feedback.
    We will look into adding more options to the menu items.
     
  5. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    95
    Thanks for getting back to me so quickly!
    We're using this approach because the player can make any amount of anything, within only gameplay restrictions, on a very large map.

    If I'm able to optimize it at all, I'll be sure to share my changes.
     
  6. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    One idea is you could give the player the option to decide how to spawn objects.
    Maybe tell them use "normal" unless you plan on placing a very large amount/high density, in that case, use "instancing' or whatever name you give it, and it's just a tick option for them
     
  7. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    95
    Also with GPUIs occlusion culling, do instanced pieces cull other instanced pieces?
     
  8. vlastan

    vlastan

    Joined:
    Nov 15, 2015
    Posts:
    49
    @GurhanH After updating to unity 2021.2.5f gpui instancer is not working anymore with HDRP.
    Here's the error that pops up when gpui is initialized and every frame after:

    Code (CSharp):
    1. CSInstancedCameraCalculationKernel.compute: Kernel at index (0) is invalid
    2. UnityEngine.StackTraceUtility:ExtractStackTrace ()
    3. GPUInstancer.GPUInstancerUtility:DispatchCSInstancedCameraCalculation<GPUInstancer.GPUInstancerRuntimeData> (UnityEngine.ComputeShader,int[],GPUInstancer.GPUInstancerRuntimeData,GPUInstancer.GPUInstancerCameraData,bool,bool,bool) (at Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:551)
    4. GPUInstancer.GPUInstancerUtility:UpdateGPUBuffer<GPUInstancer.GPUInstancerRuntimeData> (UnityEngine.ComputeShader,int[],UnityEngine.ComputeShader,int[],GPUInstancer.GPUInstancerRuntimeData,GPUInstancer.GPUInstancerCameraData,bool,bool,bool,bool) (at Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:370)
    5. GPUInstancer.GPUInstancerUtility:UpdateGPUBuffers<GPUInstancer.GPUInstancerRuntimeData> (UnityEngine.ComputeShader,int[],UnityEngine.ComputeShader,int[],System.Collections.Generic.List`1<GPUInstancer.GPUInstancerRuntimeData>,GPUInstancer.GPUInstancerCameraData,bool,bool,bool,bool) (at Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:338)
    6. GPUInstancer.GPUInstancerManager:UpdateBuffers (GPUInstancer.GPUInstancerCameraData) (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:567)
    7. GPUInstancer.GPUInstancerEditorSimulator:CameraOnBeginRenderingSRP (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Camera[]) (at Assets/GPUInstancer/Scripts/GPUInstancerEditorSimulator.cs:180)
    8. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    In this case, it happens with the detail manager when simulation is started in the editor, but the similar error pops up with the tree manager in play mode.
     
  9. racesofwar

    racesofwar

    Joined:
    Dec 14, 2019
    Posts:
    1

    Help plz me
     
  10. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Yes they do. Since GPUI uses the depth texture for occlusion culling, every object that writes to the depth becomes an occluder and an occludee.

    Looks like Unity did not import the Compute Shader files correctly while updating. Try right clicking and selecting Reimport on the folder GPUInstancer/Resources/Compute.

    Hi there,
    First please make sure to upgrade to the latest GPU Instancer version from Package Manager. Then open the Shader Graph window for the shader (SyntyStudios/PolygonTrees_LOD) and add the GPU Instancer Setup node as described in this documentation.
     
    VirtusH likes this.
  11. vlastan

    vlastan

    Joined:
    Nov 15, 2015
    Posts:
    49
    Reimporting Compute folder solved the issue, thanks!
     
  12. daedal

    daedal

    Joined:
    Dec 19, 2013
    Posts:
    31
    I finally looked into this issue. While in the editor and when not viewing the GPUI Prefab Manager in an inspector tab, GPUInstancerSettings.SetDefultBindings was not getting called at runtime. It was only being called while not in play mode when UnityEngine.XR.XRSettings.enabled would be false. So CalculateCameraData was getting the wrong projection matrix.

    I solved the issue for me by adding a SetDefultBindings call to one of my OnEnable methods.

    Edit: I learned that this was the result of setting "Reload Domain" in the editor settings to false. I'll still leave it off to save time and continue to use that SetDefaultBindings call.
     
    Last edited: Dec 22, 2021
    GurhanH likes this.
  13. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    Hello I have a question about the occlusion system and instancing. Just wondering if for example you are procedurally building a town with say multiple prefab buildings and those buildings have other prefabs inside of them like furniture or something, for the dynamic occlusion system, what prefab(s) should be put into the manager? Would it be the prefab of the building, or each of the furniture, or both?
     
    Last edited: Dec 25, 2021
  14. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    I strongly recommend you to read the Best Practices article, which explains these in detail.
    As for your question, you should use the furniture as prototypes and only add the buildings if they have high instance counts.
     
  15. HairyBallsagna

    HairyBallsagna

    Joined:
    Jan 12, 2020
    Posts:
    10
    Some people are saying it doesn't work too well with HDRP, can someone give feedback on how it works with HDRP
     
  16. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    339
    Hi,the LOD cross fade in GPUInstancer HDRP looks odd to me.

    is there a way to make it look like the cross fade in unity LOD Component?
    I tried adjusting "LOD Fade Transition Width", didn't help.

    I'm using
    unity2021.2.3.f1
    HDRP12.1.1
    GPUInstancer1.6
    vegetation shaders are from The Vegetation Engine (not sure the version,but close the newest one)
    I tried using hdrp lit shader for vegetations, the results looked same.

    edited in 2022.1.4:
    I tried upgrade to GPUInstancer1.7,still the same result.

    GPUInstancer cross fade:
    GIF 2022-1-3 20-52-10.gif

    unity LOD component cross fade:
    GIF 2022-1-3 20-54-22.gif
     
    Last edited: Jan 4, 2022
    PutridEx likes this.
  17. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    and thank you for the feedback.

    I was able to recreate the issue and it looks like there was a miscalculation for the dithering on HDRP. Can you please replace the code for the LODDitheringTransitionGPUI method as follows and see if it solves the issue:

    GPUInstancer/Shaders/Include/GPUInstancerInclude.cginc at line 79:
    Code (CSharp):
    1. void LODDitheringTransitionGPUI(uint2 fadeMaskSeed, float ditherFactor)
    2. {
    3.     if (LODLevel >= 0)
    4.     {
    5.         uint4 lodData = gpuiInstanceLODData[gpui_InstanceID];
    6.  
    7.         if (lodData.w > 0)
    8.         {
    9.             float fadeLevel = floor(lodData.w * fadeLevelMultiplier);
    10.  
    11.             if (fadeLevel > 0)
    12.             {
    13.                 ditherFactor =  (frac(fadeMaskSeed.y) + fadeLevel) * 0.0625;
    14.                 float p = GenerateHashedRandomFloat(fadeMaskSeed);
    15.                 float f = ditherFactor - p;
    16.                 if (lodData.z == uint(LODLevel))
    17.                     f = -f;
    18.                 clip(f);
    19.             }
    20.         }
    21.     }
    22. }
    We will also include the fix on the next update.
     
  18. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    339
    It works! thank you for the fix!
     
  19. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    57
    Hi, does GPUI support reflection probes?
    There is one reflection probe in the scene and here is the result with the same prefab instanced with GPUI and without:

    upload_2022-1-6_4-7-26.png

    Using URP 10.7, Unity 2020.3.25 and VR Single Pass Instanced.
     
  20. GurhanH

    GurhanH

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

    You can read the Known Limitations for information on lighting limitations. It also includes reflection probes:

     
    pierre92nicot likes this.
  21. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    339
    PVVVWZTW0~(`E~}S94]YH}I.png

    Hi,i tried the billboard generator in GPUInstancer for HDRP.

    it looks like billboards lost all ambient light in shadow area.

    i tried HDRP Lit shader and The Vegetation Engine shaders for trees in a new project,both of them generated same result.

    there are not too much shaders we can use for trees in hdrp, i hope at least these two could work soon.

    i tried in:
    Unity2021.2.3 + HDRP12.1.1 + GPUInstancer1.7
    Unity2021.2.7 + HDRP12.1.2 + GPUInstancer1.7


    And 2 suggestions for billboard in GPUInstancer:

    1. please add shadow casting ability for billboard, the shadow keep popping in and out because the lod switching between mesh and billboard.
    it is really annoying when it's dawn.

    2. if you could bake self shadows in a texture channel (like alpha channel in normal map)to fake the shadow that will be great,
    for now the baked billboard looks kinda flat compare to Amplify Impostor because it dose not have self shadow.
     
  22. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    and thank you for the feedback.
    You can use Amplify Imposters instead of the generated billboards if you wish, GPUI works with it. You can read about it from the online documentation. Since main focus of GPUI is not billboards, we prefer to keep it simple and integrate to more complex third party solutions when necessary.
     
  23. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    339
    Amplify Imposters suffers totally same problem like the billboards in GPUInstancer since HDRP12 and they don't have any news that they will fix it...
    that is the reason i'm playing billboards in GPUI.
    and the billboards in GPUI have its own advantage as it only rotate in Y direction which is much better for trees than Amplify Imposters.
    don't give it up,please...
     
  24. Deleted User

    Deleted User

    Guest

    Experimenting with MapMagic 2 and multiple tiles; I am working with the Integration plugin, works great ! I was wondering if it was possible to have the live preview while working in Edit mode, like when I use the Details Manager in standalone mode ? Thanks !
     
  25. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    Having a "slight" issue with GPUI, Occlusion Culling seems to be entirely broken for us in Unity 2020.3.19f1 using HDRP 10.6 (Our first install, so version might or might not be the issue).

    Essentially using the GPUI HiZ generator debug shows a pure black texture here and the Unity Depth Texture array is of size 1x1. https://i.gyazo.com/d563d0c8d75aca260144ba6faccdb122.png

    What could be the issue here? We're considering of replacing our own solution with GPUI but without occlusion culling it's slower than our custom solution (and expecting it to be faster with it).
     
  26. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    MM2 integration currently does not have an editor simulation for details. We will look into adding it in a future update. Thank you for the feedback.
    Hi there,
    GPUI uses the Unity Depth Texture to make calculations for Occlusion Culling. I am not sure what would cause it to be a black 1x1 texture in your project. If you can email us a sample project where we can see this issue, we can investigate.
     
  27. jukibom

    jukibom

    Joined:
    Aug 31, 2015
    Posts:
    54
    Hey,

    I'm trying to get GPU Instancer to play ball with Map Magic 2 integration and floating origin - I was under the impression that trees should automatically snap to the transform of the terrain when an FO correction occurs but that doesn't seem to be the case, what's the process for this? There are no floating origin options in the MM2 integration object, and the `Use Floating Origin` checkbox in the runtime-spawned tree manager has no effect. They seem to spawn in the correct position but disappear (or rather, doesn't move with the world) when a correction occurs

    I use additive scenes for different environment conditions so the integration is constructing the prefab and tree manager in a separate (active) scene, is that a problem?

    upload_2022-1-12_11-8-37.png

    In the above, the `World` object is the one being manipulated by the floating origin script.
     
  28. Deleted User

    Deleted User

    Guest

    Thanks ! Would there be a "quick hack" in the meantime ?
     
  29. Wawwaa

    Wawwaa

    Joined:
    Sep 30, 2017
    Posts:
    165
    Hey there! I've got my national government tech support for my game. He is the trailer:



    And 3 more recent views:







    GPUInstancer has a great part in this.
     
  30. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I have issue with GPU Instancer with Unity 2021.2.8f1.

    The same shader (variant) works fine in Unity 2021.2.7f1 but not in Unity 2021.2.8f1.

    Upon looking at the Unity release note, URP version has changed from 12.1.2 to 12.1.3
    perhaps this has to do with the problem?

    The issue is that the instanced elements shows all right in the center of the camera screen instead of the designated position I have set them.

    Nothing has changed in terms of shader content and how I use them. Just Unity version number from 2021.2.7f1 to 2021.2.8f1. No apparent errors.
     
    iceb_ likes this.
  31. Sterner

    Sterner

    Joined:
    Nov 11, 2012
    Posts:
    33
    Having same issue with HDRP, only in build
     
  32. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Oh yeah, The same. I forgot to mention that it only happens in build as well.
     
  33. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    95
    Hi again,
    I have a few questions about how gameobject-less prefab prototype rendering is handled.

    Say you have two prefabs that both render the same mesh with the same material, but each has it's own prototype.
    In the gameobject-less workflow, is that compressed to a single call?
    Or would that only occur if the same mesh+mat object is a nested prefab with a prototype component on it?
     
  34. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    I also have display issues with gpuinstancer in URP 2021.2.8, (only in builds, not editor) objects look like they're not rendering pixel updates, and you're staring into the depths of infinite.
     
    Last edited: Jan 18, 2022
  35. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I think this has to be known issue for 2021.2.8f1, I hope GUP Instancer author can answer this soon.
     
  36. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    MM2 integration currently does not have floating origin support. We will look into adding it in a future update. Thank you for the feedback.

    I can't think of an easy fix. However if you are not generating terrains at runtime, you can add the detail managers on the terrains instead of using the MM2 integration and then use the simulation feature from the managers.

    Hi there,
    Every prototype has their own separate draw calls. GPUI does not check if different prototypes have same mesh+mat combinations. However you can use nested prefabs to combine draw calls. You can read about it from the Best Practices documentation.
     
  37. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    It looks like Unity is arbitrarily stripping the procedural instancing shader variants from builds for some shaders on 2021.2.8f1. I tried changing settings to avoid this but it doesn't work. Hopefully Unity will fix this soon.

    I attached a script to this post which might solve the problem. You can find it in the attachment. After adding this script to your project, select Tools -> GPU Instancer -> Temp Unity 2021.8.2 Bug Fix. This should edit the generated GPUI shaders and hopefully add the procedural instancing variants on builds.
    Note: This is a temporary hack, so you should delete this script when Unity fixes this issue or when we provide a permanent solution.

    Since this is a Unity bug we can not do much about it on our side. I highly recommend to use the LTS version of Unity. These in between Unity version bugs are usually a mess to deal with and most of them get fixed on LTS versions.
     

    Attached Files:

    Sterner likes this.
  38. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    Thank you, will try that script. I would use LTS except 2021.2 have a whole bunch of cool new features that are fairly important.
     
  39. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    Just tested the 2021.2.8 temp fix script, works!
     
  40. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Has this bug actually been reported ? If not, I am not sute if Unity even knows about it.
     
    iceb_ likes this.
  41. Deleted User

    Deleted User

    Guest

    Thank you for the suggestion; not at runtime but with MapMagic 2 in the editor; I will try to hack it around. If you could bring this in the next update eventually it would be much appreciated.
     
  42. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Yes, I reported it.
     
    castor76 and Sterner like this.
  43. MeHigh94

    MeHigh94

    Joined:
    May 21, 2019
    Posts:
    2
    Hi there,

    I am trying to use GPU Instancer on mobile(android) hoping to increase performance on my game, but after trying to use it( before i had like 20-25 fps, now it gets stuck at 10, and checking profiler, i see this:
    upload_2022-1-20_15-30-55.png

    Any idea on how to fix it?

    I had a build before GPUI and it was fine, let me know if you need more screenshots, details!

    Thanks!
     
  44. GurhanH

    GurhanH

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

    Can you please email us detailed information on how to recreate this issue and a sample project following this guide so we can investigate the issue?
     
  45. HajiyevEl

    HajiyevEl

    Joined:
    Feb 19, 2020
    Posts:
    47
    Hi! Found this video on youtube
    and wanted to do the same only with GPUI. Result? I had 2FPS with GPUI when on project from ytube video gives me 40FPS on PC and 30FPS on mobile (both with 1M instances of grass). Can you please tell me why it is? Don't you both use Drawmeshinstancedindirect?
     
    Last edited: Jan 20, 2022
  46. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    GPUI is not optimized to render high amount of single triangles as instances. We explicitly advise against it (see Best Practices). You can get better performance when you use programs designed and limited for a very specific case. GPUI is a generic solution with many features, but it will not always perform better especially when you use it for cases that it is not designed for. Also if you made your comparison with a more complex mesh or shader, it will make a big difference with high instance counts (e.g even a quad will double the total geometry compared to a triangle).

    In any case if you have a use case where you think GPUI is not performing well, you can email us a sample project and we can investigate.
     
  47. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Please let us know of the public link to the issue tracker, once it is available. We will rally there and vote for it.
     
    ScottJak, GurhanH and brute- like this.
  48. roundyyy

    roundyyy

    Joined:
    Dec 23, 2019
    Posts:
    112
    Hi, Do you know how can I make generated billboards to fade out/in smoothly, not pop up? I'm using cross fade shaders, my tree meshes fade out/in with dither no problem, but billboards not. There is no LOD groups or anything like that, just one mesh tree, then billboard
    Thank you
     
  49. liyingsong

    liyingsong

    Joined:
    Sep 9, 2021
    Posts:
    5
    Please take a look at this error report:

    01-24 12:04:19.980 780-2220/? E BufferQueueProducer: [SurfaceView - com.******/com.unity3d.player.UnityPlayerActivity#0]:305: dequeueBuffer: attempting to exceed the max dequeued buffer count (2)


    mobile android
    GPUI version: 1.7.0
    unityversion 2020.3.20 URP

    How can I solve it ??
     
  50. liyingsong

    liyingsong

    Joined:
    Sep 9, 2021
    Posts:
    5