Alpha Blending Layers for Linear Light Mode

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?


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


  • glMapBufferRange() returns all zeros in Android OpenGLES 3.0 using TrasnformFeedback
  • How to use a huge array in HLSL (error X4505)
  • glGetUniformLocation return -1 on nvidia cards
  • Text overlay not showing in GPUImage iOS
  • Geometry shader doesn't do anything when fed GL_POINTS
  • Thread synchronization with syncwarp
  • How to call a procedure using NHibernate that returns result from multiple tables?
  • Efficient & Pythonic way of finding all possible sublists of a list in given range and the minim
  • Changing references to deprecated methods C++
  • For loop with if condition on multiple R functions
  • SQLite connection strategies
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • How to assign byte[] as a pointer in C#
  • TextToSpeech.setEngineByPackageName() triggers NullPointerException
  • revitapi ironpython ToRoom returns “indexer # object”
  • Access variable of ScriptContext using Nashorn JavaScript Engine (Java 8)
  • App restarts from wrong activity
  • C: Incompatible pointer type initializing
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • CakePHP 2.0.4 - findBy magic methods with conditions
  • Sencha Touch 2.0 Controller refs attribute not working?
  • When to use `image` and when to use `Matrix` in Emgu CV?
  • What is the “return” in scheme?
  • PHP - How to update data to MySQL when click a radio button
  • Is possible to count alias result on mysql
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • what is the difference between the asp.net mvc application and asp.net web application
  • Upload files with Ajax and Jquery
  • Apache 2.4 - remove | delete | uninstall
  • Numpy divide by zero. Why?
  • php design question - will a Helper help here?
  • AngularJs get employee from factory
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • How can I remove ASP.NET Designer.cs files?
  • java string with new operator and a literal