Search Unity

[RELEASED] GPU Instancer

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

  1. Crowsinger

    Crowsinger

    Joined:
    Apr 23, 2022
    Posts:
    19
    Hello. I've spawned ferns and flowers on a landscape using Gaia (four terrains), and I the GPUI Details Manager is now on the four terrains. It never finishes preparing the simulation, which is fine, but none of the vegetation is appearing on the landscape in game either. Is there some reason why the vegetation isn't there?

    Thank you
     
  2. Grigler_f

    Grigler_f

    Joined:
    May 14, 2020
    Posts:
    24
    Hi,

    On this topic, we're attempting to get reflection probes to work with URP using the deferred path and are still running into issues. Normal (not instanced) draw calls made by unity will have a texture set for the nearest reflection probe, but we're finding that any InstancedIndirect draw calls made by GPUI have Unity's black cube texture set instead. We're finding that only hard-coding a custom environment reflection is having an effect on these draw calls, but we'd prefer to use reflection probes if possible. Do you have any ideas on this?
     
  3. OmnifariousStudios

    OmnifariousStudios

    Joined:
    Mar 12, 2018
    Posts:
    48
    I've been experimenting with the color variation and my prefab instances, and it works great!

    Weird thing though; whenever I call the script at startup to change my objects to different colors, it also creates an instance of all 4 prefabs at the origin. Is it supposed to do that by default? Or is it because I'm calling it on my prefab instances that are already in the scene?

    I've made sure to copy the functions correctly from the demo ColorVariation script too.

    Thanks!
     
  4. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    You should check if there are any error logs and make sure you are not using another instancing solution or its shaders.

    Hi there,
    We do not make anything specific for reflection probes in GPUI. We mainly look into what Unity supports with indirect instancing and explain that to the users. I haven't tested the URP reflection probes recently and there has been many changes since we last looked into it. So I can't really say much right now, but we will look into it and update the documentation accordingly for the URP deferred path.

    The code in the ColorVariation both instantiates and adds variations. So if you also copied the Instantiate part, you might be creating instances.
    In any case, if you can share the code and explain what it should do, we can help
     
  5. OmnifariousStudios

    OmnifariousStudios

    Joined:
    Mar 12, 2018
    Posts:
    48

    Sorry, I should've added that I'm not using the instantiate code from ColorVariation.

    - I have around 100 buildings in my scene. The building itself is a prefab, and it's children are walls and floors that are GPU Prefabs.

    I register those in the GPUI Manager in the editor.

    Then when I hit play, my code does this:

    Code (CSharp):
    1.             for (int i = 0; i < GPUInstancerPrefabs.Count; i++)
    2.             {
    3.                 GPUInstancerAPI.DefinePrototypeVariationBuffer<Vector4>(prefabManager, GPUInstancerPrefabs[i].prefabPrototype, bufferName);
    4.                 print("Defining Prototype Variation Buffer for " + GPUInstancerPrefabs[i].prefabPrototype.name);
    5.             }
    6.  
    7.  
    8.             for (int i = 0; i < GPUInstancerPrefabs.Count; i++)
    9.             {
    10.                 // Register the variation buffer for this instance.
    11.                 GPUInstancerPrefabs[i].AddVariation(bufferName, (Vector4)buildingColor);
    12.             }
    13.  
    14.         GPUInstancerAPI.RegisterPrefabInstanceList(prefabManager, GPUInstancerPrefabs);
    15.         GPUInstancerAPI.InitializeGPUInstancer(prefabManager);
    16.  
    My buildings all change color as intended, but it still creates those instances at the origin as well.


    But I've found a different problem, unrelated to the color variation.

    It seems that my instances stop rendering when I'm looking in very specific directions (I'm using VR if that makes a difference). There are 2 directions I've found, but there could be more.

    If I look directly towards the x axis, or the -z axis, all of my instances disappear. The only ways I can make them reappear are:
    1. turning off my Camera's occlusion culling (Unity's version, not the GPUI occlusion culling as I have that off already). 2. If I set my Camera's near clip plane from 0.1 to around 12.5
    3. If I set my Camera's far clip plane from 1000 to 260.

    I've tried rebaking occlusion, and removing and re-adding my prefabs/prototypes, but I'm still getting the same issue.
     
  6. Grigler_f

    Grigler_f

    Joined:
    May 14, 2020
    Posts:
    24
    Hi, thanks for the response. I queried Unity on this here and it's actually a non-documented limitation of URP either in Forward or Deferred paths. But they're planning to allow for it in the future with their Forward+ paths.

    https://forum.unity.com/threads/ref...ced-rendering-using-the-deferred-path.1336892
     
    GurhanH likes this.
  7. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    If the instances are already registered in editor, you don't need to call RegisterPrefabInstanceList again. It might be causing duplicate entries.

    As for the disappearing instances, it sounds like Unity is culling the instances. For the draw calls, we define a bounding box that is centered on the camera and its default size is 10000, so it should never be culled by Unity. Make sure that you have the correct camera set on the manager, and the "Instancing Bounds Size" on the GPU Instancer Preferences is set to a high value.
     
  8. animal531

    animal531

    Joined:
    Aug 26, 2014
    Posts:
    25
    Is it possible to make a GPUInstancer prefab and then modify the UV's of an instance (and still have them batched)?

    Thanks,
     
  9. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    You can not change the UV of the mesh, but you can use Material Variations and modify UV values inside the shader.
     
  10. KHam256

    KHam256

    Joined:
    Sep 17, 2016
    Posts:
    19
    First off, this asset is awesome!

    in play mode InitializeWithMatrix4x4Array() works perfectly fine however in editor nothing shows up. I would like to use it to preview these prefabs I'm generating with out having to play the game and see the changes. Is there more to it when initializing in the editor?
     
  11. TimDoesDev

    TimDoesDev

    Joined:
    Feb 23, 2018
    Posts:
    35
    Hi we're trying to chop down terrain trees. We want to do it by hitting the tree detail with an axe and then we'd like to figure out what type of tree prefab it actually is in order to spawn a different version of the tree. After that we'd like to remove the terrain tree that we hit using the GPUI API..

    We're unsure how to figure out what tree we hit and we're not really able to remove the terrain tree instance because using RemoveInstancesInsideCollider or RemoveInstancesInsideBounds do not work with the small collider we use for the axe.. We also can't use the collider we get from the tree we hit because that collider is part of the entire terrain too..

    Any ideas for these 2 issues? Thanks! :)
     
  12. Raystorm

    Raystorm

    Joined:
    Mar 28, 2016
    Posts:
    9
    Hi there we're having problem implementing this with addressable, the game keeps crashing when we enable GPU Instancer, is there any instructions on how we could properly implement this?
     
  13. OmnifariousStudios

    OmnifariousStudios

    Joined:
    Mar 12, 2018
    Posts:
    48
    Removing the RegisterPrefabInstanceList worked! No more extra instances. Thanks!

    However the culling issue is still a problem. I checked, and the instancing bounds size is still at 10000, and I don't have any other active cameras in the scene. I can also confirm that the only time they are culled is when facing towards the Z axis or when facing the -X axis.
     
  14. Raystorm

    Raystorm

    Joined:
    Mar 28, 2016
    Posts:
    9
    Follow up on this, seems like it kept crashing because i set the GPU Instancer prefab manager Prefab as addressable.
    I tried unsetting the manager from addressable, now it doesn't detect the prefab as the one i registered in the manager.

    this might be because the Prefab object being referenced is different (since my prefabs are all in addressable)
     
  15. maniek12585

    maniek12585

    Joined:
    Oct 30, 2017
    Posts:
    1
    Hi there . Is there any way that GPUI is changing shadow distance drawed per prototype, when the quality level in Quality settings is changed ? I have disabled all shadows settings in scene global volume and shadow distance is drawing differently on each quality level. Any respond will be much appreciated. (using HDRP 10.7.0 and Unity 2020.3)
     
    Last edited: Sep 30, 2022
  16. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there and thanks.
    You can use the StartEditorSimulation API method before calling Initialize, then the instances will also be rendered in edit mode.

    Hi there,
    Finding the tree that your axe collides with is not related to GPUI. You need to search through the treeInstances to find out. After you find the TreeInstance, you can call the RemoveInstancesInsideBounds with the bounds centering the tree instance position.

    I am not sure why the culling issue is happening. If you can email us a sample project we can investigate.

    Hi there,
    If you are making the Manager itself a prefab, you shouldn't. Prefab Manager has references to the objects in the scene, so it would loose those references if you make it a prefab. Manager should be saved with the scene, not as a prefab.
    If you are having issue with the prefab prototypes, than make sure that these prefabs are loaded before you load the Prefab Manager.

    Hi there,
    GPUI uses the QualitySettings.shadowDistance by default. You can either update this value, or set a high Shadow Distance value using Use Custom Shadow Distance setting.
     
    KHam256 likes this.
  17. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Hello!

    I have an addressable setup with one main project and content project where terrains and trees come from. At runtime these terrains are streamed in and out in a scene. Main project does not know anything about the content folder (shaders, trees etc..).

    I am trying to figure out what the proper workflow is, do I add the tree manager to each of the content scenes? Keep in mind I could have multiple terrain scenes active at any time as the terrain tiles are streamed in.

    Can I just add the a manager to each terrain?


    EDIT:
    So I have been playing around a bit but still can't get it to click in my head, how this should work. Perhaps if below is explained I'd be off to a good start.

    Lets say I have a GameObject loaded from addressables:

    GameObject treePrefab =InstantiateFromAddressables(treeObj);


    Now this is in my running scene. Just a good ol GameObject.

    How do I instance/display this (or many of these) at a given position(s) with a given rotation(s) using GPUI?

    Thanks!
     
    Last edited: Oct 3, 2022
  18. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    One approach you can use is to call the DefineGameObjectAsPrefabPrototypeAtRuntime API method to create a prototype on the Prefab Manager when you first load the prefab. Then for every instance instantiated in the scene, you can call AddPrefabInstance API method. Please take a look at the AddRuntimeCreatedGameObjects demo for an example usage.
     
  19. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    I will try this out. Thanks.
     
  20. PieterM2H

    PieterM2H

    Joined:
    Aug 2, 2021
    Posts:
    8
    Hi,
    We have a usecase for where the player can update a specific area on the terrain's heightmap every now and again. (interval of roughly 10 minutes I would say)
    It would be amazing if the detail instances could update accordingly, even if it takes half a second.
    Due to our big terrain, reinitializing the detailManager does work but it means the grass and other vegetation is gone for more than 1 second, which is not what we want.

    Is there a way to update a selection of the instances and simply update their height? We have no intention of removing any instances, just applying the detail's height according to the new heightmap.

    I've tried some things but in the end I can't get the GPUInstancerDetailCells to update their detailInstanceBuffers. I don't want to modify a lot of the existing code, if at all.
     
  21. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    Unfortunately, there is no functionality for partially updating heightmaps for the Detail Manager. You can only reinitialize to reload the data.
    We are not planning to add further runtime modification features to the current Detail Manager, because its design is not suitable for it (it would be slow and memory intensive).
    We are working on a new system where height modifications can be made efficiently at runtime, but it is not yet ready for release, so unfortunately I can not offer a solution at the moment.
     
  22. Rail9

    Rail9

    Joined:
    Feb 21, 2020
    Posts:
    28
    Hi!

    The following error occurs when importing and building the GPU Instancer.

    Assertion failed on expression: 's.buildTarget.platform >= kFirstValidStandaloneTarget'
    UnityEngine.GUIUtility: ProcessEvent (int,intptr,bool&)

    Assertion failed on expression: 'buildTarget.platform >= kFirstValidStandaloneTarget'
    UnityEngine.GUIUtility: ProcessEvent (int,intptr,bool&)

    Assertion failed on expression: 'buildTarget.platform >= kFirstValidStandaloneTarget'
    UnityEngine.GUIUtility: ProcessEvent (int,intptr,bool&)

    This error causes the grass and trees in The Vegetation Engine and others to not shake.

    The version of Unity is 2021.3.9f1.
    This error also occurs in new projects just created.

    I also want to delete objects with Destroy(gameobject) and hide them with SetActive(False), but I have to check Enable Runtime Modifications and Add/Remove Instance at Runtime. Add/Remove Instance at Runtime, but the object does not disappear and the information is not updated.

    How can I dynamically delete or hide them?
     
    Last edited: Oct 9, 2022
  23. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Hello,
    When I try to use the runtime GameObjects workflow I keep seeing this message. How do I fix this? I can't seem to find the prototype settings (or anything relating to this in the prototype section).

    Also (obviously), my game objects shows up pink.

    I have the render (URP) asset set in the project settings and depth is selected.

    Code (CSharp):
    1. Can not find GPU Instancer setup for shader: Universal Render Pipeline/Lit. Check prototype settings on the Manager for instructions.
    2. UnityEngine.Debug:LogError (object,UnityEngine.Object)
    3. GPUInstancer.GPUInstancerShaderBindings:GetInstancedShader (string,string) (at Assets/GPUInstancer/Scripts/Core/DataModel/GPUInstancerShaderBindings.cs:111)
    4. GPUInstancer.GPUInstancerShaderBindings:GetInstancedMaterial (UnityEngine.Material,string) (at Assets/GPUInstancer/Scripts/Core/DataModel/GPUInstancerShaderBindings.cs:131)
    5. GPUInstancer.GPUInstancerRuntimeData:CreateRenderersFromMeshRenderers (int,GPUInstancer.GPUInstancerPrototype) (at Assets/GPUInstancer/Scripts/Core/DataModel/GPUInstancerRuntimeData.cs:412)
    6. GPUInstancer.GPUInstancerRuntimeData:CreateRenderersFromGameObject (GPUInstancer.GPUInstancerPrototype) (at Assets/GPUInstancer/Scripts/Core/DataModel/GPUInstancerRuntimeData.cs:287)
    7. GPUInstancer.GPUInstancerPrefabManager:InitializeRuntimeDataForPrefabPrototype (GPUInstancer.GPUInstancerPrefabPrototype,int) (at Assets/GPUInstancer/Scripts/GPUInstancerPrefabManager.cs:238)
    8. GPUInstancer.GPUInstancerPrefabManager:AddInstancesToPrefabPrototypeAtRuntime (GPUInstancer.GPUInstancerPrefabPrototype,System.Collections.Generic.IEnumerable`1<UnityEngine.GameObject>) (at Assets/GPUInstancer/Scripts/GPUInstancerPrefabManager.cs:1172)
    9. GPUInstancer.GPUInstancerAPI:AddInstancesToPrefabPrototypeAtRuntime (GPUInstancer.GPUInstancerPrefabManager,GPUInstancer.GPUInstancerPrefabPrototype,System.Collections.Generic.IEnumerable`1<UnityEngine.GameObject>) (at Assets/GPUInstancer/Scripts/API/GPUInstancerAPI.cs:666)
    10. _GPUITools.GPUIRuntimeObject:Start () (at Assets/_GPUITools/GPUIRuntimeObject.cs:52)
    11.  

    Also, it seems if I manually add the prototype to the prefab manager, this does not happen. So it looks like I am missing a step, like creating/initializing a shader?

    here's what I am doing:
    Code (CSharp):
    1.  
    2. using System;
    3. using System.Collections.Generic;
    4. using GPUInstancer;
    5. using UnityEngine;
    6.  
    7. namespace _GPUITools
    8. {
    9.     public class GPUIRuntimeObject : MonoBehaviour
    10.     {
    11.         public GPUInstancerPrefabManager prefabManager;
    12.         public GameObject prototypeGameObject;
    13.  
    14.        
    15.         private List<GameObject> instances = new();
    16.         private GPUInstancerPrefabPrototype prototype;
    17.        
    18.  
    19.         private void Start()
    20.         {
    21.             GameObject holder = new GameObject("holder");
    22.             prototypeGameObject.SetActive(false);
    23.             for (int i = 0; i < 1000; i++)
    24.             {
    25.                 GameObject instance = Instantiate(
    26.                     prototypeGameObject,
    27.                     UnityEngine.Random.insideUnitSphere * 20,
    28.                     Quaternion.identity);
    29.                 instances.Add(instance);
    30.                 instance.transform.SetParent(holder.transform);
    31.             }
    32.  
    33.             // prototype = GPUInstancerAPI.DefineGameObjectAsPrefabPrototypeAtRuntime(prefabManager, prototypeGameObject);
    34.             prototype= prefabManager.DefineGameObjectAsPrefabPrototypeAtRuntime(prototypeGameObject, true);
    35.  
    36.             prototype.autoUpdateTransformData = true;
    37.             prototype.enableRuntimeModifications = true;
    38.            
    39.            
    40.             //GPUInstancerAPI.AddInstancesToPrefabPrototypeAtRuntime(prefabManager, prototype, instanceList);
    41.             prefabManager.AddInstancesToPrefabPrototypeAtRuntime(prototype,instances);
    42.  
    43.         }
    44.     }
    45. }
    46.  
    Thanks!
     
    Last edited: Oct 7, 2022
  24. stephenq80

    stephenq80

    Joined:
    Jun 20, 2018
    Posts:
    34
    Hello,

    I was wondering if anyone knows if GPU Instancer works with any version of Unity 2022?

    Thanks!
     
  25. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Hi, I am having some issue with Speedtree 7 in Unity 2021.3
    If I select the Speedtree 7 shader from GPU Instancer I cannot use the Cutout feature and therefore the leafs looks horrible!
    Could you please help me?

    Thank you in advance,

    Dom
     
  26. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    I am not sure if the error is related to GPUI. But if it starts to happen after you add GPUI, please email us a sample project so we can investigate.

    If you wish the Prefab Manager to automatically add/remove instances when you destroy or disable GameObjects, you need to enable the Auto. Add/Remove Instances option. Alternatively, you can use the RemovePrefabInstance API method.


    Hi there,
    GPU Instancer requires shaders that are setup for its indirect instancing methods. When you add a prototype in editor, it goes through the shaders and auto. converts them. If you are defining prototypes at runtime, you need make sure that the shaders are already setup. You can do this by using the Context Menu by right clicking the material/shader you are using.


    Hi there,
    There are no known issues for Unity 2022.


    Hi there,
    It looks like there has been some modifications to the SpeedTree7 shader which does not play along with the GPUI auto. shader conversion. We will look for ways to adapt the converter on the next update. For now you can replace the shader code under GPUInstancer/Shaders/SpeedTree7_GPUI.shader with the one attached to this post and see if it solves the issue.
     

    Attached Files:

    FlightOfOne likes this.
  27. Rail9

    Rail9

    Joined:
    Feb 21, 2020
    Posts:
    28

    I sent the project to your email.

    As I mentioned at the beginning, this project was created as a new project, and I just imported the GPU Instancer from PackageManager.

    Also, the project created with 2020.3.33.f1 is working fine with Add/Remove, and there are no errors in the console after build, so everything is fine.

    It is only 2021 that does not work even when Auto is checked or Vegetation Engine does not work after build.
     
    Last edited: Oct 11, 2022
  28. andylewisart

    andylewisart

    Joined:
    Nov 4, 2013
    Posts:
    19
    Hi there,
    I'm trying to utilize occlusion culling, but am finding that it's only working on the right side of the screen. Attached is what my Hi Z Occlusion Generator debug view looks like. The majority of the screen is a flat color - you can only see depth on the far right quarter of the screen. This is reflective of what the occlusion culling is doing overall: completely culling everything on the left three quarters of the screen, and then doing proper occlusion culling on the far right quarter. Any ideas why this might be happening? This is in Unity 2021.3.11f1, utilizing HDRP 12.1.7.

    upload_2022-10-11_6-57-54.png
     
  29. OmnifariousStudios

    OmnifariousStudios

    Joined:
    Mar 12, 2018
    Posts:
    48
    Hello again!

    What would be the main causes of CPU performance spike while using GPUI in VR? I feel like I've tried everything, but can't seem to find the cause.

    Details for clarity:
    - VR
    - 4 prototypes that I use to make up destructible buildings; 3 walls and 1 floor.
    - Prototypes are using the Material/Color Variation shader, but only firing at the start to change the initial color.
    - Part of one of the wall prototypes has a window, which uses the GPUI Standard shader for reflections instead of the color variation shader.
    - No prototypes are using Shadow Casting, and Light Probes are disabled
    - Spike happens when viewing a group of buildings, but the instance count being rendered isn't more than a few thousand at max.
    - Because I'm using addresables, when loading into the scene containing all of these instances, I have my scripts call the DefineGameObjectAsPrefabPrototypeAtRuntime function and then Register and Initialize the instances.


    Enabling/Disabling these didn't help:
    - Unity's Occlusion Culling
    - GPUI Occlusion Culling and Frustum Culling
    - Using Fog
    - Color Variation (leaving them all the same color by not defining the buffer at start)


    Could this be due to Compute Shaders?
    Or is using a different shader/material for the windows too expensive?

    Thanks!
     
  30. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    334
    Hello, I'm to use the detail manager, but I keep receiving this error

    upload_2022-10-14_11-26-4.png

    This is my prototype under detail manager
    upload_2022-10-14_11-27-53.png

    What am I doing wrong?
     
  31. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    There might be a transparent object writing to depth texture while it shouldn't. Or it might be because of an HDRP feature modifying the texture. Try the DetailInstancing demo scene to see if it is scene specific or project wide. If you can't figure out the cause, email us a sample project and we can investigate to find out the reason.

    Hi there,
    To figure out what is causing the spike you can use the Profiler. Unity has a detailed guide here.
    If, for example, your application is bound by the GPU, then you most probably have too many vertices/polygons that the GPU is not able to process effectively. In this case you need to reduce the vertices for example by using LODs, or by using a simpler shader so that the GPU can complete its process faster.

    Hi there,
    Looks like the Detail Manager was not able to calculate a cell size for the partitioning. What is your Detail Resolution, Heightmap Resolution and Terrain Width/Height values on the terrain?
    You might be able to solve this issue by disabling the Auto SP Cell Size option, and setting the cell size to your terrain size.
     
  32. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    334
    upload_2022-10-14_19-30-37.png

    I disable the auto SP_Size on detail manager and the error was gone, but what I'm trying to achieve is set a dynamic occlusion, but this isnt happening, also I saw that the prototypes just included my - paint details - from terrain, not the paint trees, is it correct? I mean, I want to occlude the trees too

    EDIT:
    It`s fixed
     
    Last edited: Oct 18, 2022
  33. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    AH-HA! See, I told you, 30 seconds later.

    So, in case anyone else is an idiot like me:

    Add Game Object prefabs into the "Prefab Manager"

    THEN, add those prefabs to your scene. (I had already added the objects to my scene, that's why I was getting that error)

    So, Dev, again, thanks for your time.... and, you know, nevermind.

    -------------------------------
    EDIT: Why do I always hit "Send" and then 30 seconds later find the answer. (sort of)

    The error is because I was adding items from the Hierarchy, not the Project. COMPLETELY my fault. I even noted you did it that way in the videos and yet I still got it wrong.

    Now, my current problem is even through I have those prefabs in the scene, when I add that gameobject prefab to the Prefab Manager it loads, but does not have any instances in my scene, when there are thousands.

    (gonna keep trying to figure it out.... cause in 30 seconds....)

    -------------------------------
    Hello,

    I am having an odd issue and cannot find the solution. I have a set of objects that I spawn into my scene, in editor, NOT at runtime. These are prefabs I created (basic GameObjects) but when I attempt to add them to the "GPU Instancer Prefab Manager" I get the following msg: GPU Instancer prefab Manager only accepts user created prefabs. Cannot add selected object.

    If I press the "Register Instances in the Scene" button, no response.

    On your wiki (https://wiki.gurbu.com/index.php?title=GPU_Instancer:GettingStarted) you mention: "Note that the Prefab Manager only accepts user created prefabs."

    So, what dumbass thing am *I* doing wrong?

    Thanks for your time and the asset
     
    Last edited: Oct 17, 2022
  34. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    Ok, so now I have spent the last 24 hours running various tests, and feel secure in my ignorance.

    Prefabs in the scene are not appearing until I am close to them. REAL close (sometimes less than one foot, sometimes I have to be within 3 to 5 meters)

    Here I have screenshots of the GPUI Prefab manager, the game object (a sign) and the project's GPU Instancer settings: https://imgur.com/a/mVDwJYV

    IMPORTANT: If I compile the project as a NON-VR app, I see the signs correctly. It's only within VR that the issue occurs. I am using Unity 2021.3.61, HDRP 12.1.7 OpenXR, Single-Pass. PCVR (as opposed to Android)

    I did see one post in Oct last year, https://forum.unity.com/threads/released-gpu-instancer.529746/page-54#post-761, about what MAY be the issue, but the response: "Sounds like the camera projection matrix is incorrect" didn't make sense to me, so yea, it's my ignorance for sure. (sorry)

    Thanks for any information or ideas.

    EDIT: If I turn OFF "Use Frustum Culling" on "GPU Instancer Prefab Manager" then the signs are visible. This is wrong? Am I stupid? (it's possible)
     
    Last edited: Oct 18, 2022
  35. Nanachi88

    Nanachi88

    Joined:
    Aug 10, 2022
    Posts:
    14
    Hello, I follow your tutorial in YT, but I have this error. I have tried using a simple prefab without LOD to a simple cube; however, the error still exist and the GPU instancing does not work like video showed me. Could you please tell me what to do to handle this error?


    upload_2022-10-19_8-52-31.png
     
  36. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    There might be a problem with the projection matrix or the depth texture used by Occlusion Culling. Sometimes other tools/features modify these and as a result cause issues with culling. You can try disabling the Occlusion Culling or checking the debugger to see if the depth texture is modified. If this does not help, email us a sample project and we can investigate what is causing the issue.

    Hi there,
    Looks like some files are not imported correctly. Please make sure you have the latest version of GPU Instancer installed, and then right click on the GPUInstancer folder and select Reimport.
     
  37. Skaltum

    Skaltum

    Joined:
    Nov 1, 2013
    Posts:
    28
    Hello,
    I'm having some issues with a tree creator tree which results in a mostly empty/transparant billboard.
    Only the branch shows up in the billboard, the leaves do not. I've tried overriding the cutoff but it has no effect.

    What might have caused this and how could I fix it? I can provide a unitypackage with the tree if that is useful.

    Edit for solution: The geometry mode "Billboard" from the tree creator is not suppored by GPU Instancer. Select the leaves in node in the tree creator and switch the geometry mode to a different mode like "Cross". Regenerate the billboards in the prefab manager. Set the geometry mode back to billboard.

    Thank you for your support Gurhän.
     

    Attached Files:

    Last edited: Oct 20, 2022
  38. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    I am not sure what is causing the issue. Please email us the unitypackage and we can investigate it.
     
    Skaltum likes this.
  39. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    334
    Hi, my fps is going down when using the prefab manager even though my tris and verts are being cut by half o_O

    Without
    upload_2022-10-19_11-3-13.png

    With
    upload_2022-10-19_11-3-31.png

    Then I used the profiler and the - RenderShadowMaps - step is being slowed when enabling the prefab manager, I tried to touch on shadow settings other prototype (disabling it increase the FPS in ~2 but as most part of the environment come from this prefabs, the visual get quite weird), without success, following with the profile images

    Prefab enabled
    upload_2022-10-19_11-16-36.png

    Prefab disabled upload_2022-10-19_11-17-30.png

    Also, a good amount of objects set on the prefab manager do not an advised amount of instances, I mean, some of them is 1-5 instances in a scene only, but in my project, the whole scene can be collected and reconstructed, like a sandbox, so initially, it does not have a good amount but it can increase to any number during the runtime and (if I understood the asset correct) the only way to make it as occluders during runtime is to adding it to the prefab manager and marking the - Enable Runtime Modifier - What am I doing wrong? Or how can I properly setup it up?
     
  40. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    Thank you very much for the quick response. Occlusion Culling was/is turned off on the camera.

    Before we go any further I need to know if I can deal with the following: In my scene I have a series of signs that have a couple of materials that are assigned at startup. I notice that this is not happening. All materials in are staying the same as they were originally.

    Also, one of those materials gets updated every frame (it's emission property) This too is not happening. Am I going to be able to still do this with this asset?

    If these are not possible, then that's fine and thank you for your time. No need to work on this further.
    --------------------------

    On your wiki you sent me it starts with this: "If a GPUI Manager in the scene has the occlusion culling feature enabled"

    So... I do not have a "GPUI Manager" within my scene. I do have a "GPUI Preset Manager", but I am guessing that is not what you're talking about.
     
  41. Rail9

    Rail9

    Joined:
    Feb 21, 2020
    Posts:
    28
    Hi!

    For some reason, objects created dynamically using the following script are not deleted even if Auto Add/Remove is checked.

    Those from scripts do not work correctly in both editor and build.
    Is it possible that I am doing something wrong?

    Is there any other way to do this besides Auto, as I checked the Wiki and could not see any examples of deleting from scripts?

    Objects placed by hand work correctly after build but are not deleted in the editor.
    I have queried this before, but in 2021.3.9.f1 the object is destroyed in the editor but remains on the screen.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. namespace GPUInstancer
    6. {
    7.     public class SponerObject : MonoBehaviour
    8.     {
    9.         public GPUInstancerPrefabManager GPUInstancerPrefabManager;
    10.         public List<GPUInstancerPrefab> listObjs = new List<GPUInstancerPrefab>();
    11.  
    12.         private List<GPUInstancerPrefab> listObjComp = new List<GPUInstancerPrefab>();
    13.         private GPUInstancerPrefab allocated;
    14.  
    15.         public float xMinRange;
    16.         public float xMaxRange;
    17.         public float yMinRange;
    18.         public float yMaxRange;
    19.         public float zMinRange;
    20.         public float zMaxRange;
    21.         public float range;
    22.  
    23.         public int instNumver;
    24.  
    25.         public
    26.  
    27.         RaycastHit hit;
    28.  
    29.         private void Awake()
    30.         {
    31.             Shoot();
    32.         }
    33.  
    34.         void Shoot()
    35.         {
    36.             for (int i = 0; i < instNumver; i++)
    37.             {
    38.                 int randomNumver = Random.Range(0, 3);
    39.  
    40.                 if (Physics.Raycast(transform.position, transform.forward + new Vector3(Random.Range(xMinRange, xMaxRange), Random.Range(yMinRange, yMaxRange), Random.Range(zMinRange, zMaxRange)), out hit, range))
    41.                 {
    42.                     if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Ground"))
    43.                     {
    44.                         listObjComp.Add(instancerPrefab());
    45.                     }
    46.                 }
    47.             }
    48.         }
    49.  
    50.         private GPUInstancerPrefab instancerPrefab()
    51.         {
    52.             allocated = Instantiate(listObjs[Random.Range(0, listObjs.Count)], hit.point, Quaternion.Euler(0, Random.Range(0, 360), 0));
    53.             return allocated;
    54.         }
    55.  
    56.         private void Start()
    57.         {
    58.             GPUInstancerAPI.RegisterPrefabInstanceList(GPUInstancerPrefabManager, listObjComp);
    59.             GPUInstancerAPI.InitializeGPUInstancer(GPUInstancerPrefabManager);
    60.         }
    61.     }
    62. }
     
  42. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    First of all, it is important to know that GPU Instancer is not a standalone culling solution. GPU Instancer, as the name suggests, is a GPU instancing solution that also uses various culling techniques to improve the performance of instancing. Please see Terminology documentation to learn about how GPU instancing works.
    So you need to use GPU Instancer with objects that are suitable for instancing to see benefit. Please see Best Practices documentation for more information.
    When you use GPUI with objects that only have few instances, you will not see any benefit from it. Additionally every prototype you have on the manager has a performance affect caused by draw calls and compute shader operations. So when you have a lot of prototypes with few instances, this can have an adverse affect on performance.

    GPU instancing works by batching draw calls for objects that use the same material and mesh. So you can not assign different materials to instances of the same prototype. Please see Terminology documentation for more information.
    When there are simple property changes on the materials, these can be handled by using Material Variations. Please see ColorVariations demo in the package for an example usage.

    Hi there,
    Auto. Add/Remove Instances is a runtime feature that automatically adds/removes instances of a prototype when they are added/removed after the manager is initialized. So if you want to use auto. add/remove, only call the InitializeGPUInstancer method before adding/removing instances.

    RegisterPrefabInstanceList methods adds a list of instances to the PrefabManager which are processed when InitializeGPUInstancer method is called afterwards. If you are adding/removing all the instances before initializing the manager, then you can use the following API methods to register/unregister instances:
    2.1 RegisterPrefabInstanceList
    2.2 UnregisterPrefabInstanceList
    2.3 ClearRegisteredPrefabInstances
    2.4 ClearRegisteredPrefabInstances
     
    JamesWjRose likes this.
  43. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    Thanks for the details. I am looking at a hybrid approach.

    I'll try to get a copy of the project with just the issue (previous post) soon. I'll dm you a link

    Have a wonderful weekend
     
  44. Rail9

    Rail9

    Joined:
    Feb 21, 2020
    Posts:
    28
    I am trying to delete the same object, but before the object is deleted I called GPUInstancerAPI.InitializeGPUInstancer(GPUInstancerPrefabManager);, but for some reason the previous object is deleted. The object that I want to disappear now does not disappear.

    I read that it should be done before the object is destoryed, but I thought it would be meaningless to initialize the object before it is deleted, so I tried executing it after the object is deleted, but the result is the same.

    The script on the object side is as follows
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5.  
    6. namespace GPUInstancer
    7. {
    8.     public class TreeHitDamage : MonoBehaviour
    9.     {
    10.         public float treeHealth;
    11.         public float treeDamage;
    12.         public float time;
    13.         public float activeFalsetime;
    14.         public int randomAxis;
    15.  
    16.         public bool rigidOn;
    17.  
    18.         public SpawnerObject spawnerObject;
    19.  
    20.         private void Awake()
    21.         {
    22.             spawnerObject = GameObject.Find("Instantiater_Tree").GetComponent<SpawnerObject>();
    23.         }
    24.  
    25.         private void Update()
    26.         {
    27.             if (treeHealth <= 0)
    28.             {
    29.                 GetComponent<CapsuleCollider>().enabled = false;
    30.                 GetComponent<BoxCollider>().enabled = true;
    31.  
    32.                 if (!rigidOn)
    33.                 {
    34.                     rigidOn = true;
    35.                     randomAxis = Random.Range(0, 4);
    36.  
    37.                     GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
    38.  
    39.                     if (randomAxis == 0)
    40.                     {
    41.                         transform.rotation = Quaternion.Euler(5, 0, 0);
    42.                     }
    43.  
    44.                     if (randomAxis == 1)
    45.                     {
    46.                         transform.rotation = Quaternion.Euler(-5, 0, 0);
    47.                     }
    48.  
    49.                     if (randomAxis == 2)
    50.                     {
    51.                         transform.rotation = Quaternion.Euler(0, 0, 5);
    52.                     }
    53.  
    54.                     if (randomAxis == 3)
    55.                     {
    56.                         transform.rotation = Quaternion.Euler(0, 0, -5);
    57.                     }
    58.                 }
    59.  
    60.                 time += Time.unscaledDeltaTime;
    61.  
    62.                 if (time > activeFalsetime)
    63.                 {
    64.                     spawnerObject.PrefabInitialized();
    65.                     Destroy(gameObject);
    66.                 }
    67.             }
    68.         }
    69.  
    70.         public void TreeHits()
    71.         {
    72.             treeHealth -= treeDamage;
    73.         }
    74.     }
    75. }
     
    Last edited: Oct 22, 2022
  45. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    Unfortunately I did not understand what the issue is exactly from the code. Can you please email us a sample project so we can investigate it?
     
  46. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    236
    Hi, I have two questions.

    Will this this work with World Streamer 2? It looks like they have a few overlapping features so I wonder if I should choose one over the other or if I can use both.

    I'm using shaders from The Vegetation Engine. Is it possible to to use those with this asset?
    Ignore that, I saw on their store page that it does.

    So instead I wanna ask if this asset can use Amplify Impostors?
     
    Last edited: Oct 25, 2022
  47. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    I did not test World Streamer before so I can not say for sure, but there were several people who contacted us previously that were using it with GPUI without issues.
    As for Amplify Impostors, it is tested, and works out of the box with GPUI. See this documentation for more information.
     
    knas01 likes this.
  48. Werfaso

    Werfaso

    Joined:
    Mar 1, 2021
    Posts:
    8
    Hi, ran into two problems:

    1. If I set up prefabs in the prefab manager in the editor, and these prefabs are addressable, when trying to add new instances, I get an error that the prefab type is not found in the manager
    Code (CSharp):
    1. GPUInstancerAPI.RegisterPrefabInstanceList(ctx.PrefabManager, trees);
    2. GPUInstancerAPI.InitializeGPUInstancer(ctx.PrefabManager);
    Also, when instantiating a prefab, I get an error in GPUInstancerPrefabRuntimeHandler with the text "Can not find GPUI Prefab Manager for prototype"

    I think it has to do with the identity of the prototypes in the manager and instance_id or m_cachedPtr or hashCode, because there is no such problem when I don't use addressable prefabs of my objects.

    I have a bad solution now:
    Code (CSharp):
    1. var prefabs = new List<GPUInstancerPrefab>(ctx.PrefabManager.prefabList.Select(o => o.GetComponent<GPUInstancerPrefab>()));
    2. foreach (var prefab in prefabs) {
    3.     GPUInstancerAPI.RemovePrototypeAtRuntime(ctx.PrefabManager, prefab.prefabPrototype);
    4. }
    5. foreach (var resourceName in ResourceNames.Prefabs.Client.Game.PrototypeData.Prefab.Values) {
    6.     var prefabPrototype = _resourceStorage.GetGpuInstancerPrefabPrototype(resourceName);
    7.     var defineGameObjectAsPrefabPrototypeAtRuntime = GPUInstancerAPI.DefineGameObjectAsPrefabPrototypeAtRuntime(_prefabManager, prefabPrototype.prefabObject);
    8.     GPUInstancerAPI.AddInstancesToPrefabPrototypeAtRuntime(_prefabManager, defineGameObjectAsPrefabPrototypeAtRuntime, new List<GameObject>());
    9. }
    10. GPUInstancerAPI.RegisterPrefabInstanceList(ctx.PrefabManager, trees);
    11. GPUInstancerAPI.InitializeGPUInstancer(ctx.PrefabManager);
    so I delete and re-register the prototypes when the game starts, I can do this because I have a procedurally generated world

    2. The problem described above
    Assertion failed on expression: 'buildTarget.platform >= kFirstValidStandaloneTarget'
    UnityEngine.GUIUtility: ProcessEvent (int,intptr,bool&)
    Came up after installing the package

    version UNITY 2021.3
    version package 1.7.4
     
  49. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    539
    Hi there,
    1. I am not sure why you are having this issue with the addressable. It might be related to how you set it up (e.g. some required objects were not loaded), or a Unity bug. If you can email us a sample project we can investigate.
    2. The "Assertion failed" error messages are caused by a recent change in Unity. There are some files within the package that has the ".compute" extension but does not have a kernel which results in this error message during build. Unity might fix this since it looks like a bug, but in any case we will change the file extensions on the next update. For now you can ignore these messages, since they do not affect any functionality.
     
  50. Raul_T

    Raul_T

    Joined:
    Jan 10, 2015
    Posts:
    363
    Hey, sorry for bothering you, you were the most recent result when searching for this issue - we are running into the same problem, though on 2019.4 with BiRP. And I see there is no hint of this being fixed in latest GPU Instancer changelogs (or is it fixed but not logged?). Did you guys found any solution/workaround to this for your project until it gets fixed by the GPUI devs? It's been giving me headaches for the past few days now and figured it's worth asking...