Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

HD render pipeline and instancedIndirect

Discussion in 'Graphics Experimental Previews' started by LennartJohansen, Mar 22, 2018.

  1. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi.

    Have anyone got instanced indirect rendering working with the new HD pipeline.
    I made a copy of the standard HD.Lit shader and added the #pragma instancing_options procedural:setup and a include file with the setup function

    Code (csharp):
    1.  
    2.  
    3. #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    4.  
    5.     struct IndirectShaderData
    6.     {
    7.         float4x4 PositionMatrix;
    8.         float4x4 InversePositionMatrix;
    9.         float4 ControlData;
    10.     };
    11.  
    12.         StructuredBuffer<IndirectShaderData> VisibleShaderDataBuffer;
    13. #endif
    14.  
    15. void setup()
    16. {
    17. #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
    18.         unity_ObjectToWorld = VisibleShaderDataBuffer[unity_InstanceID].PositionMatrix;
    19.         unity_WorldToObject = VisibleShaderDataBuffer[unity_InstanceID].InversePositionMatrix;
    20. #endif
    21. }
    22.  
    23.  
    The shader compiles and it works as normal for instancing but when I try to render instanced indirect nothing shows up at all.

    Any ideas?

    Lennart

    Edit: I do get one instanced rendered. at 0,0,0 position. It looks like the setup code does not run.
     
  2. Shinao

    Shinao

    Joined:
    Mar 7, 2014
    Posts:
    36
    Bump. Any infos on indirect instancing and surface shader alternative for HDRP ?
     
    Last edited: Jun 15, 2018
  3. pablo-romero-rigger

    pablo-romero-rigger

    Joined:
    Oct 25, 2017
    Posts:
    3
    Hi!. I´m in the same.. here we need documentation about how to make a custom HDRP shader with indirect instance support.

    thanks!

    Best!.
     
  4. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi.

    Have a look here. These nodes are spesific to my implementation but the principle is the same.

    Lennart
     
    AggressiveMastery likes this.
  5. pablo-romero-rigger

    pablo-romero-rigger

    Joined:
    Oct 25, 2017
    Posts:
    3
    Thanks LennartJohance.. but what dependency I need?
     
  6. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    You will have to make your own node to inject your custom setup function, pragmas and redefine the unity_ObjectToWorld and unity_WorldToObject

    The redefine is needed since the HD srp renders relative to the camera position.

    As an alternative to a node you can edit the shader manually to add the needed code.

    Lennart
     
    AggressiveMastery likes this.
  7. pablo-romero-rigger

    pablo-romero-rigger

    Joined:
    Oct 25, 2017
    Posts:
    3
    I understand. by the way, about relative camera position. in my projects what I have and demos that I have seen.. the shadows moving without sense.. but when I set camera relative = 0. the behaviour shadow position works fine.
     
  8. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    365
    @LennartJohansen

    Hi,

    Do you know what options are available at the moment for HDRP+ShaderGraph+DrawInstancedIndirect?

    As far as I understand from your other posts, it's not possible to use your shader graph nodes from GitHub as the custom node API has changed.

    I've also found a related reply on the ShaderGraph forums

    Is it possible to use DrawInstancedIndirect+HDRP+ShaderGraph at this moment somehow?

    Any answer will be much appreciated. Thanks!
     
  9. AggressiveMastery

    AggressiveMastery

    Joined:
    Nov 19, 2018
    Posts:
    206

    @sqallpl.

    I am working on the FPS Sample, which uses the HDRP, and runs in 2018.3.0f2. I have been able to get Veg Studio Pro, using @LennartJohansen linked script above (
    https://github.com/AwesomeTechnologies/VegetationStudioPro-ShaderGraphNodes) for 2018 (diffrent brance per his instructions.) working.

    By adding that node to the shader graph packages folder (Packages > Shader Graph > Editor > Data > Nodes), and creating my own hdrp shader, i'm getting trees rendered instanced indirect in hdrp.

    Without that script, the instance indirect rendering places the replicants on top of you, Veg Studio manages the modification of those positions. I think Lennart was saying you could write your own script to do that, or purchase his package. I'm a strong believer in his stuff!

    Cheers
    Micah
     
  10. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    365
    @AggressiveMastery ,

    Hi. Looks like the ShaderGraph custom node API has changed in 2019.1.
    Anyway, according to the reply in the ShaderGraph forums, the feature is on the road-map.

    https://forum.unity.com/threads/2019-1-shadergraph-custom-nodes-poll-please-vote.648454/

    https://forum.unity.com/threads/fee...n-render-pipeline.560653/page-20#post-5018786

    https://forum.unity.com/threads/drawmeshinstancedindirect-and-shader-graph.720638/#post-4834331
     
  11. AggressiveMastery

    AggressiveMastery

    Joined:
    Nov 19, 2018
    Posts:
    206
    All depends how long you can wait, or if you can catch the falling knife. Since the wait is never over...
     
  12. cert

    cert

    Joined:
    Feb 10, 2013
    Posts:
    24
    Can anyone post a HDRP + DrawInstancedIndirect solution? I tried to find out how Lennart got this working, but i can't see my mesh .... no errors.
     
  13. ekakiya

    ekakiya

    Joined:
    Jul 25, 2011
    Posts:
    59
    For camera relative space rendering, HDRP overrides UNITY_MATRIX_M with deform function, and prevent the direct use of unity_ObjectToWorld and the inv matrix.
    It conflicts with the instancedIndirect's procedural function, that process unity_ObjectToWorld at the beginning of fragment shader.
    The Lennart's solution looks like revive unity_ObjectToWorld by redefinition, then process it as usual instancedIndirect's procedural function.
     
  14. cert

    cert

    Joined:
    Feb 10, 2013
    Posts:
    24
    It's working now with the package Lennart posted in another thread and some modifications in the script!
     
  15. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    802
    Is Lennarts package still the preferred solution for supporting Graphics.DrawMeshInstancedIndirect in ShaderGraph? I get "error CS0122: 'CodeFunctionNode' is inaccessible due to its protection level" when importing the package.
     
  16. echu33

    echu33

    Joined:
    Oct 30, 2020
    Posts:
    49
    Hey guys, I managed to using draw instance indirect with shadergraph + HDRP.



    The custom function node(string mode)pragma inject method are still working. So basically just make sure your custom function has connect to master node output. so shadergraph can generate instancing indirect code properly.

    Here's the unity package that contains the graph sample and related script, hope it helps.
    (Import the package in Unity2021, HDRP installed project)
     
    Last edited: Jan 12, 2023
    crism_unity and cecarlsen like this.
  17. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    802