1
votes

I'm working on trying to create a cg shader that emits a quad from each vertex of a mesh. I know I'm looking at making a Geometry shader, but can't find any documentation or examples of geometry addition shaders that play well with Unity - most only modify existing vertices in the vertex subshader.

For every vertex on the mesh, I am essentially looking at creating a particle system comprised of quads created at each existing vertex on the mesh.

Thanks in advance for any guidance or resources!

1

1 Answers

0
votes

Using an old answer of mine elsewhere as a basis, you need the folowing:

  • #pragma geometry geom
  • [maxvertexcount(N)]
    void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream)
  • And some code to turn the input verticies into output verticies.

Note that the above example takes in full triangles at a time, although there are other types. Second thing to note is the N in the annotation, that is you telling the GPU how many verticies you're sending back. In my case, I was sending 12 (4 for each edge in the original triangle), in your case you can use GL_POINTS and take in a single vertex and output 4 as a quad (so N would be 4 for you). See also the MSDN article on how to declare the geom function for other inputs.