问题
For example we have 2 transparency layers: first is black (0, 0, 0, 0.75)
and second is white (255, 255, 255, 0.64)
. I don't know how to blend them.
But I know how to blend one opaque and one transparent layers. It's look like this: https://wikimedia.org/api/rest_v1/media/math/render/svg/1e35c32f13d5eedc7ac21e9e566796dd048a31e6
回答1:
Assume that the background colour is (C, 1)
(RGB, A), the first layer is (A, s)
and the second layer (B, t)
. Applying the blending equation twice:
C' = t * B + (1-t) * [s * A + (1-s) * C]
= [t * B + (1-t) * s * A] + (1-t) * (1-s) * C
We can see that the new effective blending coefficient is 1 - (1-s) * (1-t)
. To get the combined transparency colour, divide the first term by this:
r := 1 - (1-s) * (1-t)
D := [t * B + (1-t) * s * A] / r
--> C' = r * D + (1-r) * C
i.e. the new effective transparency layer is given by (D, r)
.
In your example the values would be D = (179, 179, 179)
and r = 0.91
.
来源:https://stackoverflow.com/questions/53321906/how-to-blend-2-transparency-layers