Draw thick lines

Started by
5 comments, last by Tommato 3 years, 3 months ago

Hi All

With core profile 3.3 the line thickness is limited from 0.125 to 1.0 (on my card), but I need more. Can you please suggest a good shader(s) to draw regular lines with arbitrary thickness ?

Thx

Advertisement

Typically thick lines are accomplished by drawing quads instead. For simple cases this is easy: just take the tangent to the line, and use the tangent to offset the quad vertices sideways from the line endpoints.

Unfortunately things can get a bit complicated based on requirements, however. Antialiasing for quads is different it is than for lines, and especially for thin lines - you likely want to use actual lines for thicknesses below a few pixels, and only use quads for thicknesses above that. And depending on how you want to join sequential line segments, the mitering the joint can be more or less complicated.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

swiftcoder said:
Typically thick lines are accomplished by drawing quads instead.

Thx for the reply. Understand, I've already started this. My interest was more mercantile - just to use a ready shader ;-) It's normal, 3.3 is > 10 years old, another one “reinvented wheel” is unneeded. But after googling - nothing essential found.

One detail, how to “extrapolate” UVs for the new triangles pair? Any idea?

Thx

Tommato said:
But after googling - nothing essential found

This stackoverflow post is probably about as close as you'll get to a standard. Lots of copy/pasted versions of that around the internet ?

Tommato said:
One detail, how to “extrapolate” UVs for the new triangles pair? Any idea?

Simplest approach is just to keep the U direction from the original line, and then the V coordinate goes from 0..1 widthways across the extruded the quad

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

For antialiased thick lines have a look at http://jcgt.org/published/0002/02/08/​ , it's not quite ready to use, but source code is included with the paper.

Eternal said:
or antialiased thick lines have a look at http://jcgt.org/published/0002/02/08/​ , it's not quite ready to use, but source code is included with the paper.

Thx for the info

Another detail: before drawing lines I should check their intersection with frustum. It's not a “prob” nor “complex” but a piece of code in shader and in app. Is there a way/secret to avoid it?

Thx

This topic is closed to new replies.

Advertisement