Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

[RELEASED] GPU Instancer

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

  1. mariv1k_

    mariv1k_

    Joined:
    Oct 22, 2020
    Posts:
    2
    [Help]. First of all thanks for this addon, good work. I loaded the example CrowdAnimationDemoScene and got lower performance than expected. The setup is working and no errors are shown, however non of the demos seem to run at the desired framerate. ie the asteroid demo runs at "only" 200fps. Is that ok? environment: linux, rtx 2060, ryzen 3600x. i'm attaching some profiler screenshots and info (150MB data file) in case

    Screenshot_2023-12-09_19.53.35.png Screenshot_2023-12-09_19.55.47.png Screenshot_2023-12-09_19.56.11.png
     
  2. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    322
    same thing for me
     
  3. unity_dev3194

    unity_dev3194

    Joined:
    Apr 17, 2017
    Posts:
    80
    Hello, I'm using GPU Instancer with MapMagic 2. I keep getting this error when entering playmode:

    NullReferenceException: Object reference not set to an instance of an object
    GPUInstancer.GPUInstancerMapMagic2Integration.MapMagicTerrainAddDetailManager (UnityEngine.Terrain terrain) (at Assets/GPUInstancer-Integration/MapMagic2/GPUInstancerMapMagic2Integration.cs:428)
    GPUInstancer.GPUInstancerMapMagic2Integration.MapMagic2TileApplied (MapMagic.Terrains.TerrainTile terrainTile, MapMagic.Products.TileData tileData, MapMagic.Products.StopToken stopToken) (at Assets/GPUInstancer-Integration/MapMagic2/GPUInstancerMapMagic2Integration.cs:103)
    MapMagic.Terrains.TerrainTile+<ApplyRoutine>d__54.MoveNext () (at Assets/MapMagic/Terrains/TerrainTile.cs:828)
    Den.Tools.Tasks.CoroutineManager.Update () (at Assets/MapMagic/Tools/ThreadManager/CoroutineManager.cs:147)
    MapMagic.Core.MapMagicObject.Update () (at Assets/MapMagic/Core/MapMagicObject.cs:142)
     
  4. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    I was not able to reproduce the issue on the CrowdAnimationDemoScene. It might be caused by a specific setting or an issue on a specific Unity version. If you can contact support email with a sample project, I can investigate.
    As for the 200fps, you might have VSync or another limiting factor that prohibits the demo scene to run at a higher fps.

    Hi there,
    and thank you for reporting the issue.
    Looks like there is a missing null reference check at GPUInstancerMapMagic2Integration.cs:428. I will add the fix to the next update. If you can contact support email with your invoice number, I can send you the fixed files.
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,897
    I'm using GPU Instancer to render terrain trees created with Unity's Tree Creator, and I'm experiencing multiple visual issues. GPU instancer looks like it can increase performance in my project dramatically so I really hope the visual side can be worked out, so I can use it.
    • The trees do not pick up tree instance colors set in the terrain data. Affects both 3D models and billboards.
    • The billboards look wrong (weirdly high contrast) and don't seem affected by lighting, apart from the translucency effect.
    • The transition between 3D model and billboard looks glitchy with the trees looking semi-transparent or as if using an additive shader.
    • There are glitchy flashing effects of trees when new terrains are added to the manager (at least I think that's what's causing it). Happens whether using occlusion culling or not.
    See this video for all the mentioned issues:


    I also have these warnings in console (each one repeated many times):
    • Metal: Fragment shader missing buffer binding at index 3 (gpuiInstanceLODData / GPUInstancer/Nature/Tree Creator Leaves Optimized)
    • Metal: Fragment shader missing buffer binding at index 3 (gpuiInstanceLODData / GPUInstancer/Billboard/2DRendererTreeCreator)
    • Metal: Fragment shader missing buffer binding at index 3 (gpuiInstanceLODData / GPUInstancer/Nature/Tree Creator Bark Optimized)
    Note that the issues described in this report happen also when I disable Metal, so they are likely not the source of the described problems. However, it would be preferable if these warnings could be fixed as they are distracting.

    Have anyone had similar issues? Or did anyone get Tree Creator trees working well including nice transitions between 3d model and billboard?

    Using GPU Instancer v1.8.0.
    Tested with Unity 2019.4.40f1 and Unity 2022.3.14f1; the issues appear in both.
    Builtin render pipeline, standalone target, authoring in Mac editor on M1 MacBook Pro.

    (I've sent an email with repro project to Gurbu as well.)
     
    Last edited: Dec 14, 2023
    raulrusboy likes this.
  6. Nenad_b

    Nenad_b

    Joined:
    Nov 27, 2019
    Posts:
    1
    Hi guys,
    I added GPUI's Tree Manager on my already painted terrain (with trees and bushes) and shader are ok but when I play the game all painted assets from the terrain are gone (invisible). Also, when I disable GPUI script from Tree Manager everything comes back. Does anyone have any suggestion about what could be a problem? Thx

    I'm using Unity 2021.3, HDRP project and GPUI 1.8. v
     
    Last edited: Dec 13, 2023
  7. bh4786

    bh4786

    Joined:
    May 24, 2017
    Posts:
    23
    Hi! Just wondering if it's possible to use a single detail manager with multiple terrain tiles. It's kind of tedious when I want to change values or colors and I have to do it for every terrain tile. Unless there's a better way to do this...?
     
  8. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    Hey there

    We're using GPU Instancer's Crowd system and having a few things that keep happening:

    1) When I have the GPU Instancer in the scene the inspector breaks and it doesn't display anything. Literally the only thing the inspector is showing is this:
    2023-12-14 10_52_20-Coop.Client - GameplayMap - Windows, Mac, Linux - Unity 2022.3.13f1 _DX11_.png

    There are these errors in the console

    2023-12-14 10_54_07-Coop.Client - GameplayMap - Windows, Mac, Linux - Unity 2022.3.13f1 _DX11_.png

    Which are:
    Code (CSharp):
    1. InvalidCastException: Specified cast is not valid.
    2. GPUInstancer.CrowdAnimations.GPUICrowdUtility.GenerateCrowdPrototype (UnityEngine.GameObject go, System.Boolean forceNew, System.Boolean attachScript, GPUInstancer.CrowdAnimations.GPUICrowdPrototype copySettingsFrom) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/Static/GPUICrowdUtility.cs:357)
    3. GPUInstancer.CrowdAnimations.GPUICrowdUtility.SetCrowdPrefabPrototypes (UnityEngine.GameObject gameObject, System.Collections.Generic.List`1[T] prototypeList, System.Collections.Generic.List`1[T] prefabList, System.Boolean forceNew) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Core/Static/GPUICrowdUtility.cs:315)
    4. GPUInstancer.CrowdAnimations.GPUICrowdManager.GeneratePrototypes (System.Boolean forceNew) (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:278)
    5. GPUInstancer.CrowdAnimations.GPUICrowdManager.CheckPrototypeChanges () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:326)
    6. GPUInstancer.GPUInstancerManager.LateUpdate () (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:261)
    7. GPUInstancer.GPUInstancerPrefabManager.LateUpdate () (at Assets/GPUInstancer/Scripts/GPUInstancerPrefabManager.cs:81)
    8. GPUInstancer.CrowdAnimations.GPUICrowdManager.LateUpdate () (at Assets/GPUInstancer-CrowdAnimations/Scripts/GPUICrowdManager.cs:263)
    9.  
    and
    Code (CSharp):
    1. InvalidCastException: Specified cast is not valid.
    2. GPUInstancer.CrowdAnimations.GPUICrowdManagerEditor.DrawGPUInstancerPrototypeBeginningInfo (System.Collections.Generic.List`1[T] selectedPrototypeList) (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdManagerEditor.cs:270)
    3. GPUInstancer.GPUInstancerEditor.DrawGPUInstancerPrototypeBox (System.Collections.Generic.List`1[T] selectedPrototypeList, System.Boolean isManagerFrustumCulling, System.Boolean isManagerOcclusionCulling) (at Assets/GPUInstancer/Scripts/Editor/GPUInstancerEditor.cs:501)
    4. GPUInstancer.GPUInstancerManagerEditor.DrawGPUInstancerPrototypesBox () (at Assets/GPUInstancer/Scripts/Editor/GPUInstancerManagerEditor.cs:421)
    5. GPUInstancer.GPUInstancerPrefabManagerEditor.OnInspectorGUI () (at Assets/GPUInstancer/Scripts/Editor/GPUInstancerPrefabManagerEditor.cs:54)
    6. GPUInstancer.CrowdAnimations.GPUICrowdManagerEditor.OnInspectorGUI () (at Assets/GPUInstancer-CrowdAnimations/Scripts/Editor/GPUICrowdManagerEditor.cs:55)
    7. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass72_0.<CreateInspectorElementUsingIMGUI>b__0 () (at <7aeb7d7a52d04045b8a1c734633fa931>:0)
    8. UnityEditor.InspectorWindow:RedrawFromNative()
    9.  
    If I view the GPU Crowd Manager prefab that I made the inspector DOES display but it still throws the first error

    Any ideas? This has happened a few times and I've had to delete the whole thing and rebuild the crowd manager from scratch, which is fairly painful - we have dozens of mobs that are being animated with the system, so it takes a while to reset things up
     
  9. gekidoslair

    gekidoslair

    Joined:
    Sep 7, 2012
    Posts:
    128
    Related: is there an editor API that I can use the register prefabs from script? I have a script to configure the mobs (and their components), but setting up the GPU animation is a tedious manual process that I'd love to automate.
     
  10. raulrusboy

    raulrusboy

    Joined:
    Apr 20, 2020
    Posts:
    9
    I have this issue too.

     
  11. MorpheusXI

    MorpheusXI

    Joined:
    Jan 18, 2018
    Posts:
    75
    Hi, I'm going to be using scene streaming and as I'll be importing a lot of prefabs I'd like change the default import settings to accommodate the options for this shown below. How can I change the defaults for importing all the prefabs when using "Multi Add"?

    Also, ref the buffer should that be targeted to the minimum, average or max you would have of a prefab in a scene. Noting as I'll be scene streaming this could vary wildly per scene. And there will be 100's to 1000's of scenes.

    upload_2023-12-16_1-0-20.png
     
    Last edited: Dec 16, 2023
  12. Chunikus

    Chunikus

    Joined:
    Sep 5, 2020
    Posts:
    28
    Hey Gürhan

    I have strange issue using something close to no GO workflow. Possibly some bug on your end. 2022 LTS. I can try to reproduce it in blank project, but first look at how i call your api maybe i just do it a wrong way.

    Basically it would seem that instancing objects are not rendered for two consecutive frames for some reason. I'll post a link to the video but it's hard to see in the vid so here are screen shots frame by frame from video editing software. This is in build. (down bellow attachment)

    What happens is i click in ui new setting style for how room should look. Instancing ground tiles disappear for two frames there are not there at all. And then the correct new look renders.




    How the code works. There is a room that has collection of WorldCell classes, this class has VisualData struct inside, that has all the info on how to render a tile. WorldTilePrefab class binds to it and knows how to process VisualData struct. So when "ground style" or any other style changes first i set new ground style inside Room class. And then the room class goes and changes each it's cell's VisualData class (it's just enum of the ground "whiteTiles" or "blackCarpet", once done, it tells each tile to render world according to VisualData (it's basically collection of enums and bools).

    In my case only ground meshes are instanced (and fake shadows around walls).

    Telling tile to render new visualData class will tell every element to render anew, so changing ground or changing walls doesn't matter, everything is processed through one pipeline.

    So here is a relevant code inside "groundRendererForWorldTilePrefab" class.

    Code (CSharp):
    1. private void DoNormalVisualsInstanced(ref TileDataStruct visualDataStruct)
    2.     {  
    3.         StopGroundInstancing(); // will turn off previous rendering just for simplicity each new state of ground will turn off all possible previous states it was rendering.
    4.  
    5.         var texStyle = visualDataStruct.groundTextureStyle; // enum of new visual style
    6.         int index = (int) texStyle; //
    7.         ref Vector4 texOffsetVector = ref offsetsArr[index]; // just vector 4 of new texture tilling+offset coordinates
    8.         Vector3 hbs = new Vector3(0, 1, 1); // hue,brightness, saturation values
    9.  
    10.         WorldGridInancingManager.normalFloorWrapper.RegisterNewRenderRequestForNormalGround(this, ref texOffsetVector,ref hbs); // this is "wrapper class" that keeps the arrays of all ground tiles see below
    11.     }
    12.  
    13.     private void StopGroundInstancing()
    14.     {
    15.         if (myLastInstnacingFacilitatorForGround != null)
    16.         {
    17.             myLastInstnacingFacilitatorForGround.UnregisterRendering(myGroundInstancingIndexNumber);
    18.         }
    19.     }

    Ok so here is how the wrapper class looks :

    Code (CSharp):
    1. public class InstancingForGroundTilesNormalFloorWrapper
    2.     {
    3.         public string nameOfTheThing;
    4.         public Matrix4x4[] matrixArr;
    5.         public GPUInstancerPrefab prefab;
    6.         public int maxIteration;
    7.         public int arraySize;
    8.         public int totalCount;
    9.         public bool isDirty;
    10.         public FloorTileController[] floorTileControllersArr; // this is the "floor rendering class" from above
    11.         public int rearangeThreshhold;
    12.         public int rearangeCounter;
    13.         public Vector4[] tillingAndOffsetArr;
    14.         public Vector3[] hueShiftBrightnessSaturationArr;
    15.  
    16.  
    17.         private static readonly string hueShiftBrightnessSaturationString = "hueShiftBrightnessSaturation";
    18.         private static readonly string tillingAndOffsetBufferString = "tilingAndOffsetBuffer";
    19.  
    20.         public InstancingForGroundTilesNormalFloorWrapper(GPUInstancerPrefab prefabToUse, int firstMaxMustBeAtleastTwo)
    21.         {
    22.             nameOfTheThing = prefabToUse.gameObject.name;
    23.             prefab = prefabToUse;
    24.             arraySize = firstMaxMustBeAtleastTwo;
    25.             maxIteration = arraySize - 1;
    26.             matrixArr = new Matrix4x4[arraySize];
    27.             floorTileControllersArr = new FloorTileController[arraySize];
    28.             tillingAndOffsetArr = new Vector4[arraySize];
    29.             hueShiftBrightnessSaturationArr = new Vector3[arraySize];
    30.             totalCount = 1;
    31.             rearangeThreshhold = arraySize / 5;
    32.  
    33.             var prototype = prefabToUse.prefabPrototype;
    34.  
    35.             GPUInstancerAPI.InitializeWithMatrix4x4Array(prefabManager, prototype,
    36.                 matrixArr);
    37.             GPUInstancerAPI.DefineAndAddVariationFromArray(prefabManager, prototype, tillingAndOffsetBufferString,
    38.                 tillingAndOffsetArr);
    39.             GPUInstancerAPI.DefineAndAddVariationFromArray(prefabManager, prototype, hueShiftBrightnessSaturationString,
    40.                 hueShiftBrightnessSaturationArr);
    41.  
    42.  
    43.             GPUInstancerAPI.SetInstanceCount(prefabManager, prefabToUse.prefabPrototype, totalCount);
    44.         }
    45.  
    46.         public void RegisterNewRenderRequestForNormalGround(
    47.             FloorTileController floorTileController, ref Vector4 texOffsets, ref Vector3 hueShiftBrightnessSaturation)
    48.         {
    49.             var number = floorTileController.myGroundInstancingIndexNumber;
    50.             UnregisterRendering(number);
    51.  
    52.             int instanceNumber = totalCount;
    53.             totalCount++;
    54.             ref var matrix = ref matrixArr[instanceNumber];
    55.             var transform = floorTileController.normalFloorTransform;
    56.             matrix.SetTRS(transform.position, transform.rotation,
    57.                 transform.localScale);
    58.             floorTileControllersArr[instanceNumber] = floorTileController;
    59.             floorTileController.myGroundInstancingIndexNumber = instanceNumber;
    60.             floorTileController.myLastInstnacingFacilitatorForGround = this;
    61.             tillingAndOffsetArr[instanceNumber] = texOffsets;
    62.             hueShiftBrightnessSaturationArr[instanceNumber] = hueShiftBrightnessSaturation;
    63.  
    64.  
    65.             isDirty = true;
    66.             if (totalCount == maxIteration)
    67.             {
    68.                 ExpandArrays();
    69.             }
    70.         }
    71.  
    72.         public void UnregisterRendering(int indexNumber)
    73.         {
    74.             if (indexNumber == 0)
    75.             {
    76.                 return;
    77.             }
    78.  
    79.             rearangeCounter++;
    80.             matrixArr[indexNumber] = Matrix4x4.zero;
    81.             floorTileControllersArr[indexNumber].myGroundInstancingIndexNumber = 0;
    82.             floorTileControllersArr[indexNumber] = null;
    83.             isDirty = true;
    84.         }
    85.  
    86.         public void UpdateInstancingIfNeeded()
    87.         {
    88.             if (!isDirty)
    89.             {
    90.                 return;
    91.             }
    92.  
    93.             isDirty = false;
    94.             //Debug.Log("updating total count " + totalCount + "  " + arraySize);
    95.             GPUInstancerAPI.SetInstanceCount(prefabManager, prefab.prefabPrototype, totalCount);
    96.             GPUInstancerAPI.UpdateVisibilityBufferWithMatrix4x4Array(prefabManager, prefab.prefabPrototype, matrixArr);
    97.             GPUInstancerAPI.UpdateVariationFromArray(prefabManager, prefab.prefabPrototype,
    98.                 tillingAndOffsetBufferString, tillingAndOffsetArr);
    99.             GPUInstancerAPI.UpdateVariationFromArray(prefabManager, prefab.prefabPrototype,
    100.                 hueShiftBrightnessSaturationString, hueShiftBrightnessSaturationArr);
    101.         }
    So basically during update classes go and register or unregister themselves from rendering. Just one class doing so will trigger isDirtyFlag.

    Then in late update i run UpdateInstancingIfNeeded() and if it's dirty it will tell your API to update all the data. This all runs on main thread. Wrapper has also expand arrays, and sort arrays functionality, but these don't run i and arent the issue i verified with debug log... so let's say i have 100 ground tiles first they will occupy 1-101 first slots in array. Then when style changes slots 1-101 will be matrix.zero, they unregister first... then they'll register again with next new texture offset (so instead of carpet, they look like wooden floor now). it will be 102-202 slots. And then in late update i'll give your API new updated arrays. (once there occurred enough of unregistering the array is sorted and everything that is actually rendered is moved to the front of the array..)

    Obviously i tested rendering with unity renderers so instead of and nothing like that happens.

    And one interesting note, as you can see on the pictures fake wall shadows (just black quad with alpha gradient) appears one frame sooner the the ground tiles. It has basically identical flow. World tile first unregisters it's fake wall shadow, and then registers new instancing for fake wall shadow.. But it's transparent rendering que, could that be difference ? I'm clueless ¯\_(ツ)_/¯
     

    Attached Files:

    Last edited: Dec 18, 2023
  13. Chunikus

    Chunikus

    Joined:
    Sep 5, 2020
    Posts:
    28

    Try reimporting the package. Not just delete it and import again. Right click the folder and press reimport.
     
  14. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    If you can make a bug report following this guide, I can investigate the issue.
     
  15. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    Detail managers are designed to work with a single terrain independently. However, you can make editing multiple of them easier with some simple scripts. Here are couple of examples I shared previously:
    Regenerate Prototypes From Terrains
    Copy Detail Prototypes to Multiple Managers
     
  16. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    From the error messages, it looks like the prototype ScriptableObject references are not correct. One possible cause is editing the components or their object references manually instead of using the manager.
    To fix the references and to regenerate the prototypes, you can try removing the Crowd Manager from the scene and the "GPUI Crowd Prefab" components from the prefabs. Then add a new Crowd Manager to the scene and re-add the prefabs to it.

    There is not an editor API method to add new prefabs. But you can check these methods to implement one:
    See GPUICrowdManagerEditor.AddPickerObjectCrowd for defining crowd prototypes.
    See GPUICrowdAnimationBaker.SkinnedMeshBakeAnimations for baking animations.
     
  17. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    If you mean the Tree Creator instance colors from the terrain data, unfortunately GPU Instancer does not use this data. Trees are rendered with their default material values without instance based variations.
     
  18. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    There is not an editor setting to change the default prototype values. However you can edit multiple prototypes by Ctrl or Shift clicking.
    "Extra Buffer Size" should be set to max, if you want to avoid resizing buffers frequently at runtime since re-creating buffers can be slow. However if memory is a bigger concern, then you can keep it low and the buffers will be re-created when there is not enough memory allocated.
     
    MorpheusXI likes this.
  19. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    This might be an issue with the execution order. GPUI managers do most of their operations during LateUpdate, and your changes might be executed after the GPUI Manager (making some of the compute shader data invalid before it completed execution).
    Try moving the GPUI Prefab Manager script to the bottom of the Script Execution Order and see if it helps.
     
  20. Chunikus

    Chunikus

    Joined:
    Sep 5, 2020
    Posts:
    28
    Yep it seems it works. It's the first thing that i thought about, but then discarded it since, until i gave your API new arrays, it shouldn't even know that something changed and should render old visuals, but apparently it does rewrite something.

    This is a problem if not being able to control execution order more clearly. ^^. Glad that fix was so freaking easy :)
     
  21. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    322
    the same thing happened to me because of a type of tree. I deleted it and then the others appeared.
     
  22. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    322
    I want to request a refund for this product. After 2 months of use, it gives me no satisfaction. How should I do it ?
     
  23. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Please see section 2.9.3 of the EULA for information about Refund Policy. If you have a valid request as per EULA, you can contact Unity customer support for a refund.
     
  24. bh4786

    bh4786

    Joined:
    May 24, 2017
    Posts:
    23
    I see you can copy detail prototypes over to other managers but after I do that, how can I carry over changes made to a prototype on one manager to the others?
     
  25. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Prototypes are ScriptableObjects. When all the managers reference to the same ScriptableObject asset, changing one should change all.
     
  26. Mackerel_Sky

    Mackerel_Sky

    Joined:
    Jul 24, 2018
    Posts:
    33
    Hey guys, looking to invest in some tools to help me out with rendering a large amount of vegetation for a flight simulation game. Specifically, I'm working with levels that are approximately 25x25km, so I'm planning to create terrain tiles and convert them to meshes with LOD for better performance. I'm wondering about the prefab/tree placement implications this might have - I've read the documentation but not much is in there about placement of trees/details so I'm assuming GPUI uses the same placement tools as Unity terrain? Would anything bad happen if I turned the terrain to mesh?
     
  27. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    GPU Instancer does not have placement tools. There are three managers that are called Prefab, Tree and Detail Managers.
    Tree and Detail Managers works with the Unity terrain and loads the tree and detail instances from the TerrainData.
    Prefab Manager renders the prefab instances that are added to the scene. Alternatively, Prefab Manager can be used with no-GameObjects by supplying a Matrix4x4 array.
     
  28. IllogicalGames

    IllogicalGames

    Joined:
    Apr 16, 2013
    Posts:
    176
    Hi thank you for your reply. when you suggested to go for no-gameobject route, it seems like an interesting workaround. but i couldnt understand the matrix4x4 method. it seems like the no-gameobject solution only spawns the mesh in the matrix4x4 bound? im not understanding this because i only used to spawn an object using vector3 with xyz coordinate, how do i spawn the mesh in the vector3 position using the matrix4x4? im sorry if this question sounds silly but try to explain to me why cant we use the traditional vector3 position and if not, how do i use the matrix4x4 to spawn things. thank you
     
  29. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Matrix4x4 is a transformation matrix that contains both position, rotation and scale information. We use the Matrix4x4 array because it is the standard for sending transform data to GPU (e.g. see DrawMeshInstanced).
    A simple way to create a Matrix4x4 is to use the Matrix4x4.TRS(Vector3 position, Quaternion rotation, Vector3 scale) method. For example the transformation matrix of an object at coordinates 1,2,3 with 0 rotation and 1,1,1 scale can be created with:
    Code (CSharp):
    1. Matrix4x4.TRS(new Vector3(1, 2, 3), Quaternion.identity, Vector3.one);
     
  30. IllogicalGames

    IllogicalGames

    Joined:
    Apr 16, 2013
    Posts:
    176
    ahh thats clear things up. thank you
     
  31. Mackerel_Sky

    Mackerel_Sky

    Joined:
    Jul 24, 2018
    Posts:
    33
    Thanks for getting back to me - I'm guessing if I turn the terrain into meshes, then tree and detail managers would no longer work since the terrain data goes away. I will do some more research into this no gameobjects workflow, thanks!
     
  32. IllogicalGames

    IllogicalGames

    Joined:
    Apr 16, 2013
    Posts:
    176
    hi again GurhanH,
    recently i was messing around with unity DOTS/ECS and i was surprised with how fast it was.

    now i am wondering if GPU Instancer can work with DOTS or if it does, does the performance gain really worth it.
     
    Narkdagas likes this.
  33. ManaPotionStudios

    ManaPotionStudios

    Joined:
    Dec 26, 2016
    Posts:
    16
    It looks like using custom material in GPUI Detail Manager is bugged. If you disable and then enable GPUI Detail Manager you see an error. While still wokring correctly rendering is broken in build as custom material got destroyed during GPUI Detail Manager OnDisable and second code block fails to execute as material is null.

    It would be great if you could look into this issue

    UPDATE: This behaviour is due to GPUInstancerSettings.useOriginalMaterialWhenInstanced being true, what can be changed in editor. But I am not sure if this a way to go as it is not clear that this bool controlls custom material from the GPUI Detail Manager custom material inspector field and also if it's true material got destroyed with first script OnDisable.

    Code (CSharp):
    1. Destroying assets is not permitted to avoid data loss.
    2. If you really want to remove an asset use DestroyImmediate (theObject, true);
    3. UnityEngine.Object:DestroyImmediate (UnityEngine.Object)
    4. GPUInstancer.GPUInstancerUtility:DestroyObject (UnityEngine.Object) (at Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:3795)
    5. GPUInstancer.GPUInstancerManager:ClearInstancingData () (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:346)
    6. GPUInstancer.GPUInstancerDetailManager:ClearInstancingData () (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:77)
    7. GPUInstancer.GPUInstancerEditorSimulator:StopSimulation () (at Assets/GPUInstancer/Scripts/GPUInstancerEditorSimulator.cs:62)
    8. GPUInstancer.GPUInstancerDetailManagerEditor:OnDisable () (at Assets/GPUInstancer/Scripts/Editor/GPUInstancerDetailManagerEditor.cs:34)
    9.  
    Code (CSharp):
    1.  if (detailPrototype.useCustomMaterialForTextureDetail && detailPrototype.textureDetailCustomMaterial != null)
    2. {
    3.      instanceMaterial = GPUInstancerConstants.gpuiSettings.shaderBindings.GetInstancedMaterial(detailPrototype.textureDetailCustomMaterial);
    4.      instanceMaterial.name = "InstancedMaterial_" + detailPrototype.prototypeTexture.name + "_GPUITemp";
    5.  
    6.      // Note: Cross quad distance billboarding is disabled for custom materials since GPU Instancer handles billboarding in the GPUInstancer/Foliage shader.
    7.      runtimeData.AddLodAndRenderer(CreateCrossQuadsMeshForDetailGrass(1, 1, detailPrototype.prototypeTexture.name,
    8.              detailPrototype.quadCount), new List<Material> { instanceMaterial }, new MaterialPropertyBlock(), true, 0f,
    9.              null, false, detailLayer);
    10.  
    11.      runtimeDataList.Add(runtimeData);
    12.  
    13.      continue;
    14. }
     
    Last edited: Dec 23, 2023
    GurhanH likes this.
  34. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    GPU Instancer does not have an out of the box integration with DOTS. But you can use the no-GameObject API methods to render instances while using DOTS.
    If you are asking about how GPU Instancer rendering compares to DOTS Instancing, from my experience, using GPUI is worth it when you have a lot of instances (e.g. when DOTS instancing can not render with a single draw call because of memory limit) and when you will benefit from features like Hi-Z occlusion culling.
    GPUI is not a tool you should be using to render everything as a replacement to Unity's default. You use GPUI for specific objects for which Unity's instancing is not sufficient and when you start having performance issues because of rendering the same objects many times.

    Hi there,
    and thank you for reporting the issue.
    GPUInstancerUtility.cs line 1045 is wrong and should be removed. I will make the necessary change for the next update.
    So it should be like this:
    Code (CSharp):
    1.  if (detailPrototype.useCustomMaterialForTextureDetail && detailPrototype.textureDetailCustomMaterial != null)
    2. {
    3.      instanceMaterial = GPUInstancerConstants.gpuiSettings.shaderBindings.GetInstancedMaterial(detailPrototype.textureDetailCustomMaterial);
    4.      // Note: Cross quad distance billboarding is disabled for custom materials since GPU Instancer handles billboarding in the GPUInstancer/Foliage shader.
    5.      runtimeData.AddLodAndRenderer(CreateCrossQuadsMeshForDetailGrass(1, 1, detailPrototype.prototypeTexture.name,
    6.              detailPrototype.quadCount), new List<Material> { instanceMaterial }, new MaterialPropertyBlock(), true, 0f,
    7.              null, false, detailLayer);
    8.      runtimeDataList.Add(runtimeData);
    9.      continue;
    10. }
     
    ManaPotionStudios likes this.
  35. Foulcloud

    Foulcloud

    Joined:
    Mar 23, 2014
    Posts:
    19
    I am having issues getting Detail Scale working with terrain detail meshes. When GPUI is turned off, a see a nice variation in sizes. When I turn GPUI on, all sizes are the same. I have tried using a custom noise texture, adjusting the noise spread, different shaders, and nothing changes. I also tried a new project and used the built in sample scene with fern1 and still cannot get GPUI details to have varying sizes. Surely I am doing something wrong, or is this a limitation? Documentation goes over this and appears it should work similar to standard Unity terrain but uses it's own noise texture. Using Unity 2121.3, built in pipeline, deferred rendering project.
     
  36. Foulcloud

    Foulcloud

    Joined:
    Mar 23, 2014
    Posts:
    19
    My mistake. Was entering min max in wrong order. All good now, thanks.
     
  37. Foulcloud

    Foulcloud

    Joined:
    Mar 23, 2014
    Posts:
    19
    It seems when GPUI updates the Unity terrain details, the min/max detail scales are reversed. So when switching back to regular Unity terrain (for editing), the min values are the max values from GPUI. It can be corrected by manually editing every time but seems to be a bug.
     
  38. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    I just tested it, but I was not able to replicate the problem. Can you please email a bug report with step by step description of how to reproduce the issue so I can investigate?
     
  39. UsefulWeapon

    UsefulWeapon

    Joined:
    Oct 26, 2013
    Posts:
    67
    Hey @GurhanH i have a quick question. So in my scene i added prototypes of prefabs that are used the most on my scene, this objects have custom shader. After set up process i saw that it created a GPUI variant of my custom shader, but it does haven't applied it to this GPUI objects on scene(they still use regular version of shader, not GPUI). Should i apply new shader manually? Also one more thing, this GPUI shader variant of my custom shader is obligatory to use on GPUI prefabs or instancing wont work right?
    In asteroids demo asteroids meshes just use lit shader, i am confused a bit:confused:
    My custom shader alredy has GPU instancing checkbox by the way. Can you help me with what i should do please?
     
    Last edited: Jan 11, 2024
  40. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    Your shaders needs to have procedural instancing setup to be rendered with GPUI. When you add a prototype to a manager, the manager checks if the shaders have the GPUI setup. If not, it creates a new version of this shader, and adds a definition to GPUInstancerShaderBindings to keep track of it. GPUI does not modify your materials, but it will use the GPUI version of the shader while rendering. If you don't want to have multiple shaders, you can edit your materials to use the shader with the GPUI setup.
    Using the GPUI variant or the original shader on your materials is up to you. In either case GPUI will render using the shader with the GPUI setup. Enabling the instancing checkbox on the material will have no effect on how GPUI works, GPUI draw calls will always use indirect GPU instancing.
     
    UsefulWeapon likes this.
  41. UsefulWeapon

    UsefulWeapon

    Joined:
    Oct 26, 2013
    Posts:
    67
    Okay, thanks. So if i got it right i dont have to change materials to GPUI variant shader manually for the objects on scene, right?
     
  42. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Yes, GPUI will change the shader in the background for the instanced draw calls.
     
    UsefulWeapon likes this.
  43. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    529
    Hey there, I recently got some reports that GPUI CrossFade is not working with the Vegetation Engine, but at closer inspection it looks like it doesn't work with URP Lit shaders as well. Here is a quick recording showing the issue. I didn't go deeper to check how the cross fade value is passed, but I hope the video helps reproduce the issue.



    Edit: Did a quick test with the unity_Crossfade value, the value is not passed with GPUI
     
    Last edited: Jan 22, 2024
  44. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    and thank you for reporting the issue. I was able to reproduce it. I will release an update to GPU Instancer (v1.8.1) within this week, I will also include the fix for this issue.
     
    BOXOPHOBIC and Lars-Steenhoff like this.
  45. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi everyone,
    GPU Instancer v1.8.1 is now available for download on the Asset Store.

    Release Notes:
    Changed: Detail Manager performance improvements for distant terrains where no details are visible
    Changed: When prototype reference is lost the Auto. Add/Remove Instances feature will show a warning
    Changed: Minimum number for instance count warning is increased to 100
    Fixed: Incorrect destroy material call when using custom material for detail textures
    Fixed: MapMagic2 integration NullReferenceException (GPUI_MapMagic2_Integration package needs to be re-imported)
    Fixed: MapMagic integration undefined runInThreads error (GPUI_MapMagic_Integration package needs to be re-imported)
    Fixed: Alpha clipping not working with some Nature Manufacture URP shaders
    Fixed: Shader Graph "undeclared identifier unity_MatrixPreviousM" error when using built-in render pipeline
    Fixed: LOD Cross-fading not working on URP
     
  46. heartingNinja

    heartingNinja

    Joined:
    Mar 26, 2015
    Posts:
    36
    I have a problem that multiple objects are not being rendered correctly.

    For trees it is only showing the last LOD. I have the last one as an amplify impostor.

    With the details and prefabs it is showing but when I get close they disappear.

    The prefab one happens in editor and in build, but only after I move it. The detail and tree show in editor but not in build.

    This has happened three times after I removed the Tree Manager from a scene. I have tried to clear and regenerate the shader, reimporting the package, upgrading to 1.8.1, removing GPU instancer, adding the shader to always include, adding and deleting the Managers. Nothing has worked.

    I am using The Vegetation Engine with Baldinoboy Tropical Forest Pack in Unity 2022.3.9. I have tried to reproduce but I can not.

    I got the trees to work again if I do not use The Vegetation Engine. But the problem has always started when I remove the Tree Manager so I am posting here.

    Edit: For some reason when I delete the Tree Manager sometimes the texcoord 0 and 3 become enabled again. Just disabling them got The Vegetation Engine to work correct. That seemed to fix my problems.
     
    Last edited: Jan 30, 2024
  47. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Hi there,
    If you can contact the support email with a sample project by following this guide, I can investigate the issue.
     
  48. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    322
    GPUI v1.8.1
    Why is the number of instances zero?

    it worked with the previous version
     
  49. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    558
    Please read the documentation about Registered Instances section.
    If it is not behaving as described, please email a bug report with an example project by following this guide.
     
  50. andylewisart

    andylewisart

    Joined:
    Nov 4, 2013
    Posts:
    19
    Hello,
    Utilizing the No GameObject Workflow, is it possible to easily and cheaply swap prefabs based on some kind of distance threshold, bounds, or collider? I'm needing to swap out instances for other instanced prefabs based on proximity to an object. I'm going to have over a million instances in the prefab manager in some cases. Thanks for any help and advice.
    Cheers,
    Andy
     
    Last edited: Feb 2, 2024