Logical Alpha

One of the GraphicsPatterns, useful in conjunction with DeferredUpdate to AvoidDrawing.

Typically, alpha channels are calculated pixel-by-pixel as each primitive is drawn. If hardware accelerated, this has no real performance penalty. If you have to do this in software for whatever reason however, things can slow down to a crawl.

As stated elsewhere, if you can do some math in advance of the actual drawing, you can avoid redundant operations, and generally speed things up.

Keep a record of each drawing operation performed. Then, for each new operation, check it against previous operations. If there is an intersection, split the new operation into a series of operations representing the intersections with the various previous operations. For each section, calculate the appropriate colour for that screen section, and record it as a separate operation.

Worst case performance is no worse than the pixel method (drawing an image would likely require at most an operation for each pixel), average case is at least as good as O(n log n), given an algorithm to determine intersections in O(log n) (which might be improvable, if one can implement it as a hash rather than a tree lookup), and the best case is a simple on/off-alpha drawing in the same time as a simple rendering O(linear).

-- WilliamUnderwood


Also see GraphicsPatterns, DeferredUpdate

CategoryGraphicsPattern CategoryPattern


EditText of this page (last edited September 3, 2007) or FindPage with title or text search