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.
  2. Dismiss Notice

[RELEASED] GPU Instancer

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

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    @LouskRad first of all thank you for reminding me how the occlusion culling works and to suggest the workaround to the fast camera movement problem. I will try that asap.

    Once it's ready, I will send you a project to debug the shadows, however, I am here to discuss also a problem with the integration of vegetation engine, but I think somehow, with the auto-generation of GPUI shaders for our project in general.

    Unfortunately, I don't have the time to understand what's really going wrong, but it's a while I noticed that GPUI breaks its own autogenerated shaders and this is true with VE ones too. In order to fix them, I have to apply the following change:

    from the auto-generated one:

    Code (CSharp):
    1.  
    2. HLSLPROGRAM
    3. #include "./../../../../../GPUInstancer/Shaders/Include/GPUInstancerInclude.cginc"
    4. #pragma instancing_options procedural:setupGPUI
    5. #pragma multi_compile_instancing
    6.  
    I have to move the include after the other includes in the shader:

    Code (CSharp):
    1.     #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    2.             #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
    3.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
    4.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
    5.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl"
    6.  
    7.             #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    8.             #ifdef DEBUG_DISPLAY
    9.                 #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
    10.             #endif
    11.             #include "./../../../../../GPUInstancer/Shaders/Include/GPUInstancerInclude.cginc"
    If I don't do this, the vertices won't be correctly transformed and they will all be around the camera. I have to do this change to all the auto-generated GPUI shaders at least with our HDRP project.
     
  2. ksicotte

    ksicotte

    Joined:
    Apr 26, 2021
    Posts:
    4
    Hi, thanks for the clarification. Manage to fix the issue for the flickering.
    Can the material variation technique with the structure buffer can be used to enable/disable a keyword (enum) or to change a texture 2d? I am trying to figure out how to do this with your example and a custom shader but it seems the structured buffer doesn't accept the value types needed for changing a texture or to enable a keyword so I am wondering how to make this happen as this is the sole variation needed for our system.

    Edit: I found your node for texture variation, I will experiment with that.
    Edit2: I am using the shadergraph variation demo as a base.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor.PackageManager.UI;
    4. using UnityEngine;
    5. using UnityEngine.Profiling;
    6.  
    7. namespace GPUInstancer
    8. {
    9.     [System.Serializable]
    10.     struct ProsperityStruct
    11.     {
    12.         public Vector4 albedoPros;
    13.         public Vector4 maskPros;
    14.         public Vector4 normalPros;
    15.     };
    16.     public class prosperityTest : MonoBehaviour
    17.     {
    18.         // The reference to the Prototype (the prefab itself can be assigned here since the GPUI Prototype component lives on the Prefab).
    19.         public GPUInstancerPrefab prefab;
    20.  
    21.         // The reference to the active Prefab Manager in the scene.
    22.         public GPUInstancerPrefabManager prefabManager;
    23.  
    24.         // The count of instances that will be generated.
    25.         public int instances = 3;
    26.  
    27.         // The name of the buffer. Must be the same with the StructuredBuffer in the shader that the Material will use. See: "GPUIFloat4VariationInclude.cginc".
    28.         private string bufferName = "prosperityBuffer";
    29.  
    30.         // The List to hold the instances that will be generated.
    31.         private List<GPUInstancerPrefab> goList;
    32.    
    33.         private List<ProsperityStruct> m_prospList;
    34.  
    35.         public Vector4 _BaseColorMap_10, _MaskMap_10, _NormalMap_10,_BaseColorMap_20, _MaskMap_20, _NormalMap_20,_BaseColorMap_30, _MaskMap_30, _NormalMap_30;
    36.         void Start()
    37.         {
    38.             System.Random random = new System.Random();
    39.  
    40.             goList = new List<GPUInstancerPrefab>();
    41.        
    42.             m_prospList = new List<ProsperityStruct>();
    43.        
    44.             ProsperityStruct struct1 = new ProsperityStruct ();
    45.             struct1.albedoPros = _BaseColorMap_10;
    46.             struct1.maskPros = _MaskMap_10;
    47.             struct1.normalPros = _NormalMap_10;
    48.             m_prospList.Add (struct1);
    49.        
    50.             struct1.albedoPros = _BaseColorMap_20;
    51.             struct1.maskPros = _MaskMap_20;
    52.             struct1.normalPros = _NormalMap_20;
    53.             m_prospList.Add (struct1);
    54.        
    55.             struct1.albedoPros = _BaseColorMap_30;
    56.             struct1.maskPros = _MaskMap_30;
    57.             struct1.normalPros = _NormalMap_30;
    58.             m_prospList.Add (struct1);
    59.  
    60.  
    61.             // Define the buffer to the Prefab Manager.
    62.             if (prefabManager != null && prefabManager.isActiveAndEnabled)
    63.             {
    64.                 GPUInstancerAPI.DefinePrototypeVariationBuffer<ProsperityStruct>(prefabManager, prefab.prefabPrototype, bufferName);
    65.             }
    66.  
    67.             // Generate instances inside a radius.
    68.             for (int i = 0; i < instances; i++)
    69.             {
    70.                 GPUInstancerPrefab prefabInstance = Instantiate(prefab);
    71.                 prefabInstance.transform.localPosition = new Vector3(Random.Range(-24f, 24f), 0, Random.Range(-24f, 24f));
    72.                 prefabInstance.transform.SetParent(transform);
    73.                 goList.Add(prefabInstance);
    74.  
    75.                 // Register the variation buffer for this instance.
    76.                 prefabInstance.AddVariation(bufferName, m_prospList[i]);
    77.             }
    78.  
    79.             // Register the generated instances to the manager and initialize the manager.
    80.             if (prefabManager != null && prefabManager.isActiveAndEnabled)
    81.             {
    82.                 GPUInstancerAPI.RegisterPrefabInstanceList(prefabManager, goList);
    83.                 GPUInstancerAPI.InitializeGPUInstancer(prefabManager);
    84.             }
    85.         }
    86.     }
    87.  
    88. }
    But now I am getting this error

    Graphics.CopyTexture called for entire mipmaps with different memory size (source (R32 SFloat) is 3128888 bytes and destination (R32 SFloat) is 2306192 bytes)
    UnityEngine.Graphics:CopyTexture (UnityEngine.Texture,int,int,UnityEngine.Texture,int,int)

    I am obviously doing something wrong, but I don't know how to tell the buffer to use another texture.

    Edit 3: Got it working somehow using the material variation demo as a base.
     
    Last edited: Jul 28, 2021
  3. perholmes

    perholmes

    Joined:
    Dec 29, 2017
    Posts:
    295
    I'm a bit confused, because I'm getting exactly the same performance with and without GPU Instancer. It's actually a little bit worse with GPU Instancer, unless I disable Occlusion Culling, as the documentation suggest might be more trouble than its worth.

    My setup is a terrain covered in grass as prefabs, thousands of them, placed with Prefab Brush+. Then I've removed the terrain to make sure we're just measuring one thing. But with or without GPU Instancer, performance is the same. I do know that GPU Instancer is working, because both the culling range and occlusion culling have an effect.

    Is it possible that Unity caught up with all these instancer plugins and basically does the same now? I'm not bitter about the purchase, it all seems well made, but I'm just struggling to extract a real advantage from this.

    Certainly, it would allow you to do better instancing from terrain trees and details. But then again, it doesn't add more control like random X/Z rotation to make crooked trees, so I'm still in favor of prefabs, because I can make way more realistic forests with them.

    I'm just having a bit of crisis of faith about whether adding one more piece of middleware and one more point of failure is really worth it when I can't point to a performance advantage.
     
  4. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    Hello, I have a few questions. Please keep in mind I'm using the no game object workflow when answering:
    1. How do you add/remove instances at runtime? (do you still use AddPrefabInstance and RemovePrefabInstance?)
    2. A lot of features and the API look like it may not work with the no game object workflow, what's compatible and what's not?
    3. Is there a way to replace instances near the player with instances with a game object, or is this something I have to do myself?
    4. If I need to reinitialize a new matrix to change the instance count, would it be better to move unused instances to a hidden position and retrieve them later when needed? (kinda like pooling)
    5. Is there a way to do LOD with the no gameobject workflow? (how do you get hold of the prefabInstance?)
    6. Do you have anything in place for collision detection with the no object workflow? (ie: to allow replacing instances with full prefab when being shot)

    What I'm trying to do is use billboard/sprite for far objects, use a mesh with no gameobject in the medium range and use a normal prefab with gameobject, rigidbody, collider etc in close range.

    Thank you.
     
  5. lupsavalentin

    lupsavalentin

    Joined:
    Nov 25, 2017
    Posts:
    2
    Hello. I'm trying to use GPUI, yet I get this problem where Unity will say Hold on, busy forever, something regarding Application.UpdateScene. This get's in a loop forever, and the project becomes unusable.
    Setup is: windows 10, unity 2020.LTS.15f, scene has been generated with Gaia. Problem occurs both for trees details or prefab importer.
    I've seen the same problem in earlier versions of 2020 LTS.
    Thank you
     
  6. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    You can listen the StartListeningGPUIEvent to wait for the detail manager initialization. An example can be found in the DetailDemoSceneController file.


    We actually fixed this in a recent update. Please make sure you are using the latest version (currently v1.5.3).


    Unity is not managing DrawMeshInstancedIndirect calls in the background. Performance increase depends on the scene as per documentation, but some effects might be having additional impact on specifically the performance of GPUI.

    In any case, performance increase is dependent on multiple factors such as instance counts, mesh complexity, additional effects, etc. Most of the times, you will see an increase in realistic game scenarios where scripts are running on the CPU and GPUI takes the load off them. In cases where you are already becoming GPU bound while rendering the geometry, you would not see much increase.

    The no-game object workflow is designed as an advanced feature to give you full control over your instances, where you are to implement however you handle those instances (collision, etc.) in your given custom scenario. GPUI only helps with rendering. There are only two APIs that are designed with use with this workflow, both of which are exemplified here in the related wiki for this. Other than that, how you manage your additional GameObjects are up to you.

    LODs are still defined in the prefab, so you can still use the prefab as a prototype for that.

    This sounds like a Unity bug. We are unable to reproduce it, but if you can email us the exact steps of how to recreate this, we can investigate the issue.
     
  7. LouskRad

    LouskRad

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

    I just wanted to let you know that the GPU Instancer team will be on a summer break until September 1st. We will be answering all the questions and support requests after the break.
     
    newguy123, Ne0mega and sebas77 like this.
  8. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    @LouskRad Thank you for clarifying all that! Have a good vacation!
     
  9. vlastan

    vlastan

    Joined:
    Nov 15, 2015
    Posts:
    44
    Sorry for asking on this again, but i am still having problems.
    I modified my script to wait for the detail manager initialization, and through debug i can see it happens around frame 10.
    However when i call GPUInstancerAPI.InitializeGPUInstancer at the end of the prototypes density setting, i get this error:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. GPUInstancer.GPUInstancerDetailManager+<FillCellsDetailData>d__36.MoveNext () (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:967)
    3. UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <cfc1ad890650411e946cff2e6f276711>:0)
    Calling InitializeGPUInstancer is necessary otherwise the prototype density won't be affected.
     
  10. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    Does anyone know how and/or where GPUInstancer calculates each instance's distance to the camera, and if that data is accessible?

    Getting access to culling info would also be great, there is a lot of features in my AI scripts I could disable.

    I would like to reuse the values instead of computing them again in my scripts. I use the no game object workflow.
     
    Last edited: Aug 16, 2021
  11. ssg3d

    ssg3d

    Joined:
    Mar 8, 2021
    Posts:
    3
    I am trying to get my GameObjectLess GPU Instancer setup to work in a customVolumePass

    I cannot figure out how to get the batches to render when using
    CoreUtils.DrawRendererList

    does anyone have an example of this working? Any gotchas to look out for?
     
  12. V_R

    V_R

    Joined:
    Dec 5, 2015
    Posts:
    4
    Hey there, back again with another weird edge-case issue!

    We've got some runtime-defined prototypes, and everything works great when we spawn the prefabs, all going as it should.
    We run into issues with our duplication system, however. Our duplication system currently literally does GameObject.Instatiate(TheGameobjectThePlayerIsDuplicating). On our end, this works great, even if it copies some irrelevant things across, but with GPUI this creates the issue of the GPUI Prefab also being copied across, with it maintaining its instance ID. As you can imagine, this causes some issues (tldr; everything goes invisible).

    We realize the cleanest way to work around this would be to simply re-spawn the base prefab and copy across the needed data, but due to the scale of the changes that would entail this is not something we can currently do.

    The question, then, is two-fold;
    1) Is there some sort of function we can call to 'refresh' the duplicated GPUI Prefab component?
    2) Alternatively, is there way for us to remove the existing GPUI prefab and re-add it with valid data?
    I had a look around for both of these options, and I was unable to find what I needed.

    Thanks,
    Victor
     
  13. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,234
    Is this asset compatible with webgl?
     
  14. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    tomorrow I will start to investigate a new issue that I cannot explain at the moment, so if you have any heads let me know. I can see that there are several DrawIndexedInstancedIdirect call without instances, I am not sure how such a thing is even possible:

    upload_2021-8-4_18-31-34.png
     
  15. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    My 2 Cent while the dev is on vacation...

    The problem makes sense, you are making a copy of an object active in the hierarchy with all its data initialized. (including instance id / references)

    I would try either:

    1- Adding code on instantiate to reset GPUI settings. Not sure if it was made to be used like this, you are going to have to test to find out which one, and may have to inspect / modify the code in the script GPUI puts on your prefabs.

    2- I also remember reading about a feature that detects newly instantiated prefabs and automatically register's them with GPUI. You could use this by adding a script on your prefabs that holds a game object reference to the original prefab. When adding a copy you getcomponent that script, grab the original prefab ref and instantiate it. This way you get a "clean" instance with no prior reference to any gpui instance id or whatever.

    3- Bite the bullet: adapt your duplication system to use the proper GPUI api calls to add instances, and then copy over whatever values / states you need for the required behaviour. (This is what I would do)
     
  16. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    This may be a wild goose chase, but... is the transform matrix of those "empty" instances set to Matrix4x4.Zero?

    I use the no gameobject workflow and to disable the rendering of an instance you set its matrix value to zero. GPUI is supposed to skip rendering it, but it still has an entry in the Matrix4x4 array sent to the GPU. The reason for this is you need to completely rebuild the array to resize it, so instead it's used like a pooling system with extra instances that you enable/disable as needed.

    I'm wondering if what you are seeing could be a manifestation of that internal process happening with the normal workflow.

    If you are using the no game object workflow it's easy to get check the value of the matrix4x4 of an instance (you provide it yourself) but if you don't, I don't know if you can or how to get the buffer data out of GPUI. RTFM is advised.
     
    sebas77 likes this.
  17. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    I wonder if I am chasing a wild goose here. Is it possible that these empty meshes draw calls are expected and they are the result of batches completely culled by the frustum culling? Please confirm.

    that's not it, even with frustum culling disabled, I get these 0 triangles drawcalls
     
    Last edited: Aug 10, 2021
  18. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    40
    I think these are the LODs of your mesh. The selection is done in a compute shader.
     
  19. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    yes and can it result in a draw call with 0 triangles?
     
  20. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    while investigating the 0 triangles draw calls, something broke all of a sudden, without even updating GPUI or Vegetation Engine and unfortunately, due to the nature of the bug, it's extremely time-consuming to understand what's going on. Everything works fine inside the editor, but once in a player, GPUI shaders seem to be all scrambled. This is very puzzling and I haven't still pinned down the problem.
     
  21. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    40
    Could it be that the shader variants with GPUI defines are getting stripped while building. We had done our own shader strip which I can't recommend. Referencing the created variants collection from GPUI.

    I'm still having problems with wrong LOD selection (too early high lod)
     
    sebas77 likes this.
  22. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    After solid 10 hours of soul crashing investigation, I found out that our new rendering problems were due to me disabling the following two settings. I didn't care about which one is the culprit exactly, but I believe is the Generate Shader Variant collection. I wanted to remove the shader collection from the resource folder, because otherwise the GPUI shaders are built twice (for some reason unity builds separately shaders found in the addressables and shaders in the resource folders, even if they are the same), to improve our building times.
    Never anymore. I suggest investigating why I cannot disable these without breaking the GPUI rendering.

    upload_2021-8-12_17-29-2.png

    remember that the bug is reproducible only in a built client and in our case with HDRP+deferred but it may not be relevant.
     
    Last edited: Aug 18, 2021
    tcz8 likes this.
  23. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    about your LOD problem, it may be a bug inherited by the Unity LOD system. Unity LOD is supposed to work in this way:

    "The percentage that appears in each LOD level box represents the threshold at which that level becomes active, based on the ratio of the GameObject’s screen space height to the total screen height. For example, if the threshold for LOD 1 is set to 50%, then LOD 1 becomes active when the camera
    pulls back far enough that the GameObject’s height fills half of the view."

    But this is not true according to our experiments. The LOD selection instead is dependent somehow on the area/volume of the gameobject, which is obviously wrong. If this is your problem, in reality, GPUI could fix it because I think they have just mirrored the wrong Unity behavior.
     
  24. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    I don't know exactly if I broke something or it's something related to 1.5.3, but the shadow distance is not read anymore from the HDRPSettings. I had to use custom distance and override the value to see the shadows working again at the correct distance.
     
  25. Da_Neel

    Da_Neel

    Joined:
    Dec 29, 2013
    Posts:
    15
    Hello! I need some help with modifying meshes instanced in runtime. Is there a way to save a reference to instanced mesh somewhere in my script, so I could modify the emission of materials on those meshes?
     
  26. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    40
    Could be. I copied the logic done in GPUI for my representation of distances done by the culling group API. High scaling seems to be an issue.

    The code seems to use QualitySettings.shadowDistance. But in HDRP you can define shadow distance by a volume. So does this mean the can only be wrong? upload_2021-8-17_11-53-54.png

    Update: Tested it when changing the value QualitySettings.shadowDistance does not get updated
     
    Last edited: Aug 17, 2021
  27. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    WeltenbauerRenn likes this.
  28. animal531

    animal531

    Joined:
    Aug 26, 2014
    Posts:
    25
    I've been playing with the Color Variation Shader and it works great, but I want to add a few more options to the material.
    Is there perhaps one that's closer to the Unity Standard Shader?
     
  29. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    There is a chance that the new version of GPUI is causing the following errors. The only reason I am saying it is because two GPUI users are experiencing it (one is me) but they are using different rendering pipelines (HDRP and Builtin). Let me know if this is possible.

     
  30. chungsong

    chungsong

    Joined:
    Aug 22, 2015
    Posts:
    1
    upload_2021-8-29_7-15-13.png

    I think i'm finded renderQueue bug
    material.renderQueue is forced set to 2000, after called GetIntancedMaterial()
    Add 300 line code then fix it
     
  31. Wawwaa

    Wawwaa

    Joined:
    Sep 30, 2017
    Posts:
    164
    A little trailer... Note the foliage and rocks...

     
    GurhanH likes this.
  32. svenTheraBytes

    svenTheraBytes

    Joined:
    Jul 14, 2021
    Posts:
    1
    Hello there,

    we have encountered an issue with the GPUInstancerPrefabRuntimeHandler, a little background about our setup first:

    We instantiate a large number of different Prefabs at the start of scene, they are all setup in the GPUInstancerPrefabManager with their GPUInstancerPrefabPrototype configured correctly (Enable Runtime Modifications, Auto Add/Remove Instances). We then make a call to InitializeGPUInstancer and everything works as it should, no problems so far.

    However, when I try to instantiate other GPU Instancer prefabs at some later time they do not actually show, the GameObject and all its components are there, the GPUInstancerPrefabRuntimeHandler Inspector even tells me "Instancing active with ID: 1". I did some testing and noticed that moving the OnEnable code from the GPUInstancerPrefabRuntimeHandler to Start instead fixes the rendering issue, but causes another problem, as the Auto Update Transform Data does not work anymore in that case. The only solution I have found so far involves disabling and enabling the GPUInstancerPrefabRuntimeHandler inside the Start method, though I really dislike that solution and would very much prefer a proper one.

    Other things I have tried: change the execution order of the GPUInstancerPrefabRuntimeHandler (tried both before and after default time), disabling all culling, disabling other camera related effects like PostProcessing and an Outline effect.

    Thanks for any help you can provide
     
  33. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    476
    Hi there,
    I am not sure why you are getting this error. If you can email us a sample project showing this issue we can investigate.

    Distance-culling calculations are made in GPU and are not read back to CPU because it would be very slow. So it is not accessible.

    Renderer based systems would not work with GPUI instances since GPUI disables Unity renderers and makes custom draw calls. But there might be a workaround depending on what you are tying to accomplish.

    I would recommend to use a custom script instead of Auto. Add/Remove feature. This way after Instatiate you can reset the data and then register the instance using AddPrefabInstance API method.
    Or you can edit the GPUInstancerPrefabRuntimeHandler script. Adding these lines at the end of the Awake method should be enough:
    Code (CSharp):
    1. gpuiPrefab.gpuInstancerID = 0;
    2. gpuiPrefab.state = PrefabInstancingState.None;
    3. gpuiPrefab.GetLocalToWorldMatrix(true);
    GPUI does not support WebGL because of Compute Shader support requirement. You can see the Minimum Requirements here.

    There are some cases where there can be draw calls without instances. Since GPUI uses procedural draw calls, number of instances to draw is not known on the CPU side. So draw calls are always made unless there is no instances registered. So there might be cases where after culling and LOD calculations the resulting instance count is 0 and since we do not read back this value (which would be very slow) draw call is still made.

    Thanks for the feedback, we will investigate this issue. Can you tell us which Unity version and HDRP version you are using?

    Usually adding too many StructuredBuffers to a shader is not favorable. For example, if you need more data, you can change the float4 buffer to a float4x4 or a custom struct, and use that instead. In most cases it is better to use only one buffer for variations.
    Having a generic Standard shader with GPUI variations would be very complex and slow. It is better to only add the data you need as a variation.

    This looks like a Unity error but if you can tell us how we can reproduce it we can investigate to make sure.

    Thank you for the feedback. We will test this and make the necessary changes.

    Hi there,

    Your case might be similar to what @V_R mentioned, I recommend to check my reply to that post above. If that does not help, please email us detailed info including some sample code related to your instantiation logic, so we can investigate.
     
  34. OriolCR

    OriolCR

    Joined:
    Jan 30, 2019
    Posts:
    15
    Hi, this asset really improved our perfomance by a ton.
    But I have an issue with the GPU protoptypes, as their root prefab use light layer, the gpu prototypes ignores it.

    Any work around this issue?

    We're on HDRP, deferred rendering
     
  35. OriolCR

    OriolCR

    Joined:
    Jan 30, 2019
    Posts:
    15
    Also, sometimes some prototypes cast at camera levels, like it is instancing there just being there, the normal cull tricks us so we didn't notice it at first but it constantly repeats with multiple cameras.
     
  36. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    476
    Hi there,
    thank you for the feedback. We just released a new version that adds support for Rendering Layer Mask. Please update GPUI to v1.5.4 and see if it solves the issue.

    When instances render over the camera it means that instancing setup inside the shader is not working. The shader needs to be compatible with GPU instancing to work correctly with GPUI, you can find details on how to setup shaders for GPUI here.
     
  37. ssg3d

    ssg3d

    Joined:
    Mar 8, 2021
    Posts:
    3
    Hi Gurhan

    I am trying to get my gpu instances to render into a custom volume pass where I can assign a custom colour
     
  38. OriolCR

    OriolCR

    Joined:
    Jan 30, 2019
    Posts:
    15
    Thanks for the reply GurhanH :)
    The update fixed everything related to our light layers problem, out of the box. :) This update came just in time. Thank you very much!

    Saddly the other problem persist :( I did some digging on the shader but we are actually using a single GPUInstancer/HDRP/Lit material on our transparent objects. In fact we are using it in 3 things (windows, door windows and the glass of our lamps.) Weirdly enough it works fine with the door windows but both normal windows and lamp glass pop on top of the camera when we execute the game.

    Heres the debbuging I did:
    -Checked if we are using the shaders probided by the GPUI package
    -Changed the setting on the material but in the end it always works on the door windows but the normal windows and lamp glass still pop out of place.
    -Created a brand new GPUInstancer material. Works with default material settings. Breaks when we add transparency.
    Still works on the door but not in windows nor lamps.

    Could it be something related with the prefab itself or the mesh rendered thats causing this? Other than this we are not sure whats really causing this :/
     
  39. Calamitycal

    Calamitycal

    Joined:
    Jul 6, 2014
    Posts:
    36
    I'm having an issue with objects blinking in and out of view while turning the camera or moving around. I made a quick video of it. I am using Map Magic 2 and the GPUI integration. The trees are objects (not terrain trees).

    It only happens in builds, not in editor.



    Any ideas as to what might cause this?
     
  40. Calamitycal

    Calamitycal

    Joined:
    Jul 6, 2014
    Posts:
    36
    Did another test using the Prefab Manager and with the map and trees already loaded and everything worked fine. So this seems specifically related to the MapMagic2 integration when loading the terrains and objects at runtime.

    I thought maybe it was the shader on the tree so tried objects with the standard shader and it still happens. Also tried objects with LODs vs those without and same issue. Works fine in engine, but breaks in build.

    One thing I have noticed is that when I import objects with the MapMagic2 Integration button, sometimes the prefab only gets the GPUI Prefab script and sometimes it gets both that and the Prefab Runtime Handler script. Not sure if that's related. I've tried testing with just the one script and with both and same issue after making a build.

     
  41. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    Could I get access to it if I'm doing my calculations in a compute shader?
    Also, I would love to see how it's done, which file has the Distance-culling code?
     
  42. LouskRad

    LouskRad

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

    using a volume pass would not work with GPUI since instances are rendered all together getting material information from the prototype. That is, volume based changes would not apply since rendering does not work individually for the prototype instances.

    You can use material variations to color different instances - but HDRP's custom volume pass would not work out of the box.


    Hi there,

    It is a know issue that transparency and GPU instancing together can have unexpected effects. You can take a look at this F.A.Q for details.

    Hi there,

    This looks like a culling issue that is caused by bounding boxes of the tree objects. You can test if this is the case by turning off both occlusion and frustum culling and see if that prevents blinking in your build. If this is the case, please check if your tree prefab scale is proper (MapMagic might be scaling it).

    If this is not the case, if you can email us a sample project showing this, we can investigate it further.


    Hi there,

    You can check the compute shader:
    GPUInstancer/Resources/Compute/CSInstancedCameraCalculationKernel.compute

    Technically you can use a custom compute shader to manipulate instances (an example of this can be found in the boids scene).
     
  43. Calamitycal

    Calamitycal

    Joined:
    Jul 6, 2014
    Posts:
    36
    I did have MapMagic scaling the trees a bit using the Adjuster Node. I removed that and the bug persisted.

    I have narrowed this down though and it's really strange. It works fine if I DON'T import the grass and only import the objects. When I do import the grass, the trees and other objects blink like in the video. I can repro this 100% now.

    It's going to be difficult for me to send a sample project as this is a pretty big project. I'll see if I can put one together tho. Guessing it's related to a node setting in MapMagic.

     
  44. secondsight_

    secondsight_

    Joined:
    Mar 2, 2014
    Posts:
    163
    Hey there !
    I´m a little bit at a loss here...

    I´ve created some dense forest scenes containing mostly NATURE MANUFACTURE assets. But when I apply the GPU component, it seems to have zero impact on performance at all. Framerate pretty much stays exactly the same. Only when I reduce the draw distance a lot (~15) I get a few fps more.My scene uses around 30 different prefabs, rendered as unity trees.

    Another thing I would like to mention is the editing of the settings:
    I find it extremly time consuming and tiresome to readjust the settings for every of those 30+ prefabs everytime after a reimport (for example when I exchange some object prefabs on my terrain). Is there (still) no way to save / load settings ? Or maybe only the need to modify the settings for changed / new objects ? Or more global settings ? Or multiselection ?

    Thanks for your time !
     
  45. buc

    buc

    Joined:
    Apr 22, 2015
    Posts:
    123
    I would like to switch to GPUI, but for this I would need something to check if the respective object is visible (rendered) or occluded. With the standard approach I can check meshRenderer.isVisible. Is there something equivalent to this in GPUI?
     
  46. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,120
    Hi, I can't seem to send a private message.
    I'd like to ask why did you get the asset Mega World removed? From my understanding you sent a complaint to unity about it.

    A ton of customers are surprised by what GPUI developers did. It has a large user base. Mega World offers a ton of features that no other asset has, and from what I hear your problem was with Quadro Renderer? Nature Renderer, Quadro, Vegetation studio and GPUI all use the same API provided by unity. What part of quadro made you send a complaint?

    Please clarify. The asset was removed out of nowhere and all customers are now stuck, and frankly I depend entirely on this asset to paint my terrain. Are we missing something? Why did you do it?
     
  47. Xyztem

    Xyztem

    Joined:
    Nov 12, 2017
    Posts:
    1
    @LouskRad Hi I'm a Mega World developer. I wrote you an answer by email, I hope to receive an answer from you. I'll write right away that you do not own the copyright for MegaWorld tools such as the Brush Paint Tool, Stamper Tool, Precise Place Tool, Edit Tool and other tools that are responsible for level design. I am ready to remove the Quadro Renderer completely, you won, apparently you seriously found fault with the small source code of the Quadro Renderer, which could be similar to your implementation, but the source code of the Quadro Renderer is 98% different from the GPU Instancer. I respect this place where you help users with problems, I would not like to have a discussion here, answer me on the letter I already sent you or write yourself: uladzislau78@gmail.com
     

    Attached Files:

    Last edited: Sep 24, 2021
    jorikito, Bwacky and PutridEx like this.
  48. LouskRad

    LouskRad

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

    Performance gain issues usually depend on various factors (though in most cases it relates to low instance counts - or 3rd party vfx). You can take a look at this best practices wiki page for detailed information on how we suggest you use GPUI.

    As for editing prefab settings, you can simply multi-edit them with ctrl (or shift) clicking and multiselecting all your prototypes.

    If this doesn't work for you, and if you know which values you should use, then you can also edit the scriptable objects directly under the PrototypeData folder.

    GPUI does not offer an occluded test since all the occlusion calculations run on the GPU for the prototype instances. A readback from the GPU for this purpose would come with a performance hit.
     
  49. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    There is not much we can say about this really.

    To clarify the issue for its affected users, the "Mega World" asset was being sold with files and code from GPUI without our permission and it was reported for this. Thus, this was not an issue of similar functionality but one of copying code that was uniquely written for GPUI. The amount of infringed code was also not too little to ignore.

    The takedown decision was made by Unity based on these facts.
     
    transat and cjjeffery like this.
  50. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,234
    What happend to the "Shadow with Original Shader" that I see in the youtube tutorials for versions 1.1.1? I dont see that option in the latest 1.5.4 version...

    I have a bunch of trees (700 of them) and when using GPU Instancer they dont cast shadows during runtime. In scene view and game view, during non runtime or when I disable GPU Instancer, the shadows are fine....

    Any hints?

    (this is with HDRP)

    @LouskRad @GurhanH
     
    Last edited: Sep 28, 2021
    Mojo-Game-Studio likes this.