Search Unity

Bug DrawProcedural API is not supported by ShaderGraph Instance ID Node

Discussion in 'High Definition Render Pipeline' started by yzhao105, Nov 8, 2022.

  1. yzhao105

    yzhao105

    Joined:
    Sep 15, 2017
    Posts:
    28
    As far as I know, out of all the Graphics.DrawSomething APIs, only DrawMeshInstanced is supported by ShaderGraph. The Instance ID Node will always return 0 for the other APIs. Is this a bug, or is this an intended feature? Why are they not supported?
     
  2. amarcolina

    amarcolina

    Joined:
    Jun 19, 2014
    Posts:
    65
    I've been diving into this myself, unable to find any official answer unfortunately. It seems simply that procedural instancing is not supported for shadergraph shaders, not because HDRP doesn't support it, but simply due to the omission of the relevant #pragma in the generated shaders. I was able to get it to work using this hack I found using custom nodes, which worked for me! But definitely a hack and not officially the right way to do things hah

    upload_2022-11-9_18-53-56.png

    The code inside the custom function is simply to find a way to inject the #pragma into the generated shader, and so just needs to be present in the graph, it doesn't actually return an output any different than its input. The code is also hacky with it's braces placement, but it worked in my test.

    Here is the code directly for copy-pasting


    Code (CSharp):
    1. #pragma instancing_options procedural:setup
    2. Out = In;
    3. }
    4.  
    5. void setup() { }
    6.  
    7. void dummy() {
     
    yzhao105 likes this.
  3. yzhao105

    yzhao105

    Joined:
    Sep 15, 2017
    Posts:
    28
    Thanks! In the past version where shadergraph didn't have an InstanceID node, I would modify the generated code to include instancing. But that solution is not as straight forward as just plugging in a node. When I saw InstanceID node added in the newly released hdrp versions, I thought I could finally do instancing the easier way... I just don't understand why after so many years this feature is still not supported.
     
    amarcolina likes this.