Render vertices as point with geometry shader (DirectX 11).

I’m attempting to asses what is the most efficient manner to render vertexes as points in Unity/DirectX 11.

I’m want to create a point-cloud instancing shader, that creates vertices in the Geometry Shader. The vertex coordinates will be loaded from a texture file. Each vertex should be rendered as a point, though I’m looking for a alternative, where I don’t need to generate a triangle fragment for each point to be rendered. The points only need to be a single colour, so point-sprites are not necessary. However, setting the size of points relative to z-depth would be an nice additional feature.

I’m not experienced with DirectX shader programming, and I can’t find a good example of who to use the DirectX API internal to Unity. i.e. I found the commands D3D11_PRIMITIVE_TOPOLOGY_POINTLIST and IASetPrimitiveTopology(), which seems to be what I’m searching for, however I’m lost in how implemented these commands.

One alternative is to use a compute shader and compute buffer for vertex data, and then some Graphics.DrawProcedural MeshTopology.Points stuff to get the rendering started in an appropriate manner. Suspect the MeshTopology.Points stuff is what you are after, and which way to use it in Unity depends on where your vertex data lives, a decision that in turn may be influenced by how compute shaders compare in performance terms to geometry shaders.

I found a very simple Unity particle system on github that demonstrates these parts in action together (compute shader and buffer, not geometry shader):

Point size using this technique is something I’m only just researching right now, actually the reason I stumbled on your post while searching. Not got far yet, but for example see this old thread for an example of point size being changed, that shows up a problem with texture coordinates and no solution on that particular thread: Unity4 point sprite texture coordinates - Unity Engine - Unity Discussions

1 Like

Also see scrawks excellent blog for numerous useful posts if you decide to explore the compute shader stuff.

http://scrawkblog.com/

For example the one about compute buffers will probably strongly resemble what is happening in the code of the particle system I posted a link to previously.

http://scrawkblog.com/2014/07/02/directcompute-tutorial-for-unity-buffers/

The other alternative is that I suspect you could do a geometry shader that outputs points, but it would be more expensive than just point rendering from buffers. You wouldn’t do all the integrated stuff, but rather just an HLSL shader that has a GS component that takes in triangle topology and outputs points.

I’ve not done that way, though I’m doing the reverse (points => triangles) from buffers.

The Geometry Shader I started with as an example to learn from is here => Billboard Geometry Shader - Community Showcases - Unity Discussions

So, that should give you an idea of where to start! (I also highly recommend going through scrawk’s blog, it’s tremendously useful, well written, and perfect for someone with programming experience trying to learn DX11 material to use with Unity).