Alpha blending ??

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

Moderators: cheriff, TyRaNiD

Post Reply
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Alpha blending ??

Post by sandberg »

Hi guys,

I have a really hard time getting my alpha blending to work. Basically I've taken the setup from how it is done in the sprite sample, which works fine.
The code is shown below (it taken from several places in the project, but the code below shows the order and parameters to the GU calls). It has been stripped down to a minimum, to only two vertices for a single sprite, but it still doesn't work.

Some info. My textures are correct and I've also tried to use the ball.raw from the sprite sample Also, if I don't call sceGuEnable(GU_ALPHA_TEST), the sprite shows up correct. I have other renderings in the projects, where the alpha channel seems to be used just fine ?

Can anyone seem to difference, from what I'm doing here to what is done in the sprite sample ??

Code: Select all


	sceGuAlphaFunc(GU_GREATER,0,0xff);
	sceGuEnable(GU_ALPHA_TEST);
	sceGuEnable(GU_TEXTURE_2D);

	// setup texture
	sceGuTexMode(GU_PSM_5551,0,0,0);
	sceGuTexImage(0,width, height, width, (void *)offset);
	sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA);

	sceGuDepthFunc(GU_ALWAYS);
	sceGuAmbientColor(0xffffffff);

	sceGumMatrixMode(GU_MODEL);
	sceGumLoadIdentity();
		{
		ScePspFVector3 pos = { 0, 0, -4.5f };
		sceGumRotateXYZ(&rot);
		}

	jsaParticleVertex* l_vertices = (jsaParticleVertex*)sceGuGetMemory(2 * sizeof(jsaParticleVertex));
		jsaParticleVertex *index = &l_vertices[0]; 

		index[0].u = 0;
		index[0].v = 0;
		index[0].color = 0xffffffff;
		index[0].x = - 1.0f;
		index[0].y = - 1.0f;
		index[0].z = 0;

		index[1].u = 1;
		index[1].v = 1;
		index[1].color = 0xffffffff;
		index[1].x = 1.0f;
		index[1].y = 1.0f;
		index[1].z = 0;

	sceGumDrawArray(GU_SPRITES, GU_COLOR_8888 | GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_3D,2,0,l_vertices);

	sceGuDepthFunc(GU_GEQUAL);
	sceGuDisable(GU_ALPHA_TEST);
	sceGuDisable(GU_TEXTURE_2D);

Br, Sandberg
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Post by sandberg »

Anyone ?

I don't have the faintest clue about, why my alphachannel is ignored when I enable alpha blending and I set the texture function to modulate and take the alpha channel into account ?
Br, Sandberg
Paco
Posts: 54
Joined: Sun Oct 09, 2005 6:53 pm

Post by Paco »

I don't see anything wrong with that code. Alpha testing (you're NOT! doing alphablending) is working here, but I use 4444 textures, so it's not identical to yours.
Paco
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Re: Alpha blending ??

Post by cheriff »

I havent done much (ok. any) psp graphics coding, but are you sure you dont mean:

Code: Select all

	sceGuEnable(GU_BLEND);
instead of GU_ALPHA_TEST ???

alpha testing will simply pass/fail a pixel depending on if its alpha value is above/below/equal a certain threshold, much the same a depth testing does on the z value.
alpha blending is transparency and all that.

/me tries to remember back to openGL days..
Damn, I need a decent signature!
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Re: Alpha blending ??

Post by sandberg »

cheriff wrote:I havent done much (ok. any) psp graphics coding, but are you sure you dont mean:

Code: Select all

	sceGuEnable(GU_BLEND);
instead of GU_ALPHA_TEST ???

alpha testing will simply pass/fail a pixel depending on if its alpha value is above/below/equal a certain threshold, much the same a depth testing does on the z value.
alpha blending is transparency and all that.

/me tries to remember back to openGL days..
I do have blending enabled in the real project. But I've disabled it here, to make it easier to figure out why the alpha testing isn't working.

It is alpha testing that I need to work here. But it seems like it is ignoring my alpha plane. I'll try to convert and load the texture in 4444 format, to see if that makes any difference.
Br, Sandberg
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Re: Alpha blending ??

Post by cheriff »

Oh, sorry i must have misread you 1st post, it sounded like you were having a hard time getting blending to work..
If we still have time for one more uninformed stab in the dark, I don't see where you are setting the parameters for the apha test, are you calling

Code: Select all

void sceGuAlphaFunc(int func, int value, int mask);
somewhere in the app?
Damn, I need a decent signature!
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Re: Alpha blending ??

Post by sandberg »

cheriff wrote:Oh, sorry i must have misread you 1st post, it sounded like you were having a hard time getting blending to work..
If we still have time for one more uninformed stab in the dark, I don't see where you are setting the parameters for the apha test, are you calling

Code: Select all

void sceGuAlphaFunc(int func, int value, int mask);
somewhere in the app?
That's in the first line in the code :)
Br, Sandberg
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Post by cheriff »

so it is. Looks like im having a bad day, so i'll shutup now. :)
Damn, I need a decent signature!
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Post by sandberg »

Now I've come a little further. The only code which was different from the stuff that worked and the stuff that didn't work, was that the stuff working wasn't using 3D transforms (they were icons drawn at absolute places).

If I change the line below:

Code: Select all

sceGumDrawArray(GU_SPRITES, GU_COLOR_8888 | GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_3D,2,0,l_vertices);
So that they don't ask the GE to do the 3D transform as shown below.

Code: Select all

sceGumDrawArray(GU_SPRITES, GU_COLOR_8888 | GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D,2,0,l_vertices);
Then the alpha test works ?? Should there be any differences in using the 3D transform ??

This is really strange. Any comments or thoughts ?? Since I don't want to do the transforms my self :)
Br, Sandberg
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

I got 8888 alpha channels to work in 3D in my RoboTORN3D game. See http://forums.ps2dev.org/viewtopic.php?t=3391

I used the blend code

Code: Select all

sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0xffffffff, 0xffffffff);
And that I used GU_TFX_REPLACE instead of MODULATE. That means that lighting doesn't affect it, but that was the effect I was aiming for.
Try these parameters and see if they help.
Post Reply