Search Unity

[RELEASED] GPU Instancer

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

  1. Lee1384

    Lee1384

    Joined:
    Jun 8, 2014
    Posts:
    11
    Hello.

    I want to make the grass grow back after a certain period of time after mowing it.

    The example of mowing grass worked great, but I don't know how to grow it back.

    Could you give me a hint on how I can make it? The grass was planted with prefab, not Unity Terrain.

    Thanks!
     
  2. Rail9

    Rail9

    Joined:
    Feb 21, 2020
    Posts:
    28
    Hello there.

    I have set an object that has LOD in GPU Instancer prefab Manager but it is not working.
    If I set the sphere and cubes to LOD as shown in the video, it works with GPU Instancer Prefab Manager, but not with other 3D models, etc.



    I don't think there is a problem with the LOD object because it works unless it is set in the GPU Instancer prefab Manager.

    I checked the videos and documentation to see if there is any setting I need to do, but it doesn't look like I need to do anything in particular.

    Are there any steps required other than setting the object to GPU Instancer prefab Manager?
    I am using Animate cross fading for the LOD of the object, so I checked LOD Cross Fade in the GPU Instancer prefab Manager and also checked Animate cross fading.

    Materials are Standerd shaders and Vegetation Engine with Enable GPU Instance checked.

    Thank you.
     
    Last edited: Feb 23, 2023
  3. Doomchecker

    Doomchecker

    Joined:
    Apr 5, 2021
    Posts:
    109
    Hello.

    I can't find a method that removes the instances from the scene after I spawned them.

    1)
    For the GameObject workflow I would simply destroy the underlying gameobject that is in the scene, right?

    2)
    For the No GameObject workflow, I don't know how do remove the instances from the scene without completely removing the prefab from the manager.

    Thanks for helping out!
     
  4. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    The Instance Remover can only be used for removing instances and it can not bring them back. If you need to add/remove instances, you can use the AddPrefabInstance/RemovePrefabInstance API methods instead.

    Hi there,
    Please make sure that the LOD Group component is at the parent GameObject on the prefab that is defined as prototype. GPUI will ignore LOD Groups on the child GameObjects.
    Also try disabling cross-fading and see if it works. Custom shaders might be incompatible with GPUIs cross-fading solution which can cause issues.
    If this does not help, please email us a bug report and specify what you mean by "not working" (are the objects not rendering at all, or the LODs not transitioning correctly?) and if possible include a sample project following this guide.

    Hi there,
    There are various methods that can be used for removing. Please see this F.A.Q. for different options when using GameObjects.
    For No-GameObjects, if you want to remove all instances and release the memory allocations, you can use the ReleaseInstanceBuffers API method. If you want to temporarily disable rendering, you can use the SetInstanceCount API method and set the value zero. If you want to remove instances on specific indexes on the array, you can set the values of those indexes to Matrix4x4.zero using UpdateVisibilityBuffer API.
     
  5. AuKtagon

    AuKtagon

    Joined:
    Aug 3, 2017
    Posts:
    7
    Hi there, I am fairly new to using GPU Instancer and loved it when first starting off. I am mostly using it for runtime instantiated prefabs. I opened the project one day and it just always says "The variable prefabPrototype of GPUInstancerPrefab doesn't exist anymore". I use the prefabPrototype variable to hold the 'GPUI Prefab Manager' that is in the scene. This was all working before but now whenever I run the scene it won't work and I get that error. No objects are working on the GPU but they are still instantiated on the CPU. Any help would be amazing!
     
  6. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Hi, is raytracing supported? I've seen in the past posts that it is not, and was wondering if it is now supported.
     
  7. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    Can you please email us a support request with detailed information following this guide? Please also make sure to include the stack trace of the error and a code sample of your implementation in your email so we can investigate.

    Hi there,
    No, raytracing is not supported.
     
  8. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    325
    Just wanted to post and say thankyou for making this amazing system!

    Here's a video of it being put to good use in my procedural world generator with a custom quad tree terrain system that generates a 32x32 Kilometre world!

    Also features Enviro 3 and Crest Ocean.

     
    Zaddo, GurhanH and vertexx like this.
  9. iendsl

    iendsl

    Joined:
    Oct 17, 2013
    Posts:
    3
    I'm having an issue with addressables and runtime instances... It seems like an issue with the ScriptableObj being used as a key for adding prefab instances but the addressable Scriptable Object isn't matching the one being used as a key with the registered prefabs. Has anyone else experienced this? Is there a built in fix or workaround otherwise?
     
  10. Kasperrr

    Kasperrr

    Joined:
    Feb 23, 2019
    Posts:
    13
  11. Daezalus

    Daezalus

    Joined:
    May 16, 2020
    Posts:
    9
    New
    Hi there,

    I have a building with destructible walls in fragments (1000 - 2000 fragments total per wall). Would it be possible to GPUI the fragments of the wall, and have them -
    a) using GPUI, be multiple walls - with a quantity of fragments similar the asteroid demo - i.e, Hundreds of destructible walls with thousands of fragments
    b) utlilise gravity when 'activated' and can be destroyed? Perhaps with custom culling if needed

    Thanks in advance

    2021.3.18f1 Personal_ _DX11_ 28_02_2023 22_58_33.png
     
  12. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    I do not remember seeing an issue like this, so I can not say for sure. If you can email us a support request following this guide and include a detailed description of your setup, we can investigate.

    Hi there,
    No, GPUI does not use BatchRenderGroup API.

    Hi there,
    GPU instancing works by rendering the same mesh and material combination many times. From the image, it looks like you have different meshes for the fragments, so they will not be suitable for GPU instancing.
     
  13. backwheelbates

    backwheelbates

    Joined:
    Jan 14, 2014
    Posts:
    232
    Hi @GurhanH, Im having an issue where auto generated billboards dont seem to be showing up. Are there any things I should investigate? When I click on Show Billboard, I can see it there correctly, just cant see it in the editor or in play mode. Thanks for any ideas!

    upload_2023-3-3_15-35-50.png
     
  14. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    Possibly the instances are culled before the billboard starts. You have a Max Distance limit set to 390.
    Since you are using the "Replace LOD Culled With Billboard" option, the Culled percentage on the LOD Group might be farther.
    Please also make sure that you have the correct Object Size by clicking on the Recalculate Bounds button on the LOD Group component on your tree prefab. If you have a different Object Size value than the real one, the LOD percentages will behave differently in GPUI.

    If this does not help, please email us a bug report with a sample project following this guide and we can investigate.
     
    backwheelbates likes this.
  15. unity_4EA6FC13EF4E95E76A1B

    unity_4EA6FC13EF4E95E76A1B

    Joined:
    Jan 18, 2023
    Posts:
    3
    How do I enable Transparency for the instantiated particles?
     
    Last edited: Mar 10, 2023
  16. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    224
    Hi, for terrain details I recently wrote my own system using Burst to setup instance positions/aggregate detail cell data, etc, and just using the prefab manager rather then using your compute shader stuff in the detail manager (mainly because I wanted tighter control on how everything works). However, I have noticed that I see weird results with animated LODs as I cross cell boundaries - meaning I will see a flash of a set of instances that will be outside of culling distance and they will quickly LOD fade out. This only happens for instances with animated LODs. I suspect this is because my matrix indices are not stable. I do not only upload changed matrices (meaning just unloaded/loaded cells) but rather I remerge all visible cells and then upload the total visible set of matrices. Since I do that, matrix indices will be unstable, so an instance in the process of fading in/out might have its matrix index moved during a cell transition. I assume that for animated LODs, in GPUI you have to store state somewhere for time, unlike non-animated which can be derived without persistent state.

    Does this sound accurate? Will I need to support stable matrix indices in order to make animated LODs work in this way?

    Below is a pic where you can see two examples of the artifact. You can see the normal GPUI culling distance by the vegetation line, and then those two blobs past that culling distance show up for a few hundred ms and fade out. I am going backwards when I took this. I'm pretty certain this is not a bug in my implementation (and this doesn't happen for non-LOD and non-animated LODs).

    upload_2023-3-11_11-5-2.png

    Edit: Note, I implemented a configuration using stable matrices, and it does seem to solve the issue.
     
    Last edited: Mar 13, 2023
  17. DirtyHippy

    DirtyHippy

    Joined:
    Jul 17, 2012
    Posts:
    224
    Also there is a minor bug in GPUInstancerManagerEditor.cs:368 (DrawGPUInstancerPrototypesBox) (this is in 1.7.5 - it might be fixed in 1.7.6).

    Code (CSharp):
    1. int prototypeRowCount = Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - 30f) / (_manager.isPrototypeTextMode ? PROTOTYPE_TEXT_RECT_SIZE_X : PROTOTYPE_RECT_SIZE));
    will evaluate to 0 in some cases when the inspector pane width is very small, causing a divide by zero below that which will throw a bunch of exceptions.

    Adding a quick hack after this line will fix it.

    Code (CSharp):
    1.                 if (prototypeRowCount == 0)
    2.                 {
    3.                     EditorGUILayout.EndVertical();
    4.                     return;
    5.                 }
     
  18. kaliyo

    kaliyo

    Joined:
    Dec 8, 2015
    Posts:
    10
    Sadly doesn't seem to be compatible with 2022.2
    The scene view turns grey as soon as I add the detail manager and Unity crashes after 10~ seconds.
     
  19. windspiek

    windspiek

    Joined:
    Jun 17, 2018
    Posts:
    5
    Hey @GurhanH I am using GPUInstancer Trees and have the issue that the billboards generated, will have transparency in the part of the mesh that uses (opaque) alpha clipping.

    upload_2023-3-13_18-46-31.png

    This is using default settings with a tree without LoDs and two materials with the standard "FoliageURP_GPUI_SG" shader.

    Would love some support with this since, because editing the "BillboardURP_GPUI" shader to fix the issue has had no effect and presumably another shader is used for the billboards?
     
  20. mezzanine510

    mezzanine510

    Joined:
    Mar 7, 2018
    Posts:
    5
    I crash on 2022.2 as well. Any updates on this @GurhanH ?
     
  21. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    There is not an extra step to enabling transparency. If the transparency setting on the material is not working, there might be a shader issue. If you can email us a detailed description of the problem following this guide we can investigate.

    Hi there,
    GPUI stores a state for animating cross-fading and it is index based (since there are no GameObjects, index is the only reference). We will look into adding an API method to reset cross-fading states in a future update. For now you can set the "isInitial" field in the manager to true which should reset the states for the cross-fading. However "isInitial" is a protected field so you either need to change it to public or add a new method to the manager. (See GPUInstancerManager.cs line 93)

    Thanks for the feedback. We will look into it for the next update.

    Hi there,
    Please email us a bug report with sample project following this guide so we can investigate.

    Hi there
    Please make sure that you are not using the "Coverage Mode" for Detail Scatter Mode terrain setting. And if the issue continues, please email us a bug report with detailed description of how to reproduce the problem or a sample project following this guide so we can investigate.
     
  22. backwheelbates

    backwheelbates

    Joined:
    Jan 14, 2014
    Posts:
    232
    Thank you, Ill give it a try!
     
  23. MarkE52x

    MarkE52x

    Joined:
    Sep 7, 2022
    Posts:
    3
    Hi,
    I'm currently rendering a sports crowd. I'm looking at basing it similarly on 'No Game Objects With Jobs Demo Scene' in GPUI animation package. Before I had built the crowd without the jobs system based off 'No Game Objects Demo Scene' (So not using jobs/burst). Using jobs and burst now has improved performance when switching animations but when I call animation changes now there doesn't seem to be an option to give transition time.

    Is anyone aware of a solution to this? When changing animation I can tell it doesn't transition immediately from one animation to another but it does instead smoothly transition though quite quickly. Is there a way i can slow this transition down? maybe a shader setting? Even if I have to slow it down for all animation changes that would be alright.

    Hope that makes sense to someone :)
     
  24. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Hello, I'm trying to follow the tutorial at https://wiki.gurbu.com/index.php?ti...tances_to_have_Material_Variations_on_them.3F but instead of supplying a Vector4 representing color to the buffer, I'd like to supply a Texture2D to it. This would allow me to have entire variations of textures at runtime to choose from. I'm not sure if this is even allowed though, reading through https://wiki.gurbu.com/index.php?ti...ntation#DefinePrototypeVariationBuffer.3CT.3E . May I just ask if I could pass in entire Textures to this buffer, and also the limit of how many textures or bytes can be supplied?

    I should also mention I'm using the no-gameobject flow. Also, the current plan is to have a Texture2D representing the texture, and set that using the API through the StructuredBuffer, though I don't know how to do this through the no-gameobject flow
     
    Last edited: Mar 24, 2023
  25. AngelGalaxyOfficial

    AngelGalaxyOfficial

    Joined:
    Apr 10, 2021
    Posts:
    16
    Hi there,

    As @Rail9 mentioned in his above post, there does seem to be a current issue with GPU Instancer and The Vegetation Engine. This issue is with LOD Cross-fading.

    I currently am using a tree prefab that has been converted to The Vegetation Engine 8.4.1 shaders. I have set the Boxophobic -> Shader Manager shaders to use GPU Instancer for the shader renderer.

    I am on GPU Instancer v1.7.6 and when adding my trees to GPUI Prefab Manager and enabling LOD Crossfade, the LODs will not crossfade whether it is enabled or not. Furthermore, I can confirm the LOD Group is on the prefab parent and has animated cross-fade enabled and working fine when GPU Instancer is not enabled.

    Steps to reproduce:
    0. Install The Vegetation Engine, GPU Instancer, any tree/vegetation prefabs, and enable 'GPU Instancer' shader support in TVE by going to Boxophobic -> Shader Manager
    1. Get a tree prefab (nature manufacture in my case, it has 4 LODs)
    2. Add tree prefab to GPUI (I used scene prefab importer)
    3. Make sure LOD Cross-fade is enabled in GPUI.

    You should see the issue with the tree instantly going between LODs. Try changing settings, nothing will change. (Bonus Note: It works fine in editor, it's only in play mode.)
     
  26. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    I passed an array of integers from Unity C# into an HLSL shader's StructuredBuffer, but all of a sudden that array's contents seem to be persisting between Play sessions. No matter how much I randomize that array of int, the running game proves that the same sequence of integers is still being passed into the shader

    Basically, no matter how many times I restart Play, the same pattern of Beige and Orange (pulling in data from the array of integers) happen. I've confirmed that the RNG is working properly, but passing in new sequences of integers still doesn't change the StructuredBuffer. It's like the sequence of integers I provided it when I first got it to work is "stuck" in the StructuredBuffer

    I'm using the following modified shader which randomizes Textures using the material variation workflow

    Code (CSharp):
    1. Shader "Collapse/Toon"
    2. {
    3.     Properties
    4.     {
    5.         // Material Variations
    6.         _BaseMapArray       ("VariationTextures", 2DArray)                 = "" {}
    7.  
    8.         _BaseMap            ("Texture", 2D)                       = "white" {}
    9.        // _BaseColor          ("Color", Color)                      = (0.5,0.5,0.5,1)
    10.        
    11.         [Space]
    12.         _ShadowStep         ("ShadowStep", Range(0, 1))           = 0.5
    13.         _ShadowStepSmooth   ("ShadowStepSmooth", Range(0, 1))     = 0.04
    14.        
    15.         [Space]
    16.         _SpecularStep       ("SpecularStep", Range(0, 1))         = 0.6
    17.         _SpecularStepSmooth ("SpecularStepSmooth", Range(0, 1))   = 0.05
    18.         [HDR]_SpecularColor ("SpecularColor", Color)              = (1,1,1,1)
    19.        
    20.         [Space]
    21.         _RimStep            ("RimStep", Range(0, 1))              = 0.65
    22.         _RimStepSmooth      ("RimStepSmooth",Range(0,1))          = 0.4
    23.         _RimColor           ("RimColor", Color)                   = (1,1,1,1)
    24.        
    25.         [Space]  
    26.         _OutlineWidth      ("OutlineWidth", Range(0.0, 1.0))      = 0.15
    27.         _OutlineColor      ("OutlineColor", Color)                = (0.0, 0.0, 0.0, 1)
    28.  
    29.     }
    30.     SubShader
    31.     {
    32.         Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
    33.        
    34.         Pass
    35.         {
    36.             Name "UniversalForward"
    37.             Tags
    38.             {
    39.                 "LightMode" = "UniversalForward"
    40.             }
    41.             HLSLPROGRAM
    42.  
    43.  
    44.             // GPU Instancer
    45.             #define GPUI_CUSTOM_INPUT 1 // needs to be declared so GPUI does not override your defines
    46.             #define GPUI_STRUCT_NAME Attributes // the name of your input struct
    47.             #define GPUI_BONE_INDEX texcoord2 // TEXCOORD2
    48.             #define GPUI_BONE_WEIGHT texcoord3 // TEXCOORD3
    49.             #define GPUI_VERTEX positionOS // VERTEX
    50.             #define GPUI_NORMAL normalOS // NORMAL
    51.             #define GPUI_TANGENT tangentOS // TANGENT
    52.  
    53.             // GPU Instancer
    54.             //#include "UnityCG.cginc"
    55.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    56.            
    57.             struct Attributes
    58.             {    
    59.                 float4 positionOS   : POSITION;
    60.                 float3 normalOS     : NORMAL;
    61.                 float4 tangentOS    : TANGENT;
    62.                 float2 uv           : TEXCOORD0;
    63.  
    64.                 // GPU Instancer
    65.                 float4 texcoord2 : TEXCOORD2;
    66.                 float4 texcoord3 : TEXCOORD3;
    67.                 //
    68.  
    69.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    70.             };
    71.            
    72.             // Material Variations
    73.             #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED      
    74.                 StructuredBuffer<int> textureIndexBuffer;
    75.             #endif
    76.            
    77.             // Material Variations
    78.             #pragma target 3.5
    79.             #include "HLSLSupport.cginc"
    80.             UNITY_DECLARE_TEX2DARRAY(_BaseMapArray);
    81.             SAMPLER(sampler_BaseMap);
    82.  
    83.             #include "Assets/GPUInstancer-CrowdAnimations/Shaders/Include/GPUICrowdInclude.cginc"
    84.             #pragma multi_compile _ GPUI_CA_BINDPOSEOFFSET
    85.             #pragma shader_feature_vertex GPUI_CA_TEXTURE
    86.             #pragma multi_compile_instancing
    87.             #pragma instancing_options procedural:setupGPUI
    88.  
    89.             // Required to compile gles 2.0 with standard srp library
    90.             #pragma prefer_hlslcc gles
    91.             #pragma exclude_renderers d3d11_9x
    92.  
    93.             #pragma vertex vert
    94.             #pragma fragment frag
    95.             // #pragma shader_feature _ALPHATEST_ON
    96.             // #pragma shader_feature _ALPHAPREMULTIPLY_ON
    97.             #pragma multi_compile _ _SHADOWS_SOFT
    98.             #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
    99.             #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
    100.             // -------------------------------------
    101.             // Unity defined keywords
    102.             #pragma multi_compile_fog
    103.             //#pragma multi_compile_instancing
    104.            
    105.             //#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    106.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
    107.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
    108.  
    109.  
    110.             CBUFFER_START(UnityPerMaterial)
    111.                 //float4 _BaseColor;
    112.                 float _ShadowStep;
    113.                 float _ShadowStepSmooth;
    114.                 float _SpecularStep;
    115.                 float _SpecularStepSmooth;
    116.                 float4 _SpecularColor;
    117.                 float _RimStepSmooth;
    118.                 float _RimStep;
    119.                 float4 _RimColor;
    120.             CBUFFER_END
    121.  
    122.  
    123.             struct Varyings
    124.             {
    125.                 float2 uv            : TEXCOORD0;
    126.                 float4 normalWS      : TEXCOORD1;    // xyz: normal, w: viewDir.x
    127.                 float4 tangentWS     : TEXCOORD2;    // xyz: tangent, w: viewDir.y
    128.                 float4 bitangentWS   : TEXCOORD3;    // xyz: bitangent, w: viewDir.z
    129.                 float3 viewDirWS     : TEXCOORD4;
    130.                 float4 shadowCoord     : TEXCOORD5;    // shadow receive
    131.                 float4 fogCoord         : TEXCOORD6;  
    132.                 float3 positionWS     : TEXCOORD7;  
    133.                 float4 positionCS    : SV_POSITION;
    134.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    135.             };
    136.  
    137.             Varyings vert(Attributes input)
    138.             {
    139.                 Varyings output = (Varyings)0;
    140.                    
    141.                 UNITY_SETUP_INSTANCE_ID(input);
    142.                 // GPU Instancer
    143.                 GPUI_CROWD_VERTEX(input);
    144.                 //
    145.  
    146.                 UNITY_TRANSFER_INSTANCE_ID(input, output);
    147.  
    148.                 VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
    149.                 VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
    150.                 float3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
    151.                 float3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
    152.  
    153.                 output.positionCS = vertexInput.positionCS;
    154.                 output.positionWS = vertexInput.positionWS;
    155.                 output.uv = input.uv;
    156.                 output.normalWS = float4(normalInput.normalWS, viewDirWS.x);
    157.                 output.tangentWS = float4(normalInput.tangentWS, viewDirWS.y);
    158.                 output.bitangentWS = float4(normalInput.bitangentWS, viewDirWS.z);
    159.                 output.viewDirWS = viewDirWS;
    160.                 output.fogCoord = ComputeFogFactor(output.positionCS.z);
    161.                 return output;
    162.             }
    163.            
    164.             half remap(half x, half t1, half t2, half s1, half s2)
    165.             {
    166.                 return (x - t1) / (t2 - t1) * (s2 - s1) + s1;
    167.             }
    168.            
    169.             float4 frag(Varyings input) : SV_Target
    170.             {
    171.                 UNITY_SETUP_INSTANCE_ID(input);
    172.  
    173.                 float2 uv = input.uv;
    174.                 float3 N = normalize(input.normalWS.xyz);
    175.                 float3 T = normalize(input.tangentWS.xyz);
    176.                 float3 B = normalize(input.bitangentWS.xyz);
    177.                 float3 V = normalize(input.viewDirWS.xyz);
    178.                 float3 L = normalize(_MainLightPosition.xyz);
    179.                 float3 H = normalize(V+L);
    180.                
    181.                 float NV = dot(N,V);
    182.                 float NH = dot(N,H);
    183.                 float NL = dot(N,L);
    184.                
    185.                 NL = NL * 0.5 + 0.5;
    186.                
    187.                 // Material Variations
    188.                 float4 baseMap = float4(0,0,0,0);
    189.                 #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED      
    190.                     baseMap = UNITY_SAMPLE_TEX2DARRAY(_BaseMapArray, float3(uv.xy, textureIndexBuffer[gpui_InstanceID]));
    191.                 #endif
    192.  
    193.                 //float4 baseMap = SAMPLE_TEXTURE2D(variationBaseMap, sampler_BaseMap, uv);
    194.  
    195.                 // return NH;
    196.                float specularNH = smoothstep((1-_SpecularStep * 0.05)  - _SpecularStepSmooth * 0.05, (1-_SpecularStep* 0.05)  + _SpecularStepSmooth * 0.05, NH) ;
    197.                float shadowNL = smoothstep(_ShadowStep - _ShadowStepSmooth, _ShadowStep + _ShadowStepSmooth, NL);
    198.  
    199.                 input.shadowCoord = TransformWorldToShadowCoord(input.positionWS);
    200.                
    201.                 //shadow
    202.                 float shadow = MainLightRealtimeShadow(input.shadowCoord);
    203.                
    204.                 //rim
    205.                 float rim = smoothstep((1-_RimStep) - _RimStepSmooth * 0.5, (1-_RimStep) + _RimStepSmooth * 0.5, 0.5 - NV);
    206.                
    207.                 //diffuse
    208.                 //float3 diffuse = _MainLightColor.rgb * baseMap * _BaseColor * shadowNL * shadow;
    209.                 float3 diffuse = _MainLightColor.rgb * baseMap * shadowNL * shadow;
    210.                
    211.                 //specular
    212.                 float3 specular = _SpecularColor * shadow * shadowNL *  specularNH;
    213.                
    214.                 //ambient
    215.                 //float3 ambient =  rim * _RimColor + SampleSH(N) * _BaseColor * baseMap;
    216.                 float3 ambient =  rim * _RimColor + SampleSH(N) * baseMap;
    217.            
    218.                 float3 finalColor = diffuse + ambient + specular;
    219.                 finalColor = MixFog(finalColor, input.fogCoord);
    220.                 return float4(finalColor , 1.0);
    221.             }
    222.             ENDHLSL
    223.         }
    224.        
    225.         //Outline
    226.         Pass
    227.         {
    228.             Name "Outline"
    229.             Cull Front
    230.             Tags
    231.             {
    232.                 "LightMode" = "SRPDefaultUnlit"
    233.             }
    234.             HLSLPROGRAM
    235.            
    236.             // GPU Instancer
    237.             #define GPUI_CUSTOM_INPUT 1 // needs to be declared so GPUI does not override your defines
    238.             #define GPUI_STRUCT_NAME appdata // the name of your input struct
    239.             #define GPUI_BONE_INDEX texcoord2 // TEXCOORD2
    240.             #define GPUI_BONE_WEIGHT texcoord3 // TEXCOORD3
    241.             #define GPUI_VERTEX vertex // VERTEX
    242.             #define GPUI_NORMAL normal // NORMAL
    243.             #define GPUI_TANGENT tangent // TANGENT
    244.  
    245.             // GPU Instancer
    246.             //#include "UnityCG.cginc"
    247.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    248.  
    249.             struct appdata
    250.             {
    251.                 float4 vertex : POSITION;
    252.                 float3 normal : NORMAL;
    253.                 float4 tangent : TANGENT;
    254.  
    255.                 // GPU Instancer
    256.                 float4 texcoord2 : TEXCOORD2;
    257.                 float4 texcoord3 : TEXCOORD3;
    258.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    259.                 //
    260.             };
    261.  
    262.             #include "Assets/GPUInstancer-CrowdAnimations/Shaders/Include/GPUICrowdInclude.cginc"
    263.             #pragma multi_compile _ GPUI_CA_BINDPOSEOFFSET
    264.             #pragma shader_feature_vertex GPUI_CA_TEXTURE
    265.             #pragma multi_compile_instancing
    266.             #pragma instancing_options procedural:setupGPUI
    267.  
    268.             #pragma vertex vert
    269.             #pragma fragment frag
    270.             #pragma multi_compile_fog
    271.             //#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    272.            
    273.            
    274.  
    275.             struct v2f
    276.             {
    277.                 float4 pos      : SV_POSITION;
    278.                 float4 fogCoord    : TEXCOORD0;  
    279.             };
    280.            
    281.             float _OutlineWidth;
    282.             float4 _OutlineColor;
    283.            
    284.             v2f vert(appdata v)
    285.             {
    286.                 UNITY_SETUP_INSTANCE_ID(v);
    287.  
    288.                 // GPU Instancer
    289.                 GPUI_CROWD_VERTEX(v);
    290.                 //
    291.  
    292.                 v2f o;
    293.                 VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
    294.                 o.pos = TransformObjectToHClip(float4(v.vertex.xyz + v.normal * _OutlineWidth * 0.1 ,1));
    295.                 o.fogCoord = ComputeFogFactor(vertexInput.positionCS.z);
    296.  
    297.                 return o;
    298.             }
    299.  
    300.             float4 frag(v2f i) : SV_Target
    301.             {
    302.                 float3 finalColor = MixFog(_OutlineColor, i.fogCoord);
    303.                 return float4(finalColor,1.0);
    304.             }
    305.            
    306.             ENDHLSL
    307.         }
    308.         UsePass "Universal Render Pipeline/Lit/ShadowCaster"
    309.     }
    310. }
    311.  
     
  27. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    While using No-GOs by modifying the NativeArrays, you control the animations and weights directly. So you need to implement transitions manually. Transition can be implemented by changing the weight of the first animation from 1 to 0, and the second animation from 0 to 1 over time.

    Hi there,
    Rail9's LOD issue was related to the Object Size value on the LOD Group. The issue was resolved when Recalculate Bounds button was clicked on the LOD Group component.
    If your issue is unrelated, please email a sample project following this guide, and we can investigate.

    Hi there,
    The issue might be related to how you set the data to the buffer on the C# side. If you can email a sample project following this guide, and we can investigate.
     
  28. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Thank you. Turns out the issue was my supplying the wrong StructuredBuffer name from the C# code.
     
  29. adsilcott

    adsilcott

    Joined:
    Aug 30, 2014
    Posts:
    55
    Hi, sorry if this is mentioned somewhere, I haven't seen it. I'd like to be able to pass a list of Vector3s that indicate where to spawn a prefab, and have them spawn only at runtime rather than placing them in the editor. Is this possible?
     
  30. animal531

    animal531

    Joined:
    Aug 26, 2014
    Posts:
    25
    Hi @GurhanH ,

    I have a composite GO that I want to use GPUI for. So imagine that it has a body and some procedurally animated feet, I then add it to GPUI and I set all the Enable Runtime to Auto Update flags.
    I'm still using normal Unity Instantiate and then I call AddPrefabInstance to add it to the manager, but of course then the procedural animations stop working, since the renderers been moved into GPUI and the previous Transforms/Renderers are all disabled.

    I have the GPUInstancerPrefab on the main GO, but is there a way for me to gain access to the GPUI transform data for the feet? If I have to I can take the GO's apart and perform GPUI instancing on the parts and then build the objects up again, but I was hoping there's an easier way to do it.

    Thanks,
     
  31. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    Please see the No-GameObject Workflow where you can use an array of Matrix4x4 to render instances of a prototype. Also see the Matrix4x4.TRS method which you can use to convert position/rotation/scale values to Matrix4x4.

    Hi there,
    Procedural animations are not supported and there is not a built-in way to modify the transforms for specific bones. Crowd Animations calculates the transform data for rendering in the GPU via Compute Shaders using the baked textures. You would need to inject another Compute Shader before the draw calls to override bone transforms which would not be easy to implement.
     
  32. adsilcott

    adsilcott

    Joined:
    Aug 30, 2014
    Posts:
    55
    Worked flawlessly -- fantastic! thank you so much!
     
  33. animal531

    animal531

    Joined:
    Aug 26, 2014
    Posts:
    25
    ---
    Hi, these aren't humanoid characters with bones, they're just mesh pieces that I move procedurally using normal GPU Instancer, not Crowd Animator.

    So my question is whether I can with the single Unity Instantiate call get to the Matrix4x4 or whatever data for both the parent and whatever children there used to be in the Prefab, which is now being drawn by GPUI.
     
  34. LumaPxxx

    LumaPxxx

    Joined:
    Oct 3, 2010
    Posts:
    339
    Hi,will GPUI support "Coverage Mode" for detail rendering in the near future?
     
  35. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    GPUI uses only one matrix for each instance and treats the children as static relative to the parent GameObject. If you need to move the child renderers, you need to define the child GameObjects also as prototypes (see Nested Prefabs) so that they can have their own matrices/buffers. Then you can also use the Auto Update flags for the feet prototypes.

    Hi there, no, it is not in our plans currently.
     
  36. animal531

    animal531

    Joined:
    Aug 26, 2014
    Posts:
    25
    Thanks, that worked great!
     
  37. Dturk34

    Dturk34

    Joined:
    Nov 13, 2014
    Posts:
    24
    Hi @GurhanH,

    I'm using Gaia in my (HDRP)project and wanted to use GPU Instancer with it. As far as I can see, you mentioned GPU Instancer supports the Gaia, but I can't find updated documentation or tutorial about it. I saw a few screenshots related to it, but it's not updated; I can't see GPU Instancer in Gaia's extensions tab. I hope you can help me, thx.
     
    Last edited: Apr 11, 2023
  38. safasoylu000

    safasoylu000

    Joined:
    Oct 31, 2020
    Posts:
    2
    hello. i want to get help. the version I'm using is the gpu instancer on the right side. The editor optimized my project very well, but I lost up to 20 fps because the batches, setpass calls and shadowcasters values were too high, how can I solve this
    upload_2023-4-11_14-59-11.png
     
  39. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    Gaia extension was deprecated a long time ago. You can use the GPUI Managers as described on the Getting Started documentation regardless of which tool you use to set up your scene. However if you use additional tools/features that affect rendering at runtime (e.g. other instancing/culling solutions), they might not work out of the box with GPUI.

    Hi there,
    This does not look right. Please make sure you are using GPU Instancer as intended by reading the Best Practices documentation. Also make sure there is no error logs on the console and there is not another 3rd party tool that is involved in rendering which might be incompatible with GPUI.
    If the issue continues, please email us a sample project following this guide and we can investigate.
     
  40. MarkE52x

    MarkE52x

    Joined:
    Sep 7, 2022
    Posts:
    3
    Hi, looking at "NoGameObjectsWithJobsDemoScene" scene in GPUInstance-CrowdAnimations package v1.1.4. In the crowd manager if I provide it with a prefab with transparent material the material is changed to opaque. Is this a limitation of NoGameObjects workflow or a bug? Material is urp lit shader. Unity version is 2021.3.5f1. Would a appreciate if there is any known solution :).
     
  41. Hugo99999999

    Hugo99999999

    Joined:
    Jun 8, 2022
    Posts:
    21
    Hello, I have a question. I'm working on a VR driving simulation project. In my scene, the vehicle has a main camera and two secondary cameras, and the secondary cameras are used for the reflectors on both sides as the Rendertexture. Do I need to add GPU instances to my cameras on both sides
     
  42. safasoylu000

    safasoylu000

    Joined:
    Oct 31, 2020
    Posts:
    2
    upload_2023-4-16_11-12-16.png
    Hello. Example with the information I got from the frame debug section in your asteroid demo scene, I added 3 objects to the same demo scene myself and got the frame debug information. Can you help me?
     
  43. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    90
    Hello. Is it possible to change exposed parameters of materials for individual instances similar to using MaterialPropertyBlocks?
     
  44. Hugo99999999

    Hugo99999999

    Joined:
    Jun 8, 2022
    Posts:
    21
    I wonder what tools you use below for statistics, CPU GPU and so on?
     
  45. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there,
    Crowd Animations uses a Shader Graph replacement shader for Lit shader. You can find this shader under GPUInstancer-CrowdAnimations/Shaders/Crowd_Animations_LIT_SG. This shader does not have Transparency. To create a shader with Transparency:
    1- Create a copy of the Crowd_Animations_LIT_SG shader and give it a new name
    2- Open Shader Graph Window by clicking on the new shader
    3- Change Surface Type to Transparent under Graph Settings
    4- Save the changes
    5- Select the material and change the shader to your newly created shader

    Hi there,
    Please see Using a Multiple Camera Setup documentation.

    Hi there,
    Please email us a sample project following this guide and we can investigate.

    Hi there,
    Please see Material Variations documentation.
     
  46. Coreengage

    Coreengage

    Joined:
    Nov 25, 2020
    Posts:
    6
    Hi, I'm using GPUInstancerDetailManager and editing my terrain heights at runtime. Can I snap the grasses in the edited area again to the terrain?

    InitializeGPUInstancer API is doing this but not suitable for multiple use at runtime.
    RemoveInstancesInsideBounds API is perfect for remove at runtime, can i use something like that to only update the positions?

    Thank you.
     
  47. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    538
    Hi there
    Unfortunately there is not a built-in method to update the heightmap at runtime other than the InitializeGPUInstancer API.
     
    Coreengage likes this.
  48. AngelGalaxyOfficial

    AngelGalaxyOfficial

    Joined:
    Apr 10, 2021
    Posts:
    16
    Is there anyway to enable the default LOD group for my gpu instanced prefabs? Every time I start Play Mode, LOD Group is turned off.

    If there's no way, any small code modifications I can do to allow it or...?
     
  49. Hugo99999999

    Hugo99999999

    Joined:
    Jun 8, 2022
    Posts:
    21
    I looked at multiple camera Settings, but it still didn't solve my problem because my scene was loading dynamically. There are three cameras on the vehicle and the vehicle will not load until the editor is running. If I go and use the Selected Camera Only, it won't work. What am I supposed to do now?
     
  50. Hugo99999999

    Hugo99999999

    Joined:
    Jun 8, 2022
    Posts:
    21
    Hello, I have a problem here, that is, I have used GPUAPI to dynamically obtain the camera, my camera is dynamically loaded out, at runtime, I have the tree manager and prefab manager in my scene. But in the game window, only the tree manager is deleted, and the prefab manager has no effect. How is this going? Please tell me, thank you very much.