Pixel Bender Blend Modes

In preparation for my Pixel Bender talk at 360Flex I wanted to create an example which shows how to use Pixel Bender shaders as blend modes, so I went ahead and whipped together 20 blend shaders:  Darken, Multiply, Color Burn, Linear Burn, Lighten, Screen, Color Dodge, Linear Dodge (Additive), Overlay, Soft Light, Hard Light, Vivid Light, Linear Light, Pin Light, Difference, Exclusion, Interpolation, Invert, Quadratic, and Subtract.

You'll notice there is some overlap with the set that are natively available in flash.display.BlendMode, but I thought it would be pretty educational to see how these shaders are written Pixel Bender.  I have yet to test to see if there is a significant performance difference.

Pixel Bender Blend Modes Preview

Application - Source

The formulas behind these blend modes were pretty easy to find.  I got them from a combination of http://www.pegtop.net/delphi/articles/blendmodes, http://dunnbypaul.net/blends/, wikipedia and the Flash docs.

One topic I wasn't able to find much documentation on was how to handle alpha channels for the various blend modes.  It gets complicated if both layers have transparency, and I'm not sure if there is a standardized way of computing the resulting alpha.  So for these examples the alpha is simply set to that of the input image.  This means that these blend modes work perfectly for opaque images, but vary from what you might see in photoshop when transparency is involved.  If anyone has any good resources on the topic or would like to contribute to this effort, let me know in the comments.


About this entry