- Home /
Drawing indexed vertices from compute shader
I am trying to generate triangles in a compute shader, which I would then like to render using Graphics.DrawProcedural from a C# script. The compute shader generates two buffers, one containing the vertices of the mesh, and the other contains indices for indexing into the vertex buffer.
My problem arises when I want to draw this, I can't seem to figure out a way to use the indices to draw triangles, as Graphics.DrawProcedural doesn't exactly take many parameters. The only solution I can come up with is to create vertices for every triangle and ditch the index buffer, however this can potentially create many duplicate vertices. As I want to draw rather complex meshes (marching cubes) this would probably end up being too heavy memory wise.
Anyone have a good idea on how I can solve this?
Have you figured anything out? I'm looking for a solution, too.
Answer by aeroson · Jul 12, 2014 at 03:07 PM
You may store the data as array of vertices and array of indexes. But as far as i know you can only procedurally render an unindexed triangles.
Just do regular Graphics.DrawProcedural(MeshTopology.Triangles, dataBuffer.indexes.Count/3);
And in the vertex shader do output.position.xyz = dataBuffer.vertices[dataBuffer.indexes[input.vertexid]];
Basically your vertex shader will turn the indexed triangles into unindexed.
Also this question contains nice example.
Your answer
Follow this Question
Related Questions
Generating with scripts turned off? 2 Answers
Unity Terrains, Open World and Detail 1 Answer
2D Terrain Generation and Storage of Data 2 Answers
show progress while generating worldmap in start() function 1 Answer
Procedural Generation 2 Answers