Search Unity

[BUG] Unable to render few objects with Graphics.DrawProcedural and vertex compute buffer

Discussion in 'General Graphics' started by vladstorm_, Aug 14, 2018.

  1. vladstorm_

    vladstorm_

    Joined:
    Nov 26, 2013
    Posts:
    184
    Hi everyone,

    I cannot render several objects using Graphics.DrawProcedural.

    So, I'm using compute shaders to generate geometry.
    Then I prepare all the vertices which I wanna render in a vertex compute buffer.
    Then I use Graphics.DrawProcedural to render the geometry from the buffer.
    It totally works fine with just 1 object but if I render a few objects then sometimes only one object is shown.
    Why it could be?

    Code (CSharp):
    1. public class Renderer : MonoBehaviour {
    2.  
    3.      public Material mat;
    4.  
    5.      ComputeBuffer _vertices;
    6.     int _verticesCount;
    7.  
    8.    void Start() {
    9.  
    10.       //here i'm generating the vertices and saving them to _vertices buffer
    11.       CreateBuffers();
    12.  
    13.       MeshRenderer mr = this.GetComponent<MeshRenderer>();
    14.       if(mr!=null) mr.enabled = false;
    15.  
    16.    }
    17.  
    18.    void OnRenderObject(){
    19.  
    20.       mat.SetPass(0);
    21.       mat.SetBuffer("_vertices", _vertices);
    22.       Graphics.DrawProcedural(MeshTopology.Triangles, _verticesCount);
    23.  
    24.    }
    25. }