Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] GPU Instancer

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

  1. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    292
    I have a list of trees and rocks and many have a missing script because I had used GPUI then deleted the tool in order to reorganize my list (my GameObjects were in different folders). This is probably why the instances are at 0.
    As Unity does not support multi-editing, it takes a long time to remove calls to the missing script. I'll come back later to say if that solved the problem.
     
  2. homemacai

    homemacai

    Joined:
    Jul 22, 2020
    Posts:
    74
    Hello there, I am using Unity 2022.3 and URP 14. When using The Vegetation Engine and after adding new details in the detail manager, I sometimes get this error

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. GPUInstancer.GPUInstancerUtility.AddDetailInstanceRuntimeDataToList (System.Collections.Generic.List`1[T] runtimeDataList, System.Collections.Generic.List`1[T] detailPrototypes, GPUInstancer.GPUInstancerTerrainSettings terrainSettings, System.Int32 detailLayer) (at Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:1011)
    3. GPUInstancer.GPUInstancerDetailManager.InitializeRuntimeDataAndBuffers (System.Boolean forceNew) (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:163)
    4. GPUInstancer.GPUInstancerEditorSimulator.EditorUpdate () (at Assets/GPUInstancer/Scripts/GPUInstancerEditorSimulator.cs:135)
    5. UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <78fe3e0b66cf40fc8dbec96aa3584483>:0)
    6.  
    And now it happened again when trying to add a flower prefab, and I cannot load any scene with the detail manager, even on different terrains with different detail prefabs. this error is thrown every frame. It was working flawlessly before that to I doubt it was a setup issue. Tried to delete and a fresh GPUI reimport but no luck. Any help? thanks.
     
    Last edited: Feb 5, 2024
  3. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    521
    Hi there,
    Using colliders would be too expensive when dealing with millions of instances. The most efficient approach would be to perform a distance check and set the matrices to the buffers based on the distance.

    You can employ a Compute Shader on the GPU side or a Parallel Job on the CPU side and update the buffers accordingly. Utilizing a Compute Shader is preferable as it allows you to minimize the amount of data sent to the GPU.

    For instance, for each index, based on distance, one buffer/array can hold the correct Matrix4x4 value, while the same index on the other buffer/array can be set to zero and culled.

    Hi there,
    I was not able to reproduce the issue. Could you please email a bug report, either with an example project or a step-by-step description of how to reproduce the issue, following this guide?
     
  4. homemacai

    homemacai

    Joined:
    Jul 22, 2020
    Posts:
    74
    Hello, so I was able to fix this by removing all the prefabs from both de the detail manager and terrain, and importing them back to the detail manager. But there is still only one prefab that always cause this. The weird thing is that I made this prefab the exact same way as the others, but whenever I add it, The error is thrown when entering play mode, also it only throws' the error every frame if "error pause" is set on the console otherwise it's just one error and the scene loads normally, but that one prefab will be invisible, and it has a chance of having the effect of breaking the rest of them in edit mode, if so I need to remove them all and re-do the process again. So we can consider it solved, probably there is some error in blender to unity process on that one grass.
     
    Last edited: Feb 5, 2024
  5. homemacai

    homemacai

    Joined:
    Jul 22, 2020
    Posts:
    74
    So now I am having this small issue with trying to change the Detail Density and Detail MaxDistance at runtime. I saw that you recommend to check the TerrainGenerator to use the UpdateDetailInstance call. So I made a simple function to change it in my detail manager.
    Code (CSharp):
    1.         public void UpdateGPUIDetailManager()
    2.         {
    3.             gpuiDetailManager.terrainSettings.maxDetailDistance =  MaxDistanceSettingValue;
    4.             gpuiDetailManager.terrainSettings.detailDensity = DensitySettingValue;
    5.             GPUInstancerAPI.UpdateDetailInstances(gpuiDetailManager, true);
    6.         }
    And I can see the values changing on the detail manager inspector but they do not reflect in the game view, grass density and draw distance remain the same. Is there another step required to update the runtime detail manager? Thnaks!
     
  6. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    292
    I also had a single prefab that prevented all the others from working.
     
  7. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    521
    Each prototype has an individual distance and density setting. You can change the max. distance value at runtime by setting the maxDistance property of each prototype:
    Code (CSharp):
    1. foreach (GPUInstancerDetailPrototype p in gpuiDetailManager.prototypeList)
    2. {
    3.     p.maxDistance = MaxDistanceSettingValue;
    4. }
    However, the density setting is used at initialization. So when changing the density value, the Detail Manager needs to be re-initialized for the changes to take effect:
    Code (CSharp):
    1. foreach (GPUInstancerDetailPrototype p in gpuiDetailManager.prototypeList)
    2. {
    3.     p.detailDensity = DensitySettingValue;
    4. }
    5. GPUInstancerAPI.InitializeGPUInstancer(gpuiDetailManager);
     
  8. homemacai

    homemacai

    Joined:
    Jul 22, 2020
    Posts:
    74
    Thanks it works perfectly!
     
  9. DeidreReay

    DeidreReay

    Joined:
    Oct 28, 2019
    Posts:
    49
    So having an issue using unity settings Graphics we have basic game options menu that can change the Quality Settings options (Low to Ultra) . In game when we change graphics settings to a lower setting GPUI Prefab instances will change, but when we try to change graphics back higher the textures look horrible. Are there any known issues with changing Graphics at runtime or any idea what to maybe look at?
     

    Attached Files:

    • 1.PNG
      1.PNG
      File size:
      26.4 KB
      Views:
      7
    Last edited: Feb 11, 2024
  10. Tanknspank

    Tanknspank

    Joined:
    Oct 25, 2017
    Posts:
    3
    Hello Gurhan,
    currently using GPUI on HDRP 2022.3.10f1

    Trying to paint terrain details but simulation is not updating at all. I have to disable and reenable it for each detail I'm trying to paint to see the changes made which makes it impossible to work with it.

    have you or anyone here encountered this before and any possible fixes for this?
    (I am aware of the warning in the simulation kept alive field, but it's not just sometimes - it's always)

    I am using 1.8.1 but had the issue on 1.8.0 as well
     
  11. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    521
    Hi there,
    This is most probably a Unity bug, as GPUI does not handle anything related to texture quality. I would recommend trying the latest LTS Unity version to see if the bug persists.
    Hi there,
    I am unsure why the simulation is not updating in your case. Here is how it works:
    The Detail Manager is updated using the OnTerrainChanged method inside the GPUInstancerTerrainProxy component. The GPUInstancerTerrainProxy component is automatically added to terrains that use the Detail Manager, and the OnTerrainChanged method should execute when you make a change on the terrain.

    If this information is insufficient for you to determine why it is not working, you can email me an example project, and I can investigate further.
     
    Tanknspank likes this.
  12. OneFoxStudio

    OneFoxStudio

    Joined:
    Dec 26, 2023
    Posts:
    1
    Hi !
    I'm trying to chop down trees; using GPUI TreeManager to manage them; so i'm using

    Code (CSharp):
    1. GPUInstancerAPI.RemoveInstancesInsideBounds(treeManager, collider.bounds, 0f);
    To remove them; which works fine ... except the collider is still there; but not all the time (which is really odd).

    I can't even detect the collider from the tree nor show it using Gizmos.

    Ideally i'd like to be able to interact with a collider and do my stuff.

    Seems there's some dark magic going underneath; could you please explain how to deal with it ?

    Thank you

    Cheers!
     
  13. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    521
    Hi there,
    The RemoveInstancesInsideBounds method only removes instances from GPU memory. It will not modify the TerrainData.treeInstances or update the terrain collider. You need to implement a tree removal solution for Unity terrain and then use the RemoveInstancesInsideBounds method to notify GPUI to update the GPU memory.
    I attached a simple example I made a while ago to this post. It should give you an idea about how to implement your own solution.
     

    Attached Files:

  14. tcn5150

    tcn5150

    Joined:
    Dec 1, 2012
    Posts:
    26
    I was wondering if GPUI instances are able to cast shadows in HDRP volumetric fog? My tests would indicate that they can't, but I'd like to make sure. Thanks!
     
  15. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    521
    Hi there,
    I conducted a quick test on 2022.3 with Volumetric Fog, and there don't appear to be any issues with the shadows. The shadows might be getting culled due to distance. Please try enabling the Use Custom Shadow Distance option and set a high Shadow Distance value on your prototypes.
    If this doesn't resolve the issue, please email a sample project, and I'll investigate further.
     
  16. tcn5150

    tcn5150

    Joined:
    Dec 1, 2012
    Posts:
    26
    It was definitely culling the shadows at distance. "Use Custom Shadow" let me fix it. Thanks!
     
  17. Simunek

    Simunek

    Joined:
    Jul 15, 2016
    Posts:
    49
    Hi! Is DLSS supported? I have tried it, and it almost works, but sometimes small objects disappear randomly. What should I do? thanks!
     
  18. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    521
    Hi there,
    Please try disabling the Use Occlusion Culling option under Scene Settings.

    GPUI utilizes the camera depth texture for calculations in Occlusion Culling (see Hi-Z Occlusion Culling). However, when dynamic resolution is enabled in HDRP, the camera depth texture becomes inconsistent and unreliable for culling purposes. Unfortunately, it is a technical limitation that Occlusion Culling is not supported with HDRP dynamic resolution.