Search Unity

Help Wanted DrawMeshInstancedIndirect and Shader Graph

Discussion in 'Shader Graph' started by Aaron-Meyers, Aug 2, 2019.

  1. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    216
    I'm evaluating LWRP/Shader Graph for a project that would rely heavily on DrawMeshInstancedIndirect. I'm unclear on how/if it would work with Shader Graph. Its not apparent how I'd access something like unity_InstanceID from a Shader Graph. I guess I don't really know how you'd read from a StructuredBuffer inside a ShaderGraph either! I don't see an option for it in the Blackboard section.

    Maybe doing instanced rendering that relies on a StructuredBuffer for each instances info would be more of a job for Visual Effect Graph?

    I'm just trying to wrap my head around how this would work with LWRP. Any insight appreciated!
     
    Lars-Steenhoff and foxnne like this.
  2. thomh_unity

    thomh_unity

    Unity Technologies

    Joined:
    Feb 19, 2019
    Posts:
    10
    Hello Aaron-Meyers,

    DrawMeshInstancedIndirect is not currently supported in Shader Graph.

    This feature is on the road-map but not yet planned.
     
    Lars-Steenhoff likes this.
  3. edan_unity

    edan_unity

    Joined:
    Sep 20, 2017
    Posts:
    2
    Ya I am having the similar issue as well. At the moment I had to flatten the instances if I want to use shader graph rather than copy-and-pasting the whole big chunk of shader code from github. It will be great if there is a way to "hack" around through some custom functions.
     
  4. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    216
    Thanks for clarifying that. So in the meantime, is Visual Effect Graph a viable option?

    To get more specific, I have been working on a lot of projects visualizing point cloud data and I use DrawMeshInstancedIndirect to draw meshes (usually cubes) at each point contained in a packed buffer for each frame.

    I haven't really dug into VEG yet, but the examples I've seen seem to suggest that StructuredBuffers containing custom structs are supported, but that's just my intuition. Can you confirm if drawing hundred of thousands of cubes from such a buffer in one draw call would be possible using VEG?
     
    Lars-Steenhoff likes this.
  5. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    259
    It's possible to do something along these lines using Texture2D and Texture3D as your buffers. Check out Keijiro's stuff using the VFX Graph on Github.
     
    Lars-Steenhoff likes this.
  6. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    232
    Hi,

    Any updates on this?

    Is DrawMeshInstancedIndirect+ShaderGraph+HDRP not possible at all at the moment?

    Thanks.
     
    MODev and Lars-Steenhoff like this.
  7. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,357
    Where is the roadmap ?
     
  8. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,352
    I got instanced indirect working with the shader graph.

    I made a subnode graph that injects the setup function that reads a structured buffer and sets the Object2World and WorldToObject matrices for each instance.

    This was done using 2 CustomCode nodes. One with an external file asset with the setup function and the other to add the #pragma to call it.
     
    sqallpl and Lars-Steenhoff like this.
  9. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    259
    Would you be up for sharing an example?
     
    sqallpl likes this.
  10. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,352
    Sure. Here is a link to a package. It is for HD SRP and needs 7.x version to work because of the change to Asset reference instead of a relative path for include files.

    The setup function is for use with Vegetation Studio but just replace that to fit the data/names in your structured buffer.

    Lennart
     
    sqallpl and andybak like this.
  11. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,352
    And connect it like this. Using the vertex position it will be evaluated for shadow passes also.

    Lennart Image 267.png
     
    andybak and sqallpl like this.
unityunity