|
From: Maxim S. <mcs...@ya...> - 2005-11-10 04:58:12
|
> Hi, I'm using the lightweight rasterizer component of AGG, and I'm > experiencing "gaps" between shapes. Below are a couple pictures that > illustrate what I mean. > > First, you can see the gaps easily here: > http://www.ottoproject.com/agg_rasterizer_gaps/solid_black.jpg > > This second picture shows how the crosses are made - a central square > surrounded by four rectangles: > http://www.ottoproject.com/agg_rasterizer_gaps/false_colors.jpg > > Of course, the solution for a shape like this cross would be to make it > one single shape, instead of multiple shapes lined up. However, my > concern is not this cross shape specifically, but the general case of > two polygons that share an edge. Is there any way to prevent such gaps > from appearing between them? It's not that easy to achieve the flawless stitching with the used method of anti-aliasing. The problem is that if you blend a pixel with opacity=0.5 over another one with opacity=0.5 too, you will have the resulting opacity=0.75. It works as if you paint over a glass with translucent ink; theoretically you will never achieve full opacity. You will have the very same problem is Adobe SVG viewer, for example. The rectangles you draw "don't know" anything about each other (you draw them separately, right?), so that, we can only rely on the blending formula. You can achieve the flawless result if you use comp_op_plus instead of alpha-blend, like this: http://www.antigrain.com/stuff/gouraud_stitching.zip But you will need to use a separate RGBA buffer, initially set to zero (all channels). Then you draw into it and finally alpha-blend the whole buffer to the parent (main) one. And the shapes you draw into this intermediate buffer must not overlap! That's the principal restriction. I'm working on another rasterization algorithm (actually, pretty similar to the existing one) that supports the Flash data model. There you don't have closed contours, but just a set of edges with attributes: left-fill and right-fill. -1 means "no fill". So that, you can render a multicolor scene in one pass, with perfect stitching. http://www.antigrain.com/stuff/gouraud_mesh.zip The main point is that you don't have tro use a separate frame buffer; instead there's only one scanline is used internally. But the price is that your initial data must be prepared in a Flash-like way (no overlaps and no self-intersections). I just tried to check if the Flash rasterization algorithm can be used for the traditional triangle rendering. It perfectly handles it! The main point is the whole mesh is rasterized in one pass; and the rasterizer calculates the blending coefficients for each pixel in the scanline. Each scanline consists of a number of spans associated with the attribute (style). The style is not obligatory a solid color, it can be an image, Gouraud/Phong shader, or any pixel shader in general. The spans can overlap with the respective blending coefficients; and it's how anti-aliasing works here. Say, if a pixel is covered by two adjacent triangles (0.5/0.5), the shader function is called twice, and then the resulting color values are just summed up. In general, it's called as many times as many triangles cover the pixel. This method produces perfect stitching with perfect, 256-level anti-aliasing. McSeem __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com |