3
votes

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
Can you update question with: 1) What is the formula for Linear Light blending? 2) What result are you expecting? 3) In which case are you not getting what you expect (i.e. define 'does not work')? 4) Your OpenGL code?Tim
The code snippet should have answered all your questions. For those that don't have Photoshop would a screenshot really help?Dex
I thought this was an OpenGL question, and I didn't see any OGL code. I assumed you were trying to emulate some kind of photoshop feature, but maybe I misunderstood you.Tim
Well I'm using shader code, that I call from OpenGL. I tagged with OpenGL because lots of OpenGL programmers use shaders and probably know the theory behind it.Dex

1 Answers

5
votes

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