Alpha Blending Layers for Linear Light Mode

寵の児 提交于 2019-12-11 02:26:54

问题


I'm recreating some Photoshop blending and I'm trying to use Linear Light mode. In Photoshop you'd have a background layer at 100% opacity and then a 50% opacity top layer that is set to Linear Light as the blend mode.

I did find info on how to do the Linear Light blend, but it only works when both layers are at 100% opacity.

Here is the shader code that will do Linear Light mode and it gives the same result as Photoshop when layers are both at 100% opacity:

#define BlendLinearDodgef           BlendAddf
#define BlendLinearBurnf            BlendSubstractf

#define BlendAddf(base, blend)      min(base + blend, 1.0)
#define BlendSubstractf(base, blend)    max(base + blend - 1.0, 0.0)


#define BlendLinearLightf(base, blend)  (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5))))

I've looked at http://en.wikipedia.org/wiki/Alpha_compositing but am still having issues.

How can I get the blend mode to work for semi-transparent layers?


回答1:


You should read the PDF spec to learn about how to use blend modes when you have alpha other than 100%. In particular, see section 7.2, "Basic Compositing Computations." The formula on page 414 should explain what you need:

Cr= (1-as/ar) * Cb + (as/ar) * [(1-ab) * Cs + ab * B(Cb,Cs)]


来源:https://stackoverflow.com/questions/10713120/alpha-blending-layers-for-linear-light-mode

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