This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Bitwise help!!!


Re: Bitwise help!!!

Postby Digby » Jul 20, 2001 @ 9:45pm

Now that I think of it, if you're doing alpha blending correctly it won't overflow anyway.  Here's the typical alpha blending equation:<br><br>sC = source color (sprite)<br>dC = dest color (frame buffer)<br>a = alpha blending value<br><br>NB: assumes color and alpha are in the range 0.0..1.0.<br><br>dC = (sC * a) + (dC * (1 - a))<br><br>How is this addition going to overflow?<br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Bitwise help!!!

Postby Malmer » Jul 20, 2001 @ 10:20pm

if you do alpha like that it will be incredibly slow (floats). no, it would be insanely slow. Besides getting the source pixel color in this case requires you to calculate the "real" color since in the source image it is faded out to black. So I have to use the alpha to figure out the real value, then I have to draw the pixel over using an alpha value. Now I don't do that process because that would be slow with many multiplications (SLOW) and maybe some divisions (SLOWER). So instead I managed to isolate a pretty nice formula using just bitshifts and one multiplication. The thing itself takes litterarly no performance if it wasn't for that it in rare cases can overflow. Why do you think Ag is the first PPC game with alpha blended sprites (am I right here?)<br><br>As for the technical name of this type of alpha blending I think it is called additive alpha blending.<br><br>// Fredrik<br>
All your base are belong to us
User avatar
Malmer
pm Member
 
Posts: 768
Joined: Apr 26, 2001 @ 5:15pm
Location: Sweden


Re: Bitwise help!!!

Postby Malmer » Jul 20, 2001 @ 10:53pm

Actually...been testing some...and it isn't the method itself that causes it. What is causing it is the fact that images containing the sprite and the alpha channel aren't truecolor but are palletized making the color of certain areas of them to be less exact compared with the alpha.<br><br>Either way, I think I've found a way to fix these issues quite easily...I'll get back to you...So hopefully I can remove the conditionals alltogether. Hurray!
All your base are belong to us
User avatar
Malmer
pm Member
 
Posts: 768
Joined: Apr 26, 2001 @ 5:15pm
Location: Sweden


Re: Bitwise help!!!

Postby Malmer » Jul 20, 2001 @ 11:01pm

HAHA! I fixed it! Now we just saved three if-statements per transparent pixel! Hurray! Hurray!<br>
All your base are belong to us
User avatar
Malmer
pm Member
 
Posts: 768
Joined: Apr 26, 2001 @ 5:15pm
Location: Sweden


Re: Bitwise help!!!

Postby Dan East » Jul 21, 2001 @ 12:22am

Quake allocates a minumum of 5.57 MB off the heap at startup. Actually it will allocate all the program memory available. Plus there's a few other chunks taken off the heap (for particles, etc). I think it needs close to a megabyte heap as well. The SH3 devices needed a larger heap for some reason (must need data aligned at larger intervals).<br><br>Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Re: Bitwise help!!!

Postby Digby » Jul 21, 2001 @ 2:54am

Glad you got it working!<br><br>The only reason I expressed the equation using floats was so that you and others could understand it.  No one would be using floating point in an actual alpha blit routine.  <br><br>If it were me, I'd probably use premultiplied alpha in my source image and save the inverse alpha (here expressed with an 8-bit value) rather than the actual alpha, then the pixel calculation looks like:<br><br>dC = sC + (iA*dC)>>8<br><br>I'd measure the performance of this versus using a lookup table to perform the multiplication and shift.<br><br>I'm curious as to why you're using palettized sprites instead of storing them in the format native to the display?<br><br>It's good to see that you guys are in the optimization phase of the project.  You must be in the home stretch now.<br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Bitwise help!!!

Postby Malmer » Jul 21, 2001 @ 8:23am

I could quite easily change to premultiplied alpha. The formula I have is not very far from the one you have, but if I changed to premultiplied alpha I would have to remake all unit gfx preparations (ouch!) and john would have to rerender it all. Besides, I don't think all rendering packages out there support premultiplied alpha, so for the mod-ing community I think it is best to keep it the way it is.<br><br>Or maybe I could make it an option on each sprite...hmm...<br><br>-f
All your base are belong to us
User avatar
Malmer
pm Member
 
Posts: 768
Joined: Apr 26, 2001 @ 5:15pm
Location: Sweden


Re: Bitwise help!!!

Postby Digby » Jul 21, 2001 @ 2:19pm

You could perform the premultiply and alpha inversion when the image is loaded.<br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Clamping... (bitwise help)

Postby Refractor » Feb 4, 2002 @ 10:28am

Refractor
 


Postby Dan East » Feb 4, 2002 @ 11:28am

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby Phantom » Feb 4, 2002 @ 2:16pm

Give me some good data and
I will give you the world
User avatar
Phantom
pm Insider
 
Posts: 913
Joined: Feb 21, 2001 @ 8:14am
Location: Houten, Netherlands


Adding bytes with saturation with LUT

Postby Kzinti » Feb 4, 2002 @ 3:54pm

Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby Phantom » Feb 5, 2002 @ 9:41am

Give me some good data and
I will give you the world
User avatar
Phantom
pm Insider
 
Posts: 913
Joined: Feb 21, 2001 @ 8:14am
Location: Houten, Netherlands


Postby Digby » Feb 6, 2002 @ 9:25am

Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby refractor » Feb 6, 2002 @ 9:46am

User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


PreviousNext

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum