Is true/commutative alpha blending possible?

A place to discuss the science of computers and programs, from algorithms to computability.

Formal proofs preferred.

Moderators: phlip, Moderators General, Prelates

User avatar
MHD
Posts: 630
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Is true/commutative alpha blending possible?

Postby MHD » Tue Jun 21, 2011 8:33 pm UTC

I have often wondered if truly commutative alpha blending is possible.

That is an alpha blending algorithm that for three or more colours blended together always gives the same colour regardless of the ordering it is applied in?

Mathematically:
Given a set of colours [imath]C_n = \{ R_n, G_n, B_n, A_n \in [0;1] \}[/imath] is there then a blending operator [imath]\oplus[/imath] which when reduced over [imath]C[/imath] with the base colour [imath]\{0, 0, 0, 0\}[/imath] yeilds the same result no matter the ordering of [imath]C[/imath]?
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"

User avatar
undecim
Posts: 289
Joined: Tue Jan 19, 2010 7:09 pm UTC
Contact:

Re: Is true/commutative alpha blending possible?

Postby undecim » Tue Jun 21, 2011 9:19 pm UTC

Perhaps this is a bit naive, but...

1) Discard all Cn where An=0
2) Multiply each Rn, Gn, Bn by An
3) Take the average of R, G, B
4) Divide by the average Alpha
5) Average alpha is the final alpha
Last edited by undecim on Tue Jun 21, 2011 9:53 pm UTC, edited 1 time in total.
Blue, blue, blue

User avatar
WarDaft
Posts: 1583
Joined: Thu Jul 30, 2009 3:16 pm UTC

Re: Is true/commutative alpha blending possible?

Postby WarDaft » Tue Jun 21, 2011 9:34 pm UTC

Uh, shouldn't alpha blending not be commutative? If the top layer is 90% opaque, it should dominate the bottom layers, no matter their opacity. A commutative version should probably be called something else.
All Shadow priest spells that deal Fire damage now appear green.
Big freaky cereal boxes of death.

User avatar
benneh
Posts: 74
Joined: Tue Aug 26, 2008 8:24 am UTC

Re: Is true/commutative alpha blending possible?

Postby benneh » Tue Jun 21, 2011 9:52 pm UTC

Do you mean associative?

User avatar
undecim
Posts: 289
Joined: Tue Jan 19, 2010 7:09 pm UTC
Contact:

Re: Is true/commutative alpha blending possible?

Postby undecim » Tue Jun 21, 2011 9:56 pm UTC

WarDaft wrote:Uh, shouldn't alpha blending not be commutative? If the top layer is 90% opaque, it should dominate the bottom layers, no matter their opacity. A commutative version should probably be called something else.

Obviously that is the case

Technically, there are infinitely many solutions to OP's question, but he's looking for one that "makes sense" as a blending function. A [imath]\oplus[/imath] B = {0,0,0,0} would satisfy his condition, but doesn't make sense.
Blue, blue, blue

User avatar
MHD
Posts: 630
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Re: Is true/commutative alpha blending possible?

Postby MHD » Wed Jun 22, 2011 2:19 pm UTC

It's more for an Image manipulation program, really. I know that it's stupid with 3d graphics, I just wanted to know if it was possible.
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"

kmatzen
Posts: 214
Joined: Thu Nov 15, 2007 2:55 pm UTC
Location: Ithaca, NY

Re: Is true/commutative alpha blending possible?

Postby kmatzen » Wed Jun 22, 2011 5:01 pm UTC

So, do you still care about blending colors in any order in practice? I mean, I do this in OpenGL for GPU splatting. As far as I know, it's not really a blending function as you've described, but it's a pretty common technique in point-based 3D graphics. I first render everything with

Code: Select all

glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE);

and then I do a normalization pass where I divide by the alpha channel.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Is true/commutative alpha blending possible?

Postby Yakk » Fri Jun 24, 2011 6:46 pm UTC

An easy solution is to treat alpha as weight rather than transparency.

Note that either requires unbounded alpha, or fails when the sum of alphas pass max.

Pre-multiplied RGB works better, as then mixing is a matter of adding (so long as the sum of alphas doesn't break unity, natch).
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
WarDaft
Posts: 1583
Joined: Thu Jul 30, 2009 3:16 pm UTC

Re: Is true/commutative alpha blending possible?

Postby WarDaft » Sat Jun 25, 2011 11:49 pm UTC

Or base it on reciprocals.

That is, C1(R1,G1,B1,A1) + C2(R2,G2,B,2,A2) = C3([R1/(1-A1)+R2/(1-A2)]/[1/(1-A1)+1/(1-A2)],...,1/[1/(1-A1)+1/(1-A2)]), obviously there are some pre-computing options for optimizing. Any order of application will give the correct result.

But that's certainly not true alpha blending.
All Shadow priest spells that deal Fire damage now appear green.
Big freaky cereal boxes of death.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Is true/commutative alpha blending possible?

Postby Yakk » Mon Jun 27, 2011 1:05 am UTC

It depends what alpha means. Does it mean coverage? Or transparency? When you blend, are you putting one on top of the other? Are you mixing some kind of pigment? Or are you mixing light? Is so, what are the physical properties of the pigment? Is it back-lit, or reflective?

The concept of transparency -- being able to see through something -- and key -- something being there or not, or partly -- get mixed up. Pigment and color get mixed up. There are lots of issues that naive alpha blending doesn't reflect.

If you do pigment-based mixing where alpha is the "density" of the paint, and the colours are the components, the density of the result will be the average of the two alphas, not the A1(1-A2)+A2 value that we know and love, as an example.

I could imagine a physical process that adding all 4 channels would emulate reasonably well, or at least it isn't a stretch. Naturally the meaning of the channels wouldn't be "ignore alpha, and display RGB to the screen" for a close emulation of "what you see" (or "scale by alpha, then display RGB to the screen"), but the ability to do that is a quirk of hardware.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
MHD
Posts: 630
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Re: Is true/commutative alpha blending possible?

Postby MHD » Mon Jun 27, 2011 1:17 am UTC

How about using HSV or HSL or HCL?
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Is true/commutative alpha blending possible?

Postby Yakk » Mon Jun 27, 2011 12:43 pm UTC

Those are different colour spaces, but they don't speak to what the alpha channel means.

Traditional alpha blending (ie, C3 = (C1 * A1 * (1-A2) + C2 * A2 )/ A3, A3 = A1 * (1-A2) + A2) is alpha-as-uniform-coverage, color-as-photon-count.

In this case, any commutative alpha blending would be an incorrect algorithm: 100% coverage red in front of 50% blue looks different than 50% blue in front of 100% red. (The first case is pure red, because 100% coverage means you can't see anything behind it).

For the blending to commute, you'd have to change what "alpha blending" means, or what it is emulating. As noted, one option is to treat alpha-as-pigment-density and colour-as-pigment-response. In that case, taking 100% red and mixing it with 50% blue should do the same as the opposite, and mixing the result of a mix with another also does the same thing. Note, however, that the result of mixing 3+ colours rapidly becomes mud (which emulates what happens in real life when you mix together a lot of different pigments). Also note that using RGB for pigments is a hack.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.


Return to “Computer Science”

Who is online

Users browsing this forum: No registered users and 15 guests