Re:How to draw ugly lines fast
by IshKebab on Tuesday December 20, 2022 @04:25AM
(#34063586)
It would help if he defined what "subpixel accurate" means. I can't figure out why you'd care about subpixels if you're producing a bitmap image? Or is he doing something like cleartype but not antialiased?
[ Parent
| on HN ]
The standard bressenham algorithm expects the start and end point of the line segment to be perfectly centered inside the grid. The modified version lets you put the start and end points anywhere.
For example, the standard algorithm would always generate lines that are symmetrical:
####
####
But the modified version lets you position the endpoints different, so that you'd get: ###
#####
or ##
######
etcThe endpoints of the lines have subpixel resolution, so although you’re only drawing whole pixels, the choice of which pixels to draw along the line will change based on the subpixel positions of the endpoints.
He's not doing anything like ClearType, but for smooth animation you'd still want your end points to have more than single-pixel accuracy.
It becomes important with low resolution framebuffers and once things start to move. Triangle outlines in early 3D games tended to wobble and jitter because the 'math' didn't work at subpixel precision (many PS1 3d games suffered from this).
With subpixel precision (e.g. you do all the math at a higher precision than the framebuffer resolution, and preserve the fractional part of pixel coordinates in all computations until you actually write to the framebuffer), the outlines remain stable even for small movements. IIRC Quake (with the software renderer) was one of the first games which paid proper attention to subpixel accuracy, and they showed this off with a very slight camera movement at the result screen after a multiplayer match. Triangle edges were properly 'crawling' instead of being all jittery.
Also the death screen in single-player, and I remember being impressed by the effect.
I was confused about this too. What he means is fractionally accurate endpoints of the lines. So it's just about line endings coordinates not being exact integers.
And the reason why fractionally accurate endpoints matter is that they affect what exact pixels get drawn, which in turn makes animation look much smoother. Eg. a line that "crawls" from 0 to 6 as the endpoints move fractionally upward looks much less jittery than a line that's always 3.
0 #
#######
##
######
###
#####
3 ####
####
#####
###
######
##
6 #######
#