Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Let C by the destination background
- Firstly, layer 0 (RGB0, A0) blends with the destination like this:
- RGBBlend0 = C * (1 - A0) + RGB0 * A0
- Then layer 1 (RGB1, A1) blends with the destination like this:
- RGBBlend1 = RGBBlend0 * (1 - A1) + RGB1 * A1
- -------------------------------------------------
- Let's combine these two steps (substituting):
- RGBBlend1 = C * (1-A0)*(1-A1) + RGB0*A0*(1-A1) + RGB1*A1
- What we want is a layer that achieves this in one blend, ie (RGB, A) such that:
- RGBBlend1 = C * (1 - A) + RGB * A
- Equating C terms,
- 1-A = (1-A0)*(1-A1)
- A = 1 - (1-A0)*(1-A1) = A0 + A1 - A0*A1 -- (equation Alpha)
- Equating RGB terms,
- RGB = ( RGB0*A0*(1-A1) + RGB1*A1 ) / A -- (equation for RGB)
- ------------------------------------------------
- With some rearrangement, we get:
- RGB = RGB0 + (RGB1 - RGB0) * F(A0,A1)
- where F(A0,A1) is a lookup table given by
- F(A0,A1) = A1 / (A0 + A1 - A0*A1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement