[Y-devel] anti-aliasing?

Mikko Rantalainen mira at cc.jyu.fi
Fri Mar 5 22:41:51 GMT 2004


Aaron <drizzt321 at phpfreaks.com> wrote:
> 
> Do we want to have anti-aliasing available to be turned on? I have 
> finished my ellipse, and I'm looking at starting in on doing some AA on 
> it to help smooth it out, however I was wondering if perhaps I should 
> implement some general AA on the other primatives. perhaps work out a 
> general function(somewhat in the future), or do we just want to have 
> each shape do its own AA as necessary? I don't really have any 
> experience in AA, but it seems like I've almost volunteered myself to 
> handle putting in some of this primatives stuff into at least 
> rgbaBuffer. any thoughts? comments? suggestions? opinions? please, I 
> would like to hear them all.

I think the AA should be on by default and optionally provide a way 
to turn it off. I really don't see a reason to turn it off, unless 
your display quality is too bad to display the computed colors (a 
true black and white instead of monochrome display, for example).

As for the initial implementation: if I were to do it, I'd write a 
function to render a filled white triangle on a black background 
with toggleable anti-aliasing (8 bit or more) for each side. As 
every shape can be rendered with triangles (approximate the shape 
with a polygon that has enough corners so that errors are hidden in 
the pixel structure, then tessalate that polygon into triangles) you 
can render the actual shape so that the border line gets 
anti-aliased and all internal triangle borders are hidden. Once you 
have black and white representation of the shape, just use that as 
an alpha channel and fill all the other channels with the color the 
polygon should be rendered with (you can draw filled rectangles on 
the all other channels, because the alpha channel will take care of 
masking). [1]

You could also expose the black and white rendering to let the 
application to further modify the alpha mask before combining that 
with a color channel.

After that part is done, I'd do some basic primitives and *then* 
look if some of those need specialized rendering functions to be 
fast enough. I wouldn't expect that being the case.

You should be able to find complete implementations for anti-aliased 
polygon (or at least line) renderers from the net with suitable 
licenses. Just make sure the inner loop[2] of the polygon filler 
runs with high performance if you go with full CPU renderer. Try to 
look for "affine texture mapping" if you want simple(?), rotated, 
scaled and textured polygon 2D-rendering algorithm. [3]


[1] I think shapes should be objects and a simple optimization for 
this would be to save the color separate from color channels and 
just save the alpha channel. No need to set or copy the color 
channels if you already know that every single pixel will contain 
the same color.

[2] Most algorithms fill the polygon with horizontal lines because 
that matches the order of bytes in the memory and the algorithm 
makes effective use of CPU cache. memset() should do fine as the 
inner loop for a single colored polygons. Just compute the end 
points according to the anti-aliasing.

[3] For example:
https://www.exaflop.org/docs/fatmap/ind.html#Subpixel%20accuracy
It might be good to implement subpixel accuracy for the renderer so 
that bezier limited ares can be nicely rendered. Otherwise, it's a 
bit old document.
For some more complex algoritms, try this:
https://www.geocities.com/SiliconValley/2151/tmap.html
That document isn't fresh either. I guess it's because everybody is 
using hardware renderers today.

-- 
Mikko




More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved