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.

[RELEASED] GPU Instancer

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

  1. SkmaestroF22

    SkmaestroF22

    Joined:
    Aug 29, 2015
    Posts:
    4
    Unity 2023.1 is supported?
     
    heartingNinja likes this.
  2. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Hi there,
    No-GameObject Workflow API methods such as InitializeWithMatrix4x4Array and UpdateVisibilityBufferWithMatrix4x4Array take GPUInstancerPrefabManager as parameter, so you can call these methods twice with two Prefab Managers with different cameras.
    Hi there,
    There are currently no known issues for 2023.1. But we can not guarantee that everything will work smoothly with a tech stream Unity version, since there are frequent changes - new features.
    We will look into issues in latest tech stream, however very often the issues are caused by Unity bugs and there is not much we can do other than wait for Unity to fix it.
    We officially support and recommend LTS versions. Please also make sure to check the Minimum Requirements and Known Limitations before making a decision.
     
  3. ruimtebever44

    ruimtebever44

    Joined:
    Jan 3, 2020
    Posts:
    6
    Hello. I LOVE the asset. Been using it successfully for a while now, but I recently started using addressables for loading & unloading parts of the level. These area containers contain instances that should be added to the GPUInstancer. However, they do not seem to work in this case.

    If I turn off "add/remove instances on runtime", I can manually add them in the unity editor, but it gives errors during build time:
    Can not find runtime data for prototype: <name_of_prefab>. Please check if the prototype was added to the manager and the initialize method was called.

    Any clue how to solve it?

    Also, this may be hidden in the docs somewhere but I'm wondering if I can just add a list of positions/scales/rotations during runtime so I can stream large amounts of foliage based on the player's position in a grid, without having to generate garbage by instantiating them as gameobjects first. And without slowing down the editor by having them instantiated already before runtime. And without using the cache option GPUI provides, because I'd prefer to be able to manage my own data and iterate a lot without any worries. I'm not using unity's terrain.
     
    Last edited: Oct 30, 2023
    CheMBurN likes this.
  4. Wawwaa

    Wawwaa

    Joined:
    Sep 30, 2017
    Posts:
    165
    hi... this game was not possible without GPU Instancer and Crowd Animation. meet Create Your Own Universe on Steam Early Access.

    let me share this video first:



    and then this:



    this is a go every single place you can see on screen type of game.

    plase, support us, share... help us spread the word.

    thanks
     
    GurhanH likes this.
  5. CheMBurN

    CheMBurN

    Joined:
    Dec 13, 2020
    Posts:
    20
    I am running into the same problem with addressables. Anything instantiated with serialized prefabs work just fine. Any prefabs loaded through addressables appear to be the problem.

    EDIT: So after some debugging it seems like the prototype instance of the prototypes loaded through the addressables arent the same as the ones referenced by the dictionary in the GPUIPrefab manager. I did a super hacky string check on the prototype SO, if it matched, I casted and fed the prototype from the dictionary into the addressables loaded prefab and added it back to dictionary. It works fine now lol.
     
    Last edited: Nov 2, 2023
  6. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Hi there,
    and thank you for your support.
    Managing the references can get tricky with addressables. If Prototype ScriptableObjects-Prefabs-Scenes are packed separately and/or not loaded in correct order, some references will be lost.
    It might be easier to manage the references, if you define the prototypes at runtime using the DefineGameObjectAsPrefabPrototypeAtRuntime or AddPrototoypeToManager method instead of adding them in editor. Then you can make sure the prefab is loaded before adding it as a prototype to the Prefab Manager and disregard the scene loading.
    You can use the No-GameObject Workflow to render your foliage without GameObjects. There is also a button under Advanced Actions called Serialize Registered Instances, but its use might be too limited for your needs.
     
    Last edited: Nov 2, 2023
    ruimtebever44 and CheMBurN like this.
  7. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    unity instancer works, the objects (trees and rocks) are counted (66000) but in game or compiled, the trees have disappeared! (Unity 2022.3.1 built-in)
     
  8. homemacai

    homemacai

    Joined:
    Jul 22, 2020
    Posts:
    67
    Hey there, I gave a search before posting this but couldn't find it here, anyway.
    I am doing a graphics settings UI and want to have better control of GPUI, and couldn't find how to change some settings at Runtime. Max Detail Distance(Globally in detail manager) and Is Shadow Casting for individual prototypes (Prefabs,Trees and DetailManager).
    I tried with no luck, doing this for the MaxDetail Dist:
    Code (CSharp):
    1. gpuiDetailManager.terrainSettings.maxDetailDistance = 0;
    2. GPUInstancerAPI.InitializeGPUInstancer(gpuiDetailManager);
    As for the shadow casting I belive it's by using this ChangeLODShadow() function, I tried:
    Code (CSharp):
    1. GPUInstancerAPI.ChangeLODShadow(gpuiDetailManager.prototypeList[0], 0, true);
    With and without calling UpdateDetailInstances() after it, but nothing changes. Any advice? Thanks!
     
    Last edited: Nov 4, 2023
  9. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    What is going on ????
    not all instantiated objects appear



     
  10. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Hi there,
    For editing detail draw distance at runtime, please use:
    Code (CSharp):
    1. gpuiDetailManager.prototypeList[0].maxDistance = 0;
    For disabling shadow casting at runtime, please use:
    Code (CSharp):
    1. gpuiDetailManager.prototypeList[0].isShadowCasting= false;
    Hi there
    There are few possible reasons why some objects are not rendered when using GPU Instancer.
    Most common issue is when a custom shader is not setup correctly for GPUI. Please see the Shader Setup Guide and make sure that your shaders are compatible with GPU instancing. (For example, if your shaders' vertex function does not call the UNITY_SETUP_INSTANCE_ID method, the instances will not be positioned correctly)
    Another possibility is that the occlusion culling is not working correctly. Most of the time these can be solved by changing the culling settings for the prototypes such as Occlusion Cull Offset, Occlusion Cull Accuracy or Bounds Size Offset.
    If this does not help, please email us a bug report with a sample project following this guide and we can investigate.
     
  11. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    I'm not used to modifying shaders. Which one should I change and how? I thought everything would work the first time.
    I did "Regenerate GPUI Shaders" without success.
    I'm using Unity 2022.3.1 built-in
    In any case, no instantiated object appears, whether vegetation or buildings.
    I couldn't find the log file
     
  12. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Please make a support request via email with a sample project following this guide and we can investigate.
     
  13. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    90
    Is it possible to register GameObjects dynamically instead of adding them manually in the inspector?

    I was looking at the no-gameobject approach and it appears I still need to add the prefabs to the manager in order to get this to work. I have GameObjects that get converted to entities (so the GameObject is destroyed in the process). These GameObjects have an authoring script that runs during the conversion phase and before the GameObject is destroyed and it's here I'd like to dynamically add it to the manager for rendering.
     
  14. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Hi there,
    If you wish to define prototypes at runtime, you can use the DefineGameObjectAsPrefabPrototypeAtRuntime method. However please make sure first that you understand how GPUI works. You should have few prototypes with many instances to benefit from GPU instancing (see Instance Counts).
     
  15. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    90
    Thanks, I have actually looked into that link prior and conducted some personal tests. Although, for my current project, there will be times where entity count is low and thus there will be little to no benefit of instancing, it could blow out to thousands. Performance impact of low entity count will be negligible. It's the high entity counts that I'm trying to tackle. I've done some work with DrawMeshInstanced and can happily get around 50+k entities rendered. Which is probably more than enough for my needs. But it's been a bit of work getting it to run nicely with LODs and CPU based culling. So, I figured I'd try your asset out and see what I can do.

    Great product btw. I purchased it back in January and only now starting to look into it.
     
    Last edited: Nov 10, 2023
    GurhanH likes this.
  16. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    I made a demo scene which works well but not in my project. I must have made a mistake but which one?
    Unity 2022.3.1 built-in



    Editor :



    Game:

     
    Last edited: Nov 13, 2023
  17. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    I have no news and this Asset does not work on my project. I will request a refund.
     
  18. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Please make a support request via email with a sample project following this guide and we can investigate.
     
  19. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    suddenly the vegetation now appears. I don't know what happened. I continue to do tests

    Edit

    actually, I had disabled the script so I thought it worked.

    I sent a mail
     
    Last edited: Nov 15, 2023
  20. ghassan_khadra

    ghassan_khadra

    Joined:
    Aug 24, 2019
    Posts:
    2
    I have an issue with white shadow whenever i hit the tree ,can you help here ?
     

    Attached Files:

  21. SAMYTHEBIGJUICY

    SAMYTHEBIGJUICY

    Joined:
    Jul 12, 2023
    Posts:
    22
    Heya, I love GPUI it's much better than nature renderer in lots of ways. But I have a weird bug - the prototype pictures never show up for me and when i try text mode the names aren't synced up with the prefabs. Also in NR I can add detail/trees to the terrain with microverse paint tools and then resync the NR shader to pick these up for instancing but the GPUI docs say you can only do this at the outset of the conversion and then you need to add prefabs manually to the manager? Do I really need to go through this prototype system manually every time if I want to add some foliage? Some presets have all sorts of vegetation preset and it's not a great workflow system to 1. figure out which prefabs are in the preset and then 2. add them all manually to the GPUI manager before i can start painting. From a workflow point of view it doesnt really make much sense to me. Your method of instancing is awesome though and lightening fast (very impressive).

    upload_2023-11-15_21-59-28.png
     
  22. SAMYTHEBIGJUICY

    SAMYTHEBIGJUICY

    Joined:
    Jul 12, 2023
    Posts:
    22
    Also - this happens A LOT when I hit generate prototypes. It's usually a 50% chance of crashing at this rate upload_2023-11-15_22-14-41.png
     
  23. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    the editor crashes a lot these days and not only because of GPUI
     
  24. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    90
    Unity 2022 has been rather buggy/unstable in general. I've been trying almost every LTS version released and it hasn't improved. I keeping to 2021 for this very reason.
     
  25. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Hi there,
    It looks like on of the passes of the tree shader does not have GPU instancing support. You can see a detailed explanation on this Unity documentation or see a GPU Instancer specific guide in this documentation to learn how to add GPU instancing setup to shaders.
    Common issue with some old shaders is that they do not have the UNITY_SETUP_INSTANCE_ID call on the vertex function.

    Hi there,
    GPUI creates ScriptableObjects for each prototype to store their settings. If you modify the prototypes outside of the GPUI manager, you need to use the "Generate Prototypes" button. When you use this button, the manager will delete all previous prototype settings and create new ones. Frequently deleting and adding assets can sometimes cause issues in some Unity versions (there might also be third party code that is causing trouble with the asset import process). That is why we recommend adding/removing the prototypes from the Manager, instead of making hard resets. However if you need to edit the prototypes frequently from another system, I recommend disabling the GPUI manager until your edits are completed, and then using the "Generate Prototypes" button only once before you re-enable the GPUI manager.

    If you encounter this issue again and can provide us repro steps or a sample project, please email us a bug report following this guide.
     
  26. SAMYTHEBIGJUICY

    SAMYTHEBIGJUICY

    Joined:
    Jul 12, 2023
    Posts:
    22
    Thank you for the additional colour but I suppose I don't intend to modify so much existing prototypes but more like add or paint with vegetation to my terrain that I previously haven't used if you see what I mean. For these cases I would have expected there to be a method that adds new prototypes rather than needing a hard reset on all existing ones and/or the need to add them manually. i.e. basically check the terrain for new objects/trees/detail and add the necessary scriptable objects.
     
  27. jmgek

    jmgek

    Joined:
    Dec 9, 2012
    Posts:
    90
    GPU Instancer allows you to add and remove instances during runtime. This can be done automatically without writing any additional code, in which case GPUI will keep track of new instantiations (or destroying) of the prefab instances and will handle the prototype GPU buffers accordingly. For more control, you can also use the API to handle this yourself - or completely register and initialize the managers with exactly the instances you want. You can see below how to use each option:
    https://wiki.gurbu.com/index.php?ti...matically.29_Add.2FRemove_Prototype_Instances

    I just want to confirm that I fully understand this, does that mean as long as I have a prefab included as a prototype all runtime instancing of that prefab (prototype) will be handled by the buffer (I'll gain the effects of the package)?

    And quick follow up if that's the case, should I worry about pooling (destroying) objects? I wasn't able to find any discussion on that.

    Also thank you, solid package!
     
  28. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Yes. When you enable the Auto. Add/Remove Instances option, the Prefab Manager will attach a script on the prefab. When prefab instances are instantiated or destroyed, this script will automatically handle buffer updates.

    When we talk about adding/removing instances, we are talking about rendering them with GPUI or not. When you add a prefab instance to the Prefab Manager, that means that instance will be rendered by GPUI. GPUI does not handle instantiating, destroying or pooling objects.
     
  29. sdargiewicz

    sdargiewicz

    Joined:
    Aug 2, 2018
    Posts:
    4
    Is there a way to specify the shadow LODs separately in the detail manager? Only the tree manager lets me do it. Also being able to specify the shadow distance would be very useful for performance.
    upload_2023-11-22_9-34-11.png
     
    Last edited: Nov 23, 2023
  30. RPKMN1

    RPKMN1

    Joined:
    Feb 13, 2017
    Posts:
    36
    Hello,
    I have been using a setting in my game to allow the users to toggle grass off and on. I added that because of the big performance hit that grass was having.
    Once I added GPUI to the scene, performance improved, but when I disable the grass via this setting, it is still rendered. GPUI doesn't seem to be respecting the enable/disable state of the parent object. is there a way to get around this?
     
  31. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    275
    did anyone integrate GPUI with boing kit Reactor Field GPU Sampler yet?
     
  32. jmgek

    jmgek

    Joined:
    Dec 9, 2012
    Posts:
    90
    Thank you so much, amazing tool.

    Final question as I didn't see a best practices for this.

    In the event that I'm spawning thousands of tiles what's the best approach to handle materials / textures to get the most out of this?

    Do I have a way to dynamically add a texture to a material at runtime and still gain the prototype perf? Or is my option to just create each tile as a prototype with seperate materials?

    Thanks again!
     
  33. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    275
    Hello dev,
    Pls watch this.

    What do you think about GPU instances on moving platform?
    Are they worth updating with GPU Instancer or just let them be gameobjects?
    I think to work with them we need to update the transform matrix everyframe, so all the moving platforms should have a special prefab manager to handle them only. Still, is this a good idea?
     
  34. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Hi there,
    Detail Manager does not make separate draw calls for shadows, so unfortunately it does not support custom shadow LODs and custom shadow distance.

    Hi there,
    GPUI stops rendering when the GPUI Manager is disabled.
    If you can explain how you are using GPUI (e.g. Detail Manager with a terrain or Prefab Manager with grass prefabs) and how you are disabling the grass (e.g. sample code and a screenshot of the GameObject hierarchy), then I can be more specific on how to set it up correctly.

    Hi there,
    GPU instancing works by rendering the same mesh and material many times with a single draw call. So having different materials with different textures would mean different draw calls/prototypes.
    Best practice in this case would be to use Material Variations. You can create a texture atlas where you pack multiple textures into one, and set different UVs for each instance using material variations. This way you can have different textures for the same prototype. However you need to do some coding, both on C# and shader side.
    There is a material variations demo called ShaderGraphVariations which should be available if you download GPUI to a URP or HDRP project. There you can see an example usage of UV variations.

    Hi there,
    Most performant approach would be to use one Prefab Manager with a combined matrix array and partially update the matrices for the moving/rotating instances either with a compute shader or a multithreaded job.
    Using GameObjects will be slower because of the transform updates and memory usage. Multiple managers will cause multiple draw calls for the same prototypes which again will be slower. But these options are much easier to implement.
     
    Spikebor and jmgek like this.
  35. RPKMN1

    RPKMN1

    Joined:
    Feb 13, 2017
    Posts:
    36
    what I had been doing was just enabling/disabling a container gameobject that contained all my grass. I did notice that if I leave that container disabled, thus disabling all my grass objects via their parent, I can then just enable/disable GPUI as needed to turn off the grass entirely.

    is that the suggested way of doing things?
     
  36. timothee_le_corre

    timothee_le_corre

    Joined:
    Sep 20, 2023
    Posts:
    7
    Hello. I have some issues with the removal of details on my terrains.
    I have multiple terrains that are activated/ deactivated base on the player position.
    The details are removed around buildings placed by the players, in digged holes (using digger) and also in holes digged by our underground caves prefab.
    My issue is when the player placed buildings, dig holes etc... it removes details with no issue, but if my player go far away and come back to the same terrain, the details are not removed anymore. So I guessed I have to remove them when the terrain is activated again, so I store the bounds of where I need to remove the details. But when I do that some details are not removed.
    The only solution that work was to remove them in an update method on each terrains, but it cause a huge FPS drop.
    What I would need is an event or something that tell me when I can remove the details I stored, something like telling the details manager is ready to remove details or the player is in range of the bounds so it can remove details. Does something like that exist in the current code ? Or is there a way to catch this information from somewhere ?
     
  37. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    This only happens when the game is compiled. I feel like I have a tree trunk around my head.
     
  38. Werfaso

    Werfaso

    Joined:
    Mar 1, 2021
    Posts:
    8
    Hello, I want to know what are the plans for adding motion vectors? And for crowd animation. If there are no plans to support, are there any workarounds or algorithm for manual implementation?
     
  39. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Sure, it is one of the ways.
    If you do not need the GameObjects, you can also use the No-GameObject workflow. There is also a Serialize Registered Instances option.

    Hi there,
    StartListeningGPUIEvent method might be helpfull:
    Code (CSharp):
    1. GPUInstancerAPI.StartListeningGPUIEvent(GPUInstancerEventType.DetailInitializationFinished, MyMethod);
    Shaders that does not support GPU Instancing can cause this issue. Please see Creating shaders that support GPU instancing and GPUI shader setup guide for more information. If this tree shader is from a third party asset, you might get help from its developer in making it GPU instancing compatible.

    Hi there,
    There is not an easy workaround as far as I know. It requires core design changes (e.g. different render methods, additional GPU buffers, shader code changes etc.) that we are not planning to support in the current system.
    On that note, we have a new asset in development where the core system is redesigned to overcome various shortcomings of the current design. It will also include support for motion vectors. However it does not have a release date yet.
     
    RPKMN1 likes this.
  40. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    Why is my FPS almost not increasing?


     
  41. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    The GPUI Manager already tells you the reason on your previous screenshot:
    upload_2023-11-30_11-55-4.png

    Try for example removing the prototypes that have under 300 instance counts and see if it makes a difference.
    To learn how to get better performance while using GPUI, please read the Best Practices documentation.
     
  42. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    I understand. It would have been handy to be able to sort the instances by size since I have a lot of them.
     
  43. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
    What happened to the tree shadows?
     
  44. timothee_le_corre

    timothee_le_corre

    Joined:
    Sep 20, 2023
    Posts:
    7
    Thanks for the help. But the event doesn't give me a way to identify the terrain were the details are initialized. Is there another event or a variable I can check combined with DetailInitializationFinished ?
     
  45. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Looks like the shadow pass of the tree shader have an alpha testing issue. Some shaders make the _ALPHATEST_ON definition manually, which can cause issues with auto shader conversion. For example, this line should be before everything else:
    Code (CSharp):
    1. #define _ALPHATEST_ON 1
    If you send an email with a sample project, I can help you fix the issue. Or if the shader is from another asset, you can ask its developer for help with GPUI integration.

    There is not one, but it would be simple to add another event with a parameter. I will include it in the next update. If you can contact the support email with your invoice number, I can send you the modified code.
     
  46. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    264
  47. IllogicalGames

    IllogicalGames

    Joined:
    Apr 16, 2013
    Posts:
    170
    hi Gurbu,
    thanks for your great asset. i have a question. im planning to make a huge world for a mobile game. however i im not sure how would i achieve my world. i need your suggestion.

    so right now im using unity terrain with size 2000x2000. i lowered the heightmap, resolution, play around with pixel error until i am satisfied with the terrain drawcall. im achieving around 7-11 drawcall for the scene with the terrain only.

    next, i will populate the terrain with buildings, props, and put some trees. now since i dont want the buildings to be similar to each other, i split the building parts into multiple modular models such as pillar, wall, window, door, roof. with this, i can create multiple building variations.

    so my question is,

    1) since i have a lot of modular parts, along with props, trees etc to include in the prefab instancer, is there a limit how many prefabs i can be put in the prefab instancer?

    2) is 2000x2000 terrain size too big for mobile?

    3) which is better, scene full with prefabs, or empty scene and instantiated prefab on load?

    4) does scene full with prefab consume more memory compared to instantiate prefab on load?
     
  48. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Hi there,
    and thank you for supporting GPU Instancer.
    There is not a hardcoded limit for the number of prefab prototypes you can add to the Prefab Manager. However we recommend to add prefabs that have high instance counts (see The More Instance Counts, the Better). For example, if you have many prefabs with low instance counts (e.g. under hundred) where only a few of them visible at a time, it would be better to let Unity draw them using other batching techniques (see Batching).
    And for your other questions, they are design choices and not directly related to GPUI. You should decide based on your minimum system requirements. If memory is a big concern, using no-GameObject workflow can help.
     
  49. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,079
    Hi,

    I have a problem when building for PS5: all compute shaders output an error message when building:
    upload_2023-12-7_17-8-41.png

    Any Idea how to fix this?
     
  50. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    489
    Hi there,
    Are you using an older version? If so, you need to upgrade. This issue was fixed in v1.7.5.