How to blend 2 transparency layers?

隐身守侯 提交于 2019-12-13 03:25:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!