RGBA + global alpha value

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

RGBA + global alpha value

Post by Brunni »

Hello all ^^

I have a RGBA image that I use as a simple sprite, it's usually 5551 (just 1 bit to define if the pixel is transparent or not). Up to here, I used:
sceGuBlendFunc(GU_ADD,GU_ONE_MINUS_SRC_ALPHA,GU_SRC_ALPHA,0,0);
This will work, if the bit is 1, then it's transparent, else not.
But now, I want to add a global alpha value to my sprite, so that it's semi-transparent. Usually, I just do:
sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, coeff, 0xffffffff-coeff);
Where coeff can be 0x00808080 for semi-transparency. It works, but the problem is that this won't take the alpha value in consideration and the transparent sprite part will be drawn as solid black...

The goal would be a blendfunction that multiplies GU_SRC_ALPHA by a fixed value, like GU_ONE_MINUS_SRC_ALPHA * GU_FIX and GU_SRC_ALPHA * GU_FIX, but it seems not to be possible regarding the documentation.

If anyone can help me, I would really appreciate, thanks :)
Sorry for my bad english
Image Oldschool library for PSP - PC version released
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

You could do it that way, I guess, but the more conventional approach is to use the current colour to modulate the texture pixels.

Use:

Code: Select all

sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
sceGuBlendFunc(GU_ADD,GU_SRC_ALPHA,GU_ONE_MINUS_SRC_ALPHA,0,0);
sceGuColor(0xNNffffff); // NN = alpha
This will multiply each texture pixel with the current colour, as well as take the texture's alpha channel into account. Note you can also use this for tinting the image, rather than just changing the alpha.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

Thanks, it works, but the problem is that my alpha is opaque when 0 and transparent when 1, because it's for a library and I don't want to fill my buffers with 0xff000000 by default.
sceGuBlendFunc(GU_ADD,GU_ONE_MINUS_SRC_ALPHA,GU_SRC_ALPHA,0,0);
sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
sceGuAmbientColor(coeff<<24);
If I do that, it will multiply them and they will become more opaque instead of more transparent :(
In fact I would need to make something like Av=(1-At)*Af but sceGuTexFunc doesn't permit this.
Any solution?
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Post Reply