Sign in to follow this  
JTippetts

[web] Actionscript 3: Alpha blending using BitmapData.draw

Recommended Posts

Recently, I've taken to playing around with ActionScript 3 development using Flex, and I've run across something that puzzles me. Perhaps I'm missing something completely obvious, but... Is there a way to perform (SourceColor*SourceAlpha)+(DestColor*(1-SourceAlpha)) style blending using a BimapData.draw() call without using a Pixel Bender shader? I've perused the possible parameters for BlendMode but none of them seem to offer this sort of blending. I currently use a pixel shader to perform the operation, but I was wondering if there is a more obvious solution, particularly one that doesn't force the requirement of Flash Player 10 as shaders do (not that that is a bad thing, imo). [Edited by - JTippetts on June 22, 2009 11:36:45 PM]

Share this post


Link to post
Share on other sites
You could use one ColorTransform each to transform your "source" and "destination" images, then draw them with blend mode set to ADD. I have no idea what the performance of that would be.

ie, something like:

var src:BitmapData = new BitmapData(100, 100, false, 0xFF000000);
var dst:BitmapData = new BitmapData(100, 100, false, 0xFFFFFFFF);

var srcXfrm:ColorTransform = new ColorTransform();
srcXfrm.alphaMultiplier = 1.0;
var dstXfrm:ColorTransform = new ColorTransform();
dstXfrm.alphaMultiplier = 0;

var rect:Rectangle = new Rectangle(0, 0, 100, 100);

while (xfrm.alphaMultiplier > 0) {
srcXfrm.alphaMultiplier -= 0.1;
dstXfrm.alphaMultiplier += 0.1;

dst.draw(..., dstXfrm, BlendMode.NORMAL, ...);
src.draw(..., srcXfrm, BlendMode.ADD, ...);
}


I didn't test this, so you'd have to give that a shot and let us know if it's tweakable or a waste of time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this