Why do we Mask?

Started by
3 comments, last by Krypt0n 13 years ago
Hi,

I've recently programmed a 2d game and the artist who helped me made all the sprites with a true red background and I made a masking function in the game and it works and alls good. But WHY do we mask? I'm using .png format sprites so isn't it unnecessary seeing as .png uses RGBa? In websites that offered free sprites they had grey backgrounds so I'm assuming its standard practice but I still don't understand why this is advantageous.

Can someone please enlighten me?

Thanks
Advertisement
The reason is so you don't see the background around your sprite. If you didn't mask (or use an alpha channel) your sprites would consist of a box shape surrounding the main image.

******************************************************************************************
Youtube Channel

There are two parts to it.
1) The masking itself means you don't have to store 32bit images. You can store a 24bit or a paletted image and still make transparent images.
2) Using a mask lets you use much faster blending features, like hardware color-keying or cut-off alpha testing. Since you are doing a binary operation of keep or discard for each pixel this is faster to draw than doing a regular blend function that does a full blend calculation on every pixel. Cutoff alpha also has the benefit of being draw order independant.
On a PC it's kind of pointless really, as we have the hardware to use an alpha channel. On handhelds masking is still a must, but in a year or two it'll probably be useless there as well.

On a PC it's kind of pointless really, as we have the hardware to use an alpha channel. On handhelds masking is still a must, but in a year or two it'll probably be useless there as well.

I use it to render front2back, as masking allows me to have occlusion informations, which save some work on cpu, but even some gpus nowadays benefit from that.

that's also the reason why a lot of games use alpha test on e.g. vegetation, blending and z-buffering is still not really solved.


This topic is closed to new replies.

Advertisement