Page 1 of 1

alpha blending

Posted: Mon Jan 12, 2009 11:47 am
by LionX
(note: im not using gskit or any other. im using my gs lib)

ok, im trying to do alpha blending on the ps2 by loading a background image and draw it, then i load a texture and draw it as a flat textured sprite.

i want to enable alpha blending so i set PRIM->ABE = 1;

i also want to enale the alpha pix in my texture so i can have trasnparent TEX0->TCC = 1;




my question it. it it a crime to have Alpha=0xff for a pixel in my 32 bit image? because my image color is overflowing when i have have my sprite color set to RGBA(0x80, 0x80, 0x80, 0x80) which is normal. it looks fine when i set it to: RGBA(0x80, 0x80, 0x80, 0x40).


so i tried re-export my image with all Alpha pixel set to 0x80 instead of 0xff.

when i retried it, it look perfect. i set the sprite color to: RGBA(0x80, 0x80, 0x80, 0x80) and it was solid. then i set it to RGBA(0x80, 0x80, 0x80, 0x40) and it was half trasnparent.

so, when doing alpha blendin on textures. is it a crime to have Alpha in each pixel set to 0xff.

Posted: Mon Jan 12, 2009 12:10 pm
by radad
I had this issue with gsKit too. After looking through the GS spec pdf I came to the conclusion that 0x80 is the maximum alpha value.

Posted: Mon Jan 12, 2009 12:30 pm
by LionX
for Alpha pixel in the texture ? or for sprite color Alpha ?

Posted: Mon Jan 12, 2009 6:24 pm
by Lukasz
If look in the GS manual under "Texture Function" it states that the sprite color set in the GIF packet is used to blend with the textures colors (including alpha). How this is blended depends on the texture function used (eg. MODULATE, DECAL, HIGHLIGHT, HIGHLIGHT2), you set this in the TFX field in the TEX0 register.

If you use the default TFX value 0 (MODULATE), you get the following formula

Code: Select all

Rv = Rt * Rf
Gv = Gt * Gf
Bv = Bt * Bf
Av = At * Af
Where Xv is the output color, Xt is the texture color and Xf is the sprite color (or fragment color). In the GS manual it also states under texture function MODULATE that 0x80 is the maximum (brightest) value.

If you use the DECAL texture function then your sprite color is disregarded. See the GS manual for the rest :-)

Also if you look under "Blending Settings" (also in RGBAQ register description) in the GS manual it stats that if you set the alpha to 0x80 the multiplier becomes 1.0. So 0x80 is the maximum alpha value.

So it makes perfect sense when you write that you multiply use alpha=0x80 in your sprite texture and alpha=0x40 in your sprite color in MODULATE mode, because then you get 0x80 (1.0) * 0x40 (0.5) = 0x40 (0.5) which is exactly half transparent.

EDIT:
To answer you question directly, you shouldn't set the alpha value above 0x80 anywhere, as this is equal to 1.0 (no transparency/solid).