Alpha blending algorithm...

Started by
4 comments, last by coldacid 22 years, 1 month ago
What is the algo, and in what time does it run? I need to know whether or not it''s worth the time to do it in software, since I''d rather not use Direct3D just for the one feature. Chris ''coldacid'' Charabaruk <ccharabaruk@meldstar.com> <http://www.meldstar.com/~ccharabaruk/> Meldstar Studios <http://www.meldstar.com/> - Creation, cubed. This message double ROT-13 encrypted for additional security.

Chris 'coldacid' Charabaruk – Programmer, game designer, writer | twitter

Advertisement
It is a per pixel operation so as a general rule it is slow. The equation is simple, dp=sp*a+dp*(1-a) or dp=(sp-dp)*a+dp assuming 1 is opaque and 0 is transparent. dp is your destination pixel, sp is the source pixel and a is the alpha. Your alpha may be 0 to 255 instead though and you have to do each color individually. Simple routines are difficult to optimize. They are simple to get working though so try it, measure it and decide if you need optimization.
Keys to success: Ability, ambition and opportunity.
Thanks. Yeah, I''d be working with an 8 bit alpha instead of a single bit one, as far as I''m concerned with a single bit for alpha, you get either the source or the destination, on or off.


Chris ''coldacid'' Charabaruk <ccharabaruk@meldstar.com> <http://www.meldstar.com/~ccharabaruk/>
Meldstar Studios <http://www.meldstar.com/> - Creation, cubed.

This message double ROT-13 encrypted for additional security.

Chris 'coldacid' Charabaruk – Programmer, game designer, writer | twitter

coldacid:if you want a really simple implementation of software blitting and software alpha-blending you can check out my tutorial (unfortunetly for you it''s written in polish language, hopefully you will understand something from source)
go get it at:
http://warsztat.pac.pl/mirekcz/mczart/mczddraw1.shtml
you will find the link to source in point 7 of this tutorial.

PS.software is good as long as you don''t want hi-resolutions. a nice optimized 640x480x16bpp(on more modern computers like durons or p3 you can easily go for higher res) engine will work like a charm on most computers, while a d3d implementation needs a v2 or tnt card at least.
With best regards, Mirek Czerwiñski
Mirek: Thanks. If the source isn''t enough, and I need to read the tutorial, then I''ll get my grandparents to translate for me. Shame I don''t know my family tounges, but then again, there''s about four different languages used by my relatives. More than any one insane person could keep track of...

Regarding your postscript, I was thinking 640x480x32bpp... Too much for a P2/350 with a generic ATI card?


Chris ''coldacid'' Charabaruk <ccharabaruk@meldstar.com> <http://www.meldstar.com/~ccharabaruk/>
Meldstar Studios <http://www.meldstar.com/> - Creation, cubed.

This message double ROT-13 encrypted for additional security.

Chris 'coldacid' Charabaruk – Programmer, game designer, writer | twitter

Well, perhaps 0.0 to 1.0 would make it clearer. The alpha is a percentage. Some value is 100% transparent and some value is 100% opaque.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement