Alpha Blending Layers for linear light mode

I am recreating Photoshop blending and I am trying to use the Linear Light mode. In Photoshop, you will have a background layer with 100% opacity, and then a top layer with an opacity of 50%, which is set as linear light as the blend mode.

I found information on how to make the Linear Light blend, but it only works when both layers have 100% opacity.

Here is the shader code that will work in Linear Light mode and gives the same result as Photoshop when the layers have 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 looked at http://en.wikipedia.org/wiki/Alpha_compositing , but I still have problems.

How can I make blend mode work for translucent layers?

+2
source share
1 answer

You should read the PDF specification to learn how to use blending modes when you have alpha other than 100%. In particular, see Section 7.2, Basic Compilation Calculations. The formula on page 414 should explain what you need:

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

All Articles