# Painter algorithm on transparant objects

Why do you have to use the painter's algorithm when drawing transparant objects ? Can't you just use a z-buffer, draw all non transparant/opaque objects, then draw all transparant/opaque objects last?

Sorry if it is a stupid question, but i guess it's something all beginners run in to.

-
What if you want to draw a transparent object in front of one opaque object, and behind an other opaque object? – John McDonald Jun 11 '13 at 17:05
Good point, but that only meens that you have to sort the opaque/transparant objects. – Fredrik Boston Westman Jun 11 '13 at 17:14

You can ignore ordering but only with additive blending (common in many particle systems).

With "normal" multiplicative blending, ordering is important. The color buffer accumulates colors. New translucency effects are blended using a source alpha and the inverse of that source alpha. That is, given current color `A` and source color `B` with source alpha `C`, the final color `D` is found using `D=A*(1-C)+B*C`.

If you're looking at a single component, say the color buffer has value 100, trying to blend in value 50 at 10% then value 100 at 30%. You get `100*.9 + 50*.1 = 95`, then you get `95*.7+100*.3 = 96.5`.

Swap the order of the blends. Now you get `100*.7 + 100*.3 = 100`, then `100*.9 + 50*.1 = 95`.

Two different final color values based on the order they're applied in. Hence, order is important if you are aiming for the "standard" blending equation which "looks right."

-
ok i see. But as mentioned in a comment above, would it work if you only sorted the transparant/opauqe objects(and draw them last) ? If i understand it correctly they are the only one causing a problem – Fredrik Boston Westman Jun 11 '13 at 17:59
No, look at that math again. Had nothing to do with opaque objects. – Sean Middleditch Jun 11 '13 at 18:02
oh sorry , miss read your anwser, my bad – Fredrik Boston Westman Jun 11 '13 at 18:05
Man you worded that in such a confusing way, you could have easily just said A mixed with half B, mixed with half C, gives only one quarter B. – MickLH Sep 23 '13 at 13:08