4
\$\begingroup\$

I am trying to draw the 2D graphics (like line, polyline, polygon etc.) using Direct3D for drawing I am using LINE_LIST. Now I want to make the lines thicker and apply patterns to the line as described here.

I am able to draw the thick lines using a geometry shader to draw a quad but to apply patterns I need to write a pixel shader that will do all the stylization of line that is which fragment should be drawn and which fragment of line should be left behind.

I would really appreciate if, anybody could help in writing the pixel shader or provide me any reference to write it.

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

You may be interested in this paper on hardware-determined feature edges. In particular, the paper discusses techniques for texture parameterization of feature edges, which can be used to apply dotted/dashed stipple pattern textures to your lines.

It is probably possible to do this without that kind of texture parameterization (but still using texture coordinates to transport information about a particular fragment's position along the line segment in the pixel shader) and division to decide which bucket of size N the current fragment falls in to, and if that is an even bucket you color the fragment otherwise make it transparent.

You'd have to use the rate of change of the texture coordinates to determine whether the line's slope was such that the line was longer than it is taller (or the other way around) and use that to determine which axis to quantize into the buckets).

\$\endgroup\$
1
\$\begingroup\$

You could apply a texture containing a dash pattern to the line; when you convert it to a quad in the geometry shader, generate UVs too, proportional to the length of the line so that the dashes are a constant length. Then just use a regular texture-mapping pixel shader, with an alpha test or similar to discard the unwanted pixels.

If you're targeting hardware that has DX11 tessellation capabilities, you might also be able to use tessellation to subdivide the line and generate individual quads for each dash or dot. That would be more complex but might be useful in some circumstances. (Actually, you can do some tessellation in the geometry shader as well, though you're limited in the number of segments you can output for each input segment, and it's not as efficient as tessellation.)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .