Alpha Blending Layers for Linear Light Mode

graphics, opengl, shader

Solution

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)]

Problem

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?

Original source