← Back to team overview

kicad-developers team mailing list archive

Advanced rendering techniques for KiCad


Hi guys,

I'd just like to write some news about the Graphics Abstraction Layer:

Currently I'm working on high quality rendering for OpenGL. The goal is to provide perfect quality with transparent layers. This isn't easy to solve, it requires a lot of special tricks. One particular problem is the merging of graphic objects for a certain layer - because we want that all graphic elements of a layer have the same color. The challenge there is that you can't simply draw objects over each other - because that creates blending artifacts when using transparent layers with a lower alpha value (it works only with opaque objects). Thus we have to make shure that pixels from overlapping objects are not drawn twice. One way is to use the Z-Buffer technique - it prevents that pixels are drawn when the last drawn pixel has the same depth for instance. This works well, but only without special antialiasing techniques. The next challenge is the high quality antialiasing; it's possible to use the build-in antialiasing of most graphic cards - but the quality looks in my opinion only good at high oversampling rates (16x) and then it requires lot of graphic card memory and it's not fast. So I've done a lot of research for other methods and found the article "Fast Prefiltered Lines" (Eric Chan, Frédo Durand, Massachusetts Institute of Technology GPU Gems, 2005 - http.developer.nvidia.com) - this was a good inspiration. The trick is to redraw only the smoothed edges. I've decided to improve this method and extended it for subpixel anti-aliasing (compare http://en.wikipedia.org/wiki/Subpixel_rendering). This means I compute inside the fragment shader the color of an edge pixel from the distance of the edge. This way we get much crisper edges than possible with normal anti-aliasing. Then we have the problem to merge the smoothed edges correctly. After a lot of trial and error I've finally found a 2-pass-method that works well:

(1) We draw the complete layer in the Z-Buffer only and fill the stencil buffer with a '0', the smoothed edges get a lower Z-Axis distance. (2) The layer is drawn again with colors enabled, depth test and stencil test enabled. If the stencil test for a particular pixel is passed, the stencil buffer value is incremented. This way we prevent to overdraw a pixel twice for the actual layer.

I've attached a few screenshots of an example with circles and two layers:
Circles_simple.png: screenshot without these tricks. You can see that there are blending artifacts and the rough edges. Circles_merged_subpixelAA.png: correctly merged layer objects and subpixel anti-aliasing. Circles_merged_subpixelAA_zoom.png: zoomed image of the anti-aliasing. Note that the circle edge colors of an circle are different - this means the subpixel-AA works.


Now the GAL features a loader class for vertex/fragment/geometry shaders and support for Bézier curves. Before I'll upload I have to clean up the code a lot, that I don't break to much - I think I'll do that in the next weeks.


We will get with this features something that no other EDA-program has currently, it will be a great benefit for KiCad in my opinion.

Bye ..

Attachment: Circles_merged_subpixelAA.png
Description: PNG image

Attachment: Circles_merged_subpixelAA_zoom.png
Description: PNG image

Attachment: Circles_simple.png
Description: PNG image

Follow ups