alpha blending

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
LionX
Posts: 61
Joined: Mon Dec 27, 2004 11:40 am

alpha blending

Post 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.
radad
Posts: 246
Joined: Wed May 19, 2004 4:54 pm
Location: Melbourne, Australia

Post 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.
LionX
Posts: 61
Joined: Mon Dec 27, 2004 11:40 am

Post by LionX »

for Alpha pixel in the texture ? or for sprite color Alpha ?
User avatar
Lukasz
Posts: 248
Joined: Mon Jan 19, 2004 8:37 pm
Location: Denmark
Contact:

Post 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).
Post Reply