We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › layering art with transparency never gets opaque
Page Index Toggle Pages: 1
layering art with transparency never gets opaque (Read 2525 times)
layering art with transparency never gets opaque
Jun 18th, 2010, 1:04am
 
layering art with transparency never gets opaque

In the samples of the following section regarding Vector math the trail of circles is never fully obscured by the partially-transparent rectangle that is continually draw with each call to the draw method:

processing.org/learning/pvector/

Each draw call begins with a 3.9% (10 on a scale of 0-255) opaque white rectangle being drawn over the last state of the display:
fill(255,10);

This effectively makes the display look like it fades into the background color over time. I would expect the overlay rectangles to continue stacking up until the alpha accumulates and art (circles) that are old-enough become completely obscured by white pixels, effectively looking like the circles have faded away. However, there seems to be some limit to how much the white overlay content can obscure the freshly drawn art. Adjusting the fill method's opacity parameter to around 100 causes the trail to fade away completely.

I've come up with a few theories but they all have holes (a limit to the number of stacked semi-transparent art, non-even division into 255 preventing the last *step* to full opacity to happen, rounding error, error in the way Processing handles alpha layering with many layers, etc.).

Does anyone have ideas about what prevents the semi-transparent art overlays from eventually reaching full opacity and fully obscuring the *older* parts of the background (the areas without recently-drawn circles)?
Re: layering art with transparency never gets opaque
Reply #1 - Jun 18th, 2010, 6:33am
 
artofcode wrote on Jun 18th, 2010, 1:04am:
non-even division into 255 preventing the last *step* to full opacity to happen

This would have been my first guess.  I don't know exactly how Processing handles this, but repeatedly layering an image with an alpha value of 10 out of 255 could "max out" around an alpha of 230 or so.
Re: layering art with transparency never gets opaque
Reply #2 - Jun 18th, 2010, 7:07am
 
yes to what smitty said.  alpha-blending just doesn't work that way, it *never* fully accumulates, because it's always adding a "portion of the difference", and as the difference gets smaller, so does the portion.  a process of diminishing gains, sooner or later you hit a wall (exactly *where* that wall is depends on your alpha value, but it's still there, somewhere)

google for "zeno's second paradox", it's an apt analogy.

smitty's stuck-at value of 230 is right for your case too.  why?  let's say you have a current pixel value of 230 in your image, trying to blend it towards 255 (white) at alpha 10 (3.9%).  the difference is 25, and what is 3.9% of 25?  0.975, less than one, so after addition it will truncate back to 230.  so you could do that a bazillion times and you'd never reach 255, you're stuck.  (in practice you'll possibly hit the limit a bit earlier than 230, due to other similar problems with integer math in the alpha blending code)

hth
Page Index Toggle Pages: 1