How to manualy calculate resulting color by Alphablending two existing colors?
How to manualy calculate resulting color by Alphablending two existing colors?
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)
Cezar Wagenheimer from Green Sauce Games
Programmer of Druids - Battle of Magic, Abra Academy, Abra Academy - Returning Cast, Rabbit Jump, Dreams of a Geisha and Heroes from the Past: Joan of Arc
Wagenheimer's Game Development Blog
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).
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:
where Dest is the final color, Src1 and Src2 are the source colors with Alpha in [0..1] range.Code: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;
Thanks guys. That works like charm.
Bookmarks