Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

SikCiv

Alpha blending MMX problem

This topic is 6920 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

Has somebody of you coded a good (optimized) routine to get the PixelData and set Pixels with this info.
Maybe sth like so:

class cRGBInfo
{
private:
// RGBData

public:
HRESULT GetRGBInfo (void);
WORD RGB (BYTE red, BYTE green, BYTE blue);
};

Share this post


Link to post
Share on other sites
Advertisement
Ok, I look at the old code from my article on gamedev.net. The first correction is in the 15bpp part of the MMX code the color MASKS are incorrect. The color masks for 15bpp should be:

MASKRED = 0x7C007C007C007C00;
MASKGREEN = 0x03E003E003E003E0;
MASKBLUE = 0x001F001F001F001F;

This will fix the funky colors some of you were seeing. The second, less obvious fix is in the AlphaImproved function. The calculation of the color channels should be:

For 15bpp -
BLUEC = (((ALPHA * ((sb + PLUS64) - db)) + (db<<8) - (ALPHA64)) >> 8) & 0x001F001F;
GREENC = ((((ALPHA * ((sg + PLUS64) - dg)) + (dg<<8) - (ALPHA64)) >> 8) & 0x001F001F) << 5;
REDC = ((((ALPHA * ((sr + PLUS64) - dr)) + (dr<<8) - (ALPHA64)) >> 8) & 0x001F001F) << 10;



And for 16bpp
BLUEC = (((ALPHA * ((sb + PLUS64) - db)) + (db<<8) - (ALPHA64)) >> 8) & 0x001F001F;
GREENC = ((((ALPHA * ((sg + PLUS64) - dg)) + (dg<<8) - (ALPHA64)) >> 8) & 0x003F003F) << 5;
REDC = ((((ALPHA * ((sr + PLUS64) - dr)) + (dr<<8) - (ALPHA64)) >> 8) & 0x001F001F) << 11;


You will need to add the definition of ALPHA64 at the top of the function:

DWORD ALPHA64;
...
ALPHA64 = (ALPHA * 64) / ((ALPHA * 64) << 16);

This will fix the jitter (or flashing) that you could see. Basically as it progressed though the color channel range it would do something like:

REDC: 1,1,1,2,2,2,3,2,3,3,4,3,3,4,4,4.....

So, occasionally it resorts back by one shade and this gives the effect that it is jittery or flashing. Also, I noticed some pretty ugly banding in 15bpp mode.

The MMX code suffers from this jittering as well but I do not have the time right now to fix it. The fix, as a reader pointed out to me is simply to use an MMX instruction that retains the sign and as a bonus you can get rid of the ALPHA64 and ALPHABY4 instructions. speeds it up a little!

Later,
hebertjo

Share this post


Link to post
Share on other sites
Are these corrections supposed to fix all the problems?

I ask that because I still get odd results with the 5-5-5 MMX and non-MMX portions.

The 5-6-5 side is working well though

Share this post


Link to post
Share on other sites
Yep, all seems to be ok now

BTW, do you think the non-mmx version could benefit from being written in assembler? I might try this if I can get a firm grasp on assembler.

Thank you for this alpha blending source code, I could have took me months to do by myself

See ya

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
DragonRider, assuming you are a guru at assembler, almost anything is faster written in pure assembler than high level languages.

But you would have to know the hardware incredibly well. Otherwise, compilers are optimizing enough today that can beat out the average programmer.

Things like alpha blending though would probably still be faster to do in pure assembler, mmx or not, though around the time the mmx instruction set came out, many games were still using paletted modes, which would probably be the way to go.

Share this post


Link to post
Share on other sites
I''m glad to hear it is working for you. I have no plans to rewite the non-MMX code in assembler. Please post your results if you get it working.

hebertjo

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!