View Full Version : Manualy Alpha blending two colors
SilverWarior
06-10-2011, 01:56 AM
How to manualy calculate resulting color by Alphablending two existing colors?
wagenheimer
06-10-2011, 02:02 PM
I have done something like this some days ago!
This link help-me a lot! http://en.wikipedia.org/wiki/Alpha_compositing
The formula I used was this one :
outRGB = srcRGB * srcAlpha + destRGB * (1-srcAlpha)
SilverWarior
06-10-2011, 04:16 PM
Do you have any source code? I have seen that article and tried to implement it on my own, but I don't seem to get it working right.
Also I'm trying to implement seperate calculations for each color chanell (red, green, blue).
User137
06-10-2011, 10:59 PM
That's what he meant i think. Try formula for each channel:
outR := srcR * srcAlpha + destR * (1-srcAlpha);
outG := srcG * srcAlpha + destG * (1-srcAlpha);
outB := srcB * srcAlpha + destB * (1-srcAlpha);
Actually, the simplest (and slightly faster) alpha-blending equation is:
Dest.R = Src1.R + (Src2.R - Src1.R) * Alpha;
Dest.G = Src1.G + (Src2.G - Src1.G) * Alpha;
Dest.B = Src1.B + (Src2.B - Src1.B) * Alpha;
where Dest is the final color, Src1 and Src2 are the source colors with Alpha in [0..1] range.
SilverWarior
07-10-2011, 09:56 PM
Thanks guys. That works like charm.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.