Page 1 of 1

per pixel alpha

Posted: Thu May 17, 2007 9:56 am
by radad
I have been having a few issues with images that have per pixel alpha values.

It is hard to describe what is happening in all cases. When the alpha is 0 nothing is displayed, all correct there. But when the alpha was 255 it was still been alpha blended with the background.

What I discovered last night though is that if I rescale the 0-255 alpha values into 0-63 then everything works correctly. Anybody have any ideas about that? It seems the last two bits are used for something else.

Posted: Thu May 17, 2007 6:58 pm
by ps2devman
These are a few comments I've put in system.c in Q*Bert starter kit :

gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(1,2,0,0,0), 1);
//Cv=(Cd-0)*As>>7+Cs (p100 GS user manual)
//Alpha blending per pixel is on (p115 GS user manual)

Cv: Color value you get actually after operation
Cd: Color read at pixel destination
Cs: Color read in texture source
As: Alpha read in texture source

The formula above is only one of the possible formula you can obtain.
(only reading GS user manual will allow you to learn how to change the formula)

So... With this formula, and this one only, you can consider :
if Alpha = 128 & Cs= 0 (because 128>>7=1), color is transparency 100%
if Alpha = 0, result color is Cs, opaque 100%
and so on
if Alpha > 128 you may have unpredictable results in case of overflows

Posted: Fri May 18, 2007 10:15 am
by radad
Doesnt your formula suggest that any alpha value from 0-127 is 100% opaque?

Where is the GS user manual?

Posted: Fri May 18, 2007 12:15 pm
by radad
Ok, I have looked that up. I think I get it now.
Thanks.