I have a number of RGBA pixels, each of them has an alpha component.
So I have a list of pixels: (p0 p1 p2 p3 p4 … pn) where p_0_ is the front pixel and p_n_ is the farthest (at the back).
The last (or any) pixel is not necessary opaque, so the resulting blended pixel can be somehow transparent also. I’m blending from the beginning of the list to the end, not vice-versa (yes, it is raytracing). So if the result at any moment becomes opaque enough I can stop with correct enough result. I’ll apply the blending algorithm in this way: ((((p0 @ p1) @ p2) @ p3) … )
Can anyone suggest me a correct blending formula not only for R, G and B, but for A component also?
UPD: I wonder how is it possible that for determined process of blending colors we can have many formulas? Is it some kind of aproximation? This looks crazy, as for me: formulas are not so different that we really gain efficiency or optimization. Can anyone clarify this?
Alpha-blending is one of those topics that has more depth than you might think. It depends on what the alpha value means in your system, and if you guess wrong, then you’ll end up with results that look kind of okay, but that display weird artifacts.
Check out Porter and Duff’s classic paper ‘Compositing Digital Images‘ for a great, readable discussion and all the formulas. You probably want the ‘over’ operator.
It sounds like you’re doing something closer to volume rendering. For a formula and references, see the Graphics FAQ, question 5.16 ‘How do I perform volume rendering?’.