Line width and style in Direct3D10/11

Started by
3 comments, last by dave 8 years, 2 months ago
My problem is how to render lines with different width and styles, or what's the D3D equivalent to glLineWidth and glLineStipple. I've searched the web and found D3DXLine class serves my need well. However, D3DX is no longer available in Windows 8 SDK (http://msdn.microsoft.com/en-us/library/windows/desktop/ee663275.aspx) and so it makes no sense to use it in my application. Could some please suggest a method to do this? Thanks.
Advertisement
There is no way to adjust line width, the API only provides rendering of 1-pixel-wide lines. If you want something else you'll have to roll your own solution. One possible approach might be to use a sprite renderer to draw your lines.

There is no way to adjust line width, the API only provides rendering of 1-pixel-wide lines. If you want something else you'll have to roll your own solution. One possible approach might be to use a sprite renderer to draw your lines.

Thank you for your quick response MJP. It's hard to believe there is no line width/style support in the latest D3D, whereas the same feature was available in OpenGL 1.0. I take a look at DirectXTK and find no direct reference on line rendering. I'll read the DirectXTK documentation later. Anyway, is there any other approach to line width/style rendering. Someone suggest to use geometry shader but does not offer the code sample.
In general D3D11 doesn't expose features that aren't supported by the hardware, which is surely why there is no option for line width. I'm no OpenGL expert, but a quick search seems to indicate that line widths > 1.0 aren't supported in the core profile since version 3.2.

One way to generalize lines on GPU's is by rendering quads with width and height determined based on the thickness and length of the line you want to render. A sprite renderer will essentially render and batch quads, which is why I suggested using one and linked you to DirectXTK. A sprite renderer will also let you apply a texture, which can let you approximate antialiasing as well as different line styles. Another possible quad-based approach is to render a quad that covers the the screen-space area covered by a line, and then use a pixel shader to analytically determine coverage and rasterize the line. This article explains how to do this.

A geometry shader is generally used for expansion from one primitive to multiple primitives. An example would be taking a single point/vertex as input, and emitting a quad as an output. This is done frequently for particle systems, and could also be used in a sprite or line renderer to expand points to quads. You could also take a line primitive and emit a quad as a means implementing line thickness.

You could do this on a quad: https://www.shadertoy.com/view/4dV3Wt

This topic is closed to new replies.

Advertisement