Jump to content
  • Advertisement
Sign in to follow this  
JTippetts

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

This topic is 3314 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!