如何混合2个透明层? [英] How to blend 2 transparency layers?
问题描述
例如,我们有2个透明层:第一个是black (0, 0, 0, 0.75)
,第二个是white (255, 255, 255, 0.64)
.我不知道如何融合它们.
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.
但是我知道如何混合一层不透明层和一层透明层.看起来像这样: https://wikimedia.org/api/rest_v1 /media/math/render/svg/1e35c32f13d5eedc7ac21e9e566796dd048a31e6
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
推荐答案
假定背景色为(C, 1)
(RGB,A),第一层为(A, s)
,第二层为(B, t)
.两次应用混合方程:
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
我们可以看到新的有效混合系数为1 - (1-s) * (1-t)
.要获得组合的透明色,请将第一项除以:
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
即新的有效透明层由(D, r)
给出.
i.e. the new effective transparency layer is given by (D, r)
.
在您的示例中,值将为D = (179, 179, 179)
和r = 0.91
.
In your example the values would be D = (179, 179, 179)
and r = 0.91
.
这篇关于如何混合2个透明层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!