forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

alpha blending

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
LionX



Joined: 27 Dec 2004
Posts: 61

PostPosted: Mon Jan 12, 2009 11:47 am    Post subject: alpha blending Reply with quote

(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.
Back to top
View user's profile Send private message
radad



Joined: 19 May 2004
Posts: 246
Location: Melbourne, Australia

PostPosted: Mon Jan 12, 2009 12:10 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
LionX



Joined: 27 Dec 2004
Posts: 61

PostPosted: Mon Jan 12, 2009 12:30 pm    Post subject: Reply with quote

for Alpha pixel in the texture ? or for sprite color Alpha ?
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Mon Jan 12, 2009 6:24 pm    Post subject: Reply with quote

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:
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).
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group