1
\$\begingroup\$

What is the best way to put a dot on a vertex?

I have a model (a plane for example) consisting of a few thousand vertices. I want to draw a red dot at every vertex's 3D position, just like 3ds Max's vertex selection mode, for example).

I've tried drawing a small line on each vertex location which works fine with few vertices, but it causes performance problems when I have large objects with many vertices. I've also tried doing this with a shader, but I can't get this to work (I want to highlight the selected vertices). I've thought about drawing a small 3D cube at every vertex location, but this seems terribly inefficient.

How can I accomplish this in a way that will scale to large scenes?

\$\endgroup\$
  • \$\begingroup\$ Which version of DirectX? \$\endgroup\$ – Andrew Russell Jan 3 '14 at 9:09
  • \$\begingroup\$ I think I'm using directx 9 \$\endgroup\$ – Thomas Jan 3 '14 at 9:10
  • 2
    \$\begingroup\$ Rendering the vertices as points does not do the trick? \$\endgroup\$ – dsilva.vinicius Jan 3 '14 at 11:53
  • \$\begingroup\$ This works like a charm, didn't think of something this simple thanks \$\endgroup\$ – Thomas Jan 3 '14 at 14:36
  • \$\begingroup\$ @dsilva.vinicius Add it as an answer, please. If he doesn't do it, Thomas you can answer your own question too :) \$\endgroup\$ – Gustavo Maciel Jan 3 '14 at 15:29
1
\$\begingroup\$

As stated in the comments, this effect can be achieved by rendering the desired vertices as Points. In DirectX, this can be accomplished using this function:

public void Device.DrawPrimitives(
    PrimitiveType.PointList,
    int startVertex,
    int primitiveCount
);

As a prerequisite, you must have a Device with a bound VertexBuffer. You can see how to setup the Device, create a VertexBuffer, set it as a stream and bind it to the Device in this Drunken Hyena's tutorial.

\$\endgroup\$
  • \$\begingroup\$ I've implemented this using a basic shader with a single vertex and pixel shader pass. Works like a charm. \$\endgroup\$ – Thomas Jan 3 '14 at 20:27
2
\$\begingroup\$

If you need to draw larger dots, or drawing your geometry as points is undesirable for some other reason, there are multiple ways you could go about it.

Drawing a shape at each vertex position might seem inefficient, though if you use instancing it shouldn't really be that bad - you might even be able to use your vertex buffer as the instance buffer directly by using the right stride and offset values. This would also allow you to draw whatever shape you want.

You could also try to get clever with shaders to get the dots at the same time as you are drawing your object. For example by storing the screen-space positions of all three vertices belonging to a triangle in each vertex of that triangle, you could use them in the pixel shader to determine the current fragment's distance to those vertices, and when appropriate draw a dot instead of the regular shading you'd apply.

In DX10 or 11 this could be done easily with a geometry shader without modifying your actual vertex buffer's layout, without that it gets a little trickier.

While this approach is relatively cheap and lets you draw dots of any size you want, the drawn dots won't extend beyond the silhouette of the object, which becomes more apparent the larger the dot size:

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.