Metal 3D Line Width

How do you rasterize a wide 3D line in Metal?

OpenGL has glPointSize and glLineWidth.

MTLPrimitiveTypePoint has point_size.

MTLPrimitiveTypeLine has nothing.

I was looking today for this too and after having some chats in Twitter I got informed that wide lines are not yet supported 😟

Maybe in the next version.

I'm afraid you'll have to triangulate your lines if you want them to have a non-default width. AFIK, this is also closer to how hardware operates (for many implementations, specifying custom line style means that the driver had to convert them to polygons internally. This would be much easier if we had geometry shaders though, but it might be possible to do the extrusion in a compute shaders. Didn't really look into it yet. Anyway, doing lines as polygons allows you to have consistent apperiance across platforms and also to implement smooth lines. There are a lot of ressources on this topic, google e.g. for "OpenGL line tesselation"

Yeah, it is a pity that we don't have geometry shaders. Thanks, for all the info, though!


I am researching a bit about the line smothing business and I found some cool blogposts.

The trouble is even worse when you draw in 3D. A rectangle (instead of a line) could even look as a flat invisible short line if the camera is almost aligned to the line and a little farther than the end point of the rectangle. We should draw a tiny cylinder to solve the trouble, which means so many triangles. Think about a simple grid 20 x 20 lines with 32 triangles each. That is 12800 triangles. Also, the point is a squared rectangle only. If you need of a circle you have to draw it.

Metal 3D Line Width
 
 
Q