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.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Resolved Graphics.DrawProcedural works, but Graphics.DrawProceduralIndirect does not

Discussion in 'High Definition Render Pipeline' started by n3b, Mar 10, 2023.

  1. n3b

    n3b

    Joined:
    Nov 16, 2014
    Posts:
    56
    upd: nevermind, found out I have to specify GraphicsBuffer.Target.IndirectArguments :/

    Hey guys, so I have these two identical calls, but only the first one actually outputs something in Unity. Am I missing something or is it broken? Thanks!

    Code (CSharp):
    1.  
    2. void Awake()
    3. {
    4.     material = Resources.Load<Material>("Shader Graphs_New Shader Graph");
    5.  
    6.     var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
    7.     var mesh = go.GetComponent<MeshFilter>().sharedMesh;
    8.     index = new GraphicsBuffer(GraphicsBuffer.Target.Raw, mesh.triangles.Length, sizeof(int));
    9.     verts = new GraphicsBuffer(GraphicsBuffer.Target.Raw, mesh.vertices.Length, UnsafeUtility.SizeOf<float3x2>());
    10.     index.SetData(mesh.triangles);
    11.     verts.SetData(mesh.vertices.Select((x, i) => new float3x2{c0 = x, c1 = mesh.normals[i]}).ToArray());
    12.     Destroy(go);
    13.    
    14.     material.SetInt("vertexCount", verts.count);
    15.     material.SetBuffer("verts", verts);
    16.  
    17.     cmd = new GraphicsBuffer(GraphicsBuffer.Target.Raw, 5, sizeof(int));
    18.     cmd.SetData(new[] { index.count, 1, 0, 0, 0 });
    19. }
    20.  
    21. void Update()
    22. {
    23.     var data = new int[5];
    24.     cmd.GetData(data);
    25.     Graphics.DrawProcedural(material, new Bounds(Vector3.zero, Vector3.one * 10000), MeshTopology.Triangles, index, data[0], data[1]);
    26.     Graphics.DrawProceduralIndirect(material, new Bounds(Vector3.zero, Vector3.one * 10000), MeshTopology.Triangles, index, cmd);
    27. }
    28.  
    29.  

    custom function for shader graph:
    Code (CSharp):
    1. #ifndef TEST_VERTEX_INCLUDED
    2. #define TEST_VERTEX_INCLUDED
    3.  
    4. ByteAddressBuffer verts;
    5. uint vertexCount;
    6.  
    7. void Pos_float(uint vertexId, uint instanceId, out float3 position, out float3 normal) {
    8.     const uint index = instanceId * vertexCount + vertexId;
    9.     const uint adds = index * 24;
    10.     position = asfloat(verts.Load3(adds));
    11.     normal = asfloat(verts.Load3(adds + 12));
    12. }
    13. #endif
     

    Attached Files:

    Last edited: Mar 11, 2023