Drawing Lines is Hard (2015)
mattdesl.svbtle.com
mattdesl.svbtle.com
One thing I didn't see mentioned here is the line drawing API calls are typically not as well optimized as the triangle mesh calls, or so I've heard. Part of the reason good line drawing support was more expensive was (allegedly) only a few customers truly need antialiased lines with performance as good as the mesh API, and it's extra silicon, lines have specific needs not shared with meshes.
FWIW, I've tried all these approaches in production and ended up just doing the meshing myself, and avoiding shader tricks. It's not that bad, it gives the most control, and once you have an abstraction for it, you don't need to think about it again.
Cool writeup! It's amazing what lina can do.
"How to draw a straight line"
https://synthetica.eng.uci.edu/mechanicaldesign101/Kempe-Str...
Fun fact, Bosch's Axial Glide miter saw uses a Sarrus linkage rather than slides to generate it's straight line motion. I thought it was kind of a neat application for the oldest straight line linkage, especially since it didn't get much traction when it was first invented. It turns out for most application, a planar linkage is preferable.
[0] https://www.amazon.com/How-Round-Your-Circle-Engineering/dp/...
https://hbfs.wordpress.com/2009/07/28/faster-than-bresenhams...
Furthermore, fixed-point also allows antialiasing since it always gives how close the line is to the pixel being drawn.
In fact, I've always thought that was what Bresenham was.
> The situation is similar on the 64 bits machine, but the advantage of fixed point vanishes. Both methods takes very similar times: fixed point averages at 0.85 µs and Bresenham 0.84 µs, a difference of about 1%. However, the naïve implementation is still very far behind, at 2.96 µs.
When you said "easily beaten" I kind of expected more than just a 1-5% performance improvement.
There is also another (potential) problem with fixed point: it works by adding up rounded numbers:
> The only thing we need, is to compute the slope m as a fixed point number rather than a floating point number.
As a result, the fixed point might create rendering artefacts from adding up a rounded number repeatedly. This makes the whole thing an apples-to-oranges comparison:
- floating point method that does multiply/divide every iteration
- fixed point that adds a rounded fraction
- Bresenham that does unrounded fraction adding by splitting the fraction into an accumulator and divisor (Bresenham is actually really simple primary school math with some geometry on top)
To make a truly fair comparison, we should add a version that precomputes the floating point fraction, and adds that each iteration; I suspect the main slowdown of the naive floating point algorithm is the repeated multiply/divides more than the cast to integer, not the casts.
You'd be surprised. Last time I tried it, casting a floating point number to an integer was many times slower than floating point multiply.
Not sure the performance implications, but I use this frequently if MSAA is not natively supported.
It is a less refined version of the techniques in the article, the approach is different in that it uses post-processing to provide the line thickness.
At least i think, as there is no hard spec on X11.