Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

[RELEASED] GPU Instancer

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

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    If the number of instances varies, am I supposed to clear up the compute buffer some how? It seems that using SetDataPartial with varying count, doesn't clean up left over instances.
     
  2. GurhanHazinedar

    GurhanHazinedar

    Joined:
    Apr 24, 2017
    Posts:
    161
    You need to set the data on the indexes that you want to clean to Matrix4x4.zero.
     
  3. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    forgive me my ignorance, but what is the point of set data partial if then I have to set anyway the whole buffer? Probably it's for cases different than mine

    I wonder if it wouldn't be better to clear them in the shader (if possible) thus assuming that I have to set it every frame (which is what I do)
     
    Last edited: Apr 17, 2019
  4. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    I am not sure if for my case it's optimal to reset the remain of the compute buffer every frame, as the number of instances change continuously (building game), it would be better to be able to tell to GPU Instancer how many instances I am going to render this frame instead. Alternatively the buffer should be cleared every frame for me (if it makes sense, but not on the CPU).

    following the current logic, if I have a maximum of 10.000 instances, I have to reset the whole buffer even if currently I have placed only one block. Instead I would like to have a 10.000 buffer and say every frame how many instances I want to render
     
    Last edited: Apr 17, 2019
  5. GurhanHazinedar

    GurhanHazinedar

    Joined:
    Apr 24, 2017
    Posts:
    161
    If you are using an unordered array where the instances change indexes, it would be better to set the instance counts manually. GPUI generates a runtime data object for each prototype and they keep a variable called instanceCount. You can set this value at runtime and the remaining instances of the 10.000 will be ignored. This way you can update the buffers according to your instanceCounts without setting the rest to zero.

    You can access it from:
    Code (CSharp):
    1. prefabManager.runtimeDataList[i].instanceCount
     
    sebas77 likes this.
  6. Johnbmac

    Johnbmac

    Joined:
    Nov 20, 2018
    Posts:
    1
    hi. I purchased gpu instancer. I think it is brilliant. I am wondering about possible conflicts with Procedural worlds products, ie...CTS, Gaia, Gena, Sector, and Enviro (by Heindrik Haupt) . Thanks very much!
     
  7. Bamfax

    Bamfax

    Joined:
    Jun 12, 2016
    Posts:
    51
    May I ask for getting this on feeding the matrix4x4Array via ComputeShader as well? Pretty please :)

    Just had a go at

    foreach (GPUInstancerRuntimeData runtimeData in PrefabManager.runtimeDataList)
    runtimeData.instanceCount = UsedCapacity;

    but SetData() was not around to handle my humble request. ;)

    ...but also not really too important, I am currently fine with clearing out the matrix4x4Array in my code.
     
    Last edited: Apr 18, 2019
  8. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    If I have N instances and I want to change the material on one of them (making it transparent) should I register a different prefab or it's better to use something else? P.S.: I know you don't support the transparent pipeline, it was just an example. I know I can use something similar to material blocks, but I guess in this case I am really talking about changing the whole material. Maybe could be useful to be able to create a prototype from an existing prototype with a different material.

    about prefabManager.runtimeDataList.instanceCount, I am not sure how do I get i from the GPUInstancerPrefabPrototype. If I do the following, it doesn't work (and anyway I still would like to not use find)

    Code (CSharp):
    1. prefabManager.runtimeDataList.Find(rd => rd.prototype == prototype).instanceCount = count;
    2.             // find runtimeData for prefab
    3.             var prefabRuntimeData = GPUInstancerAPI.GetTransformDataBuffer(prefabManager, prototype);
    4.             // set data to buffer
    5.             prefabRuntimeData.SetDataPartial(matrix4x4Array, 0, 0, count);

    and last thing: if I want to simulate render queues, what is the best method? Have different GPUIPrefabManagers? If so how do I control the order of rendering? I was surprised to notice that as it is the transparency works great for us, but I am not sure if it's just a coincidence

    upload_2019-4-18_10-45-26.png
     
    Last edited: Apr 18, 2019
  9. unity_c1ndWE1Nn46iPg

    unity_c1ndWE1Nn46iPg

    Joined:
    Jan 13, 2019
    Posts:
    149
    Hi, can you tell me what's the meaning of fetching tree instances, what does it do? Since some of my trees don't have collider when using with GPUI
     
    Last edited: Apr 18, 2019
  10. Ryan-Hayle

    Ryan-Hayle

    Joined:
    Feb 16, 2014
    Posts:
    68
    Thanks! Where is the map magic integration demo as shown in the video?
     
  11. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Hi there and thanks!

    GPUI would work out of the box with CTS, Gena, Gaia and Enviro. We also have an integration with Gaia for ease of use. We have not yet tested GPUI with SECTR.
     
  12. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Hi there :)

    Not sure that I understood you correctly, but at any time (including a compute shader feeding matrix4x4 scenario), you can access the buffer for the instances with:

    Code (CSharp):
    1. ComputeBuffer dataBuffer = GPUInstancerAPI.GetTransformDataBuffer(prefabManager, prototype);
    and modify the buffer with:

    Code (CSharp):
    1. dataBuffer.SetData(matrix4x4Array, 0, 0, UsedCapacity);
     
  13. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Since GPU Instancing works by batching together the same Mesh/Material combinations as instances, it is not possible to have some of the instances of a GPUI prototype use a different material from the others. Thus, you are right in thinking you need to define them as a separate prototype (or if there are not many instances of the different material version, disable instancing for those instances and use the default Unity Mesh Renderer for those).

    I'm not sure I understand this question. If you can email us a sample project showing what you are trying to achieve, we can point you to the right direction about it.
     
  14. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Hi there,
    GPUI does not change anything as far as Colliders are concerned: the Collider components on the prefab instances are not changed by GPUI. Also, if your trees are on a Unity terrain, since the terrain engine is handling the Colliders as normal, again, GPUI has nothing to do with them.
     
  15. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Thanks
    @LouskRad I'll post the code here next week when I am back from the holidays (so you can get a break too :D).

    About the prefab for a different shader I was wondering if I am forced to provide a game object as I need to change the shader in run time and thus it would not be convenient.
     
  16. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    We made a quick scene by modifying the MapMagic demo scene to showcase the integration in the video; it is not included in the package or provided otherwise.
     
  17. unity_c1ndWE1Nn46iPg

    unity_c1ndWE1Nn46iPg

    Joined:
    Jan 13, 2019
    Posts:
    149
    Does using no prefab cause the problem since I use the original?
     
  18. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Just a nudge that I should write on Saturday to remind that I still would like to know if transparent materials are rendered after the opaque ones as otherwise I don't understand how my transparent materials are currently working so well (check my previous posts) and if there is a better way than modifying an existing game object to apply a different shader to an existing gpuinstance prefab. Enjoy the holidays!
     
  19. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Can you describe the problem a little clearer? Colliders should work the same with and without GPUI in Unity. Are you seeing a different result with GPUI?
     
  20. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    About transparency: Unity always draws the shaders with the transparent rendering queue last, but the problem is transparent instances when GPU Instancing are not ordered since they are drawn in a single draw call. In some camera angles the draw order might look right and in some others it won't - the problem is that they are not being ordered. In short, it might look right in some cases but there is no guarantee that it will look right in all cases so it cannot be used safely (without an OiT solution).

    As for switching the shader for a prototype at runtime, there is currently no support for this without re-initializing the instances or defining a new prototype.
     
  21. unity_c1ndWE1Nn46iPg

    unity_c1ndWE1Nn46iPg

    Joined:
    Jan 13, 2019
    Posts:
    149
    Sorry, I forgot to delete the post.. I already fixed it
     
  22. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    For the transparency I know exactly what you mean but I didn't realise GPUI was anyway rendering the transparent after the opaque which may be good enough for us. Btw you explained it like if unity is managing the pipeline, but this is not the case right? You just took the standard decision to split the opaques from the transparent as well.


    About the shader, is there an alternative way to create gpui prefabs that do not involve converting a gameobject? This is my real question and if you confirm that there isn't please add in the wish list
     
  23. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Hi everyone,

    We have just submitted the GPU Instancer version 1.1.1 to the Asset Store. This update includes various improvements and bug fixes as usual. The update should be live in the Asset Store in the next few days.

    Firstly, we have prepared a new video tutorial that shows how to use the basics of the Prefab Manager:



    With this update, we have added the LWRP version of the foliage shader. You can find this shader in a separate package under GPUInstancer/Extras/GPUI_Foliage_LWRP_Support.unitypackage.

    We have also added a ShaderGraph GPUI Setup node (ShaderGraph v4.x only). You can take a look at this wiki documentation to see how you can use this node to setup GPUI for use with your ShaderGraph shaders.

    GPUI-ShaderGraph-SetupNode.png

    Next up, we have added an advanced action "Serialize Registered Instances", which will allow you to use a no GameObject workflow without writing any additional code. You can take a look at the advanced actions section of the wiki for more information on using this feature.

    Also, we have added the GPUInstancerLODColorDebugger.cs script which you can use to visualize the LOD levels on your prototypes for debug purposes.

    GPUI-LODColorDebugger.png


    The update also includes various API changes and bug fixes, along with optimizations for various features.

    The full v1.1.1 changelog is as follows:

    New: Added LWRP support for the GPUI Foliage Shader
    New: Added ShaderGraph GPUI Setup node (ShaderGraph v4.x only)
    New: Added a new overload for the InitializeGPUInstancer API method where you can initialize a specific prefab prototype
    New: Added Prefab Instance Serialization advanced action, to render prefab instances without GameObjects by saving transform data without aditional coding (Unty 2018.1 and above only)
    New: Added experimental Simulation feature to render instances in Edit Mode for disabled mesh renderers and serialized prefab instances
    New: Added LOD color debugger tool to visualize prototype LOD levels

    Changed: DrawMeshInstancedIndirect argsBuffer stride size is fixed to uint and the count is set according to the renderer amount
    Changed: InitializeWithMatrix4x4Array API method so that it is not required to call the InitializeGPUInstancer before calling this method
    Changed: Optimization for Prefab Manager Editor which will no longer re-enable renderers while exiting Play Mode
    Changed: Nested Prefabs Optimization for Scene Prefab Importer tool

    Fixed: DefineGameObjectAsPrefabPrototypeAtRuntime API method null reference exception when the manager is created at runtime
    Fixed: HiZ Occlusion Generator controls for stereoTargetEye as "both eyes" when VR is enabled only
    Fixed: Compute Buffer not set error when using 5 or more LOD levels
     
    ftejada, Bamfax, docsavage and 2 others like this.
  24. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    443
    Anyway to get the alpha with a softer look and not the cutout hard type look? This is strictly for VR as the alpha cutout causes alpha buzzing and looks really bad in heavy alpha environments. Also do you know if in mobile VR we can use baked lightmapping with your your gpu instancer as well?

    I'm working on mobile VR environments and just trying to see what gpu instancer can do and still run and look as best as it can on mobile hardware but the first thing would be is softening up the alpha to start.
     
  25. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Unity is indeed managing the low level pipeline, GPUI is only registering the draw calls; order is managed by the Render Queue property on the materials as usual.

    upload_2019-4-23_0-29-15.png

    I can confirm this; there is no API method to do this otherwise - and your request is noted. :)
     
    sebas77 likes this.
  26. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Hi there,

    If you mean the foliage shader, it uses alpha testing (not transparency by alpha). That is, the shader assigns a value of 1 to the alpha channel and clips the pixels that are below the cutoff. You can modify this shader to implement AlphaToMask to keep the alpha value and assign it to the shader's Alpha output. If you do this, you would need to use MSAA and Forward Rendering.

    Another option is to use a custom shader that would look exactly as you wish, GPUI can auto-convert that shader to work with itself.

    Also you can use a post-processing effect and apply either FXAA or TAA for an AntiAliasing effect, although performance would be a concern in a mobile VR platform if you do this.

    As for baked lighting, GPUI works with real-time lighting and does not support baked lights.
     
  27. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    443
    Noted on the alpha testing. I'll do some testing for mobile vr and come back with any questions I have on that later as well.

    Do you know if in the future GPUI could support lightmapping? A great lighting mode is shadow mask for mobile it is a great lighting mode to be able to use for performance. I already purchased GPUI but just wanted to ask these questions before I dive in and do some testing out.
     
  28. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    [QUOTE="LouskRad, post: 4458193] I can confirm this; there is no API method to do this otherwise - and your request is noted. [/QUOTE]

    Thank you for this and the new release of GPUI. Since I will need to change the shader of one mesh at time, I'll render that single mesh with a normal gameobject. I am not sure how I would like to have the final feature. If I am forced to register a new prefab, then I would like to be able to create a prefab from an existing one instead to use a game object.
     
  29. VideoTutorial

    VideoTutorial

    Joined:
    Jun 27, 2017
    Posts:
    12
    For Animation Instancing (skinned mesh) check out
     
  30. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    @LouskRad

    Regarding the count problem to optimize the code in relation to the real number of instances to update, this is what I am doing now:

    https://hastebin.com/ecuxusipax.cs

    I didn't manage to make the count solution work in anyway. IMO it should be very simple to modify it for the user (us). If you can consider this feature too I would appreciate it.

    P.S.: if it's going to take days to get the new version from the asset store, can I have it now? I need the shader graph update.
     
    Last edited: Apr 23, 2019
  31. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    280
    Hey this looks really nice! I noticed throughout this thread you have mentioned skinned mesh support and had planned to provide an update on it "within days" at the start of the month. I was wondering if you could update us again on this feature? In particular I'm curious as to what high-level features you think you can obtain. Typically the hardest problem I've not seen solved is a solution that natively supports mecanim animation setups. Do you plan to aim for that, or something simpler in the form of more basic animation workflows?

    Cheers!
     
  32. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    577
    Lighmapping support is not in our roadmap for the near future.


    You can read the instanceCount variable in the GPUInstancerRuntimeData class for an accurate instance count.
    Also, the update package is live on the Asset Store currently.

    Hi there, and thanks.

    The skinned mesh support will be an extension asset and it is currently our priority. We will open a new forum thread with details of this asset and announce it here in the next week.

    As for your question, the skinned-mesh support will allow for two types of workflows: one that uses the Mecanim Animator and one with a more lightweight and faster animator. As I said, we will post the details in the new forum, but the Mecanim Animation support limitations will initially be Animation Layers, Masks and IK.
     
    strich likes this.
  33. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    280
    Great info thanks. To be clear, do you mean "Animation Layers, Masks and IK" will not be supported initially?
     
  34. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    @LouskRad sorry I think you forgot my case (you requested previously the code to understand it better), I need to write the count to change the number of instances to render, not read it. As you can see from the code right now I am zeroing the matrices but I still think that it's a waste

    -
     
  35. GurhanHazinedar

    GurhanHazinedar

    Joined:
    Apr 24, 2017
    Posts:
    161
    Yes, that is true.

    Hi @sebas77
    Can you please contact support@gurbu.com ? So that we can follow the conversation clearly and send you updates/fixes if needed.
     
  36. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Done, I agree that this discussion probably won't help anyone else until we agree if the feature is reasonable or not. However I have another question (duh): Currently we use prefabs with hierarchies and several meshes, or even one mesh with several materials. I didn't realize that somehow you are managing the hierarchical transformation for me, as I currently set the transformation matrix only for the root and everything is working fine.
    If you confirm that this is the case, I wonder what I should do in the case instead I want to transform separately specific nodes of the hierarchy.

    Edit: something is wrong with the
    GPUInstancerShaderGraphNode. It extends
    CodeFunctionNode, but this class is declared internal inside the
    UnityEditor.ShaderGraph which should be a separate assembly. Help?
     
    Last edited: Apr 24, 2019
  37. GurhanHazinedar

    GurhanHazinedar

    Joined:
    Apr 24, 2017
    Posts:
    161
    You can change the transform of the child renderers, if it will be applied to all instances (check the attached example). But if you want to make changes per instance base, you need to define the child as a separate prototype so that GPUI can create new transform buffers it. This is not done by default to conserve GPU memory.

    Which version of Shader Graph are you using? The node is only for Shader Graph versions 4.x. Please check the documentation for details.
     

    Attached Files:

  38. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Thank you, eventually you are suggesting that hierarchy should be handled by me which is what I was expecting.
    Indeed we are using the latest version of shader graph, I am not sure if our tech arts will be happy to switch to a previous version so in case we will use amplify.

    Ps. :from this link it seems that the last shader graph may have an alternative but I didn't manage to make it work https://forum.unity.com/threads/una...ssibility-of-customfunctionnode-class.586876/
     
    Last edited: Apr 25, 2019
  39. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    147
    Hi there! I recently got this asset and the performance is amazing. I am really happy with it. I do have some questions though:
    1. I cannot seem to get billboard shadows to work correctly. I've written some custom shaders which I am using and if I instantiate a billboard in the editor with "Show Billboard", it will cast shadows. In-game however, only the mesh objects cast shadows. Normally I would use the frame debugger to find a solution to this, but it seems indirect procedural draws don't show info in the same way.
    2. I'm using the "No-GameObject workflow" with an instance list which is generated by checking random points on the terrain against my splat map. I was wondering if it is possible to load the result in the editor somehow, so I don't have to run the game constantly to check the result.
    3. The resulting instance list contains over a millions elements, and I'm relying on the Prefab Manager to cull them based on distance. This seems to work fine, however I'd like to ask if you have any suggestions on how to add collision to so many objects. The game is a flight simulator, and I really only need to check if the player plane is colliding with trees, so I would be fine with a "localized" solution.
    Thanks for the great asset!
     
  40. Ameng_c

    Ameng_c

    Joined:
    Apr 25, 2019
    Posts:
    4
    This is a wonderful asset,but I don't understand it.I tried to replace "ColorVariationShader_GPUI" with a custom shader,but it produced bad results.

    Code (CSharp):
    1. Shader "Custom/ligthing" {
    2.     Properties {
    3.         _Color ("Color", Color) = (0.07843138,0.3921569,0.7843137,1)
    4.     }
    5.     SubShader {
    6.         Tags {
    7.             "RenderType"="Opaque"
    8.         }
    9.         LOD 200
    10.    
    11.         Pass {
    12.             //Name "FORWARD"
    13.             Tags {
    14.                 "LightMode"="ForwardBase"
    15.             }          
    16.            
    17.            
    18.             CGPROGRAM
    19.             #include "UnityCG.cginc"
    20.             #include "./../../../Shaders/Include/GPUInstancerInclude.cginc"          
    21.             #pragma instancing_options procedural:setupGPUI
    22.             #pragma multi_compile_instancing
    23.             #pragma vertex vert
    24.             #pragma fragment frag
    25.             #define UNITY_PASS_FORWARDBASE
    26.             #pragma multi_compile_fwdbase_fullshadows
    27.             #pragma only_renderers d3d9 d3d11 glcore gles
    28.             #pragma target 3.0
    29.             float4 _Color;
    30.  
    31.             #if SHADER_API_D3D11
    32.             #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    33.             StructuredBuffer<float4> colorBuffer;
    34.             #endif
    35.             #endif
    36.            
    37.             struct VertexInput {
    38.                 float4 vertex : POSITION;
    39.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    40.             };
    41.             struct VertexOutput {
    42.                 float4 pos : SV_POSITION;
    43.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    44.             };
    45.             VertexOutput vert (VertexInput v) {              
    46.                 VertexOutput o = (VertexOutput)0;  
    47.                 UNITY_SETUP_INSTANCE_ID(v);
    48.                 o.pos = UnityObjectToClipPos( v.vertex );
    49.                 return o;
    50.             }          
    51.             float4 frag(VertexOutput i) : COLOR {
    52. ////// Lighting:
    53. ////// Emissive:
    54.             UNITY_SETUP_INSTANCE_ID(i);
    55.             float4 col = _Color;
    56.  
    57.             #if SHADER_API_D3D11
    58.             #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    59.                     uint index = gpuiTransformationMatrix[unity_InstanceID];
    60.                     col = colorBuffer[index];
    61.             #endif
    62.             #endif
    63.                 //float3 emissive = _Color.rgb;
    64.                 float3 emissive = saturate(col).rgb;
    65.                 float3 finalColor = emissive;
    66.                 return fixed4(finalColor,1);
    67.             }
    68.             ENDCG
    69.         }
    70.     }
    71.     FallBack "Diffuse"
    72. }
     
  41. GurhanHazinedar

    GurhanHazinedar

    Joined:
    Apr 24, 2017
    Posts:
    161
    Hi there and thank you for supporting GPUI.

    1. By default, billboards does not cast shadows, since the shaders are not designed for it. But if you are using custom shaders, you can enable the Use Custom Billboard option. This option allows you to enable shadows on billboards.
    2. GPUI has a built-in simulator, you can use this to simulate your instances with a custom editor script. Check the attached package for an example usage.
    3. I can not really say much about this since it depends on your project specifics, but I would recommend to look into implementing a spatial partitioning and/or pooling solution.
     

    Attached Files:

  42. GurhanHazinedar

    GurhanHazinedar

    Joined:
    Apr 24, 2017
    Posts:
    161
    Hi there and thanks!

    Only missing part is that you need to call UNITY_TRANSFER_INSTANCE_ID method in your vert method because you use the instanced property in the frag method.

    Here is the edited shader:
    Code (CSharp):
    1. Shader "Custom/ligthing" {
    2.     Properties {
    3.         _Color ("Color", Color) = (0.07843138,0.3921569,0.7843137,1)
    4.     }
    5.     SubShader {
    6.         Tags {
    7.             "RenderType"="Opaque"
    8.         }
    9.         LOD 200
    10.  
    11.         Pass {
    12.             //Name "FORWARD"
    13.             Tags {
    14.                 "LightMode"="ForwardBase"
    15.             }        
    16.          
    17.          
    18.             CGPROGRAM
    19.             #include "UnityCG.cginc"
    20.             #include "./../../../Shaders/Include/GPUInstancerInclude.cginc"          
    21.             #pragma instancing_options procedural:setupGPUI
    22.             #pragma multi_compile_instancing
    23.             #pragma vertex vert
    24.             #pragma fragment frag
    25.             #define UNITY_PASS_FORWARDBASE
    26.             #pragma multi_compile_fwdbase_fullshadows
    27.             #pragma only_renderers d3d9 d3d11 glcore gles
    28.             #pragma target 3.0
    29.             float4 _Color;
    30.  
    31.             #if SHADER_API_D3D11
    32.             #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    33.             StructuredBuffer<float4> colorBuffer;
    34.             #endif
    35.             #endif
    36.          
    37.             struct VertexInput {
    38.                 float4 vertex : POSITION;
    39.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    40.             };
    41.             struct VertexOutput {
    42.                 float4 pos : SV_POSITION;
    43.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    44.             };
    45.             VertexOutput vert (VertexInput v) {            
    46.                 VertexOutput o = (VertexOutput)0;
    47.                 UNITY_SETUP_INSTANCE_ID(v);
    48.                 UNITY_TRANSFER_INSTANCE_ID(v, o);
    49.                 o.pos = UnityObjectToClipPos( v.vertex );
    50.                 return o;
    51.             }        
    52.             float4 frag(VertexOutput i) : COLOR {
    53. ////// Lighting:
    54. ////// Emissive:
    55.             UNITY_SETUP_INSTANCE_ID(i);
    56.             float4 col = _Color;
    57.  
    58.             #if SHADER_API_D3D11
    59.             #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    60.                     uint index = gpuiTransformationMatrix[unity_InstanceID];
    61.                     col = colorBuffer[index];
    62.             #endif
    63.             #endif
    64.                 //float3 emissive = _Color.rgb;
    65.                 float3 emissive = saturate(col).rgb;
    66.                 float3 finalColor = emissive;
    67.                 return fixed4(finalColor,1);
    68.             }
    69.             ENDCG
    70.         }
    71.     }
    72.     FallBack "Diffuse"
    73. }
     
  43. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    147
    Thank you for the reply. Would it be possible to add/hack in support for the built in system? I really, really like that I can bake the billboards in-editor, it would be a shame to lose that perk. I've added support to the shader itself, I just need GPUInstancer to do the actual draw call.
    I'll look into spatial partitioning, thanks!
     
  44. GurhanHazinedar

    GurhanHazinedar

    Joined:
    Apr 24, 2017
    Posts:
    161
    Check the GPUInstancerUtility.cs, search for method AddBillboardToRuntimeData. You will see there a variable called isShadowCasting, which is false by deafult.
     
    Fewes likes this.
  45. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    147
    It worked! Thank you very much.
     
  46. Ameng_c

    Ameng_c

    Joined:
    Apr 25, 2019
    Posts:
    4
    Thank you for helping me to solve the problem.
     
  47. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    After we realised that we cannot downgrade ShaderGraph to the version 4.x on Unity 2019, we switched to Amplify, but even with amplify and following your instructions on the wiki we are not able to make it work. We tried to figure out how the include path works, but we haven't worked it out and we get a different error with each test.

    For example, with this test, we managed to stop having the file not found error, but now we get these:

    upload_2019-4-26_15-20-46.png

    upload_2019-4-26_15-21-5.png

    upload_2019-4-26_15-22-28.png
     
  48. GurhanHazinedar

    GurhanHazinedar

    Joined:
    Apr 24, 2017
    Posts:
    161
    Hi @sebas77
    It should work when you remove the UnityCG.cginc include directive. This is not required and it would cause errors with SRP. The wiki documentation does not include the SRP for ASE because they did not have the support at the time we wrote it. We will update the wiki with the new features.
     
  49. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    yes we tried that, it actually compiles, but GPUInstancer still can't find the shader:

    upload_2019-4-26_17-14-57.png
     
  50. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    I realised that this may have been due to the fact that we were using precompiled shader. I am still not sure if I have to add your precompiled shaders in the precompiled shaders list or not.