I am trying to render a semi-transparent surface, by using convert image to set the alpha to 0x11 (just as a test), but the texture always displays fully opaque, not partially transparent. I do not have the alpha channel testing function on, and I am using the TCC_RGBA flag, and have tried all the texture effect flags with no avail.
Has anyone got a texture to render with translucency? Can anyone help?
EDIT: I think that it may have something to do with sceGuBlendFunc(), but can't quite work out what.
RGBA rendering not working
You're on the right track atleast.
To do alpha-blending, you must first enable it using sceGuEnable(GU_BLEND). Next, you have to sample the texture properly (as you already do) using GU_TCC_RGBA. Also make sure you use a texture effect that treats the alpha properly, or you'll scratch your head a bit there aswell. Next, setup the blend-function using sceGuBlendFunc(). If everything goes to plan, you should have a partially transparent primitive on screen.
Have a look at the primitive blend-sample in the SDK at samples/gu/blend. It should give you an idea how to do it.
To do alpha-blending, you must first enable it using sceGuEnable(GU_BLEND). Next, you have to sample the texture properly (as you already do) using GU_TCC_RGBA. Also make sure you use a texture effect that treats the alpha properly, or you'll scratch your head a bit there aswell. Next, setup the blend-function using sceGuBlendFunc(). If everything goes to plan, you should have a partially transparent primitive on screen.
Have a look at the primitive blend-sample in the SDK at samples/gu/blend. It should give you an idea how to do it.
GE Dominator
-
- Posts: 197
- Joined: Fri Jul 01, 2005 2:50 am
Well, I've been working on this, but can't quite get it to work. The complication, I believe is this: all my textures need to be lit, so I need to use GU_TFX_MODULATE, but when I do that, all the objects that share the same texture and vertices can be seen through each other. E.G. All the enemies are the same model, and they are partly transparent, but the only thing that you can see through them are other renders of the same models(more enemies), so you can't see the walls/shots through them. The main confusing part is that the effect is the same for all objects, whether they have a partially transparent alpha channel or not.
It's difficult to explain. Sorry.
It's difficult to explain. Sorry.
Those problems come from the order you render your objects.
For alpha blending to work correctly (and this applies to every platform except the dreamcast), you have to:
1. Render all opaque objects.
2. Make a list of your visible alpha blended objects. Roughly sort it by Z (a single iteration of a bubble sort of this object list per frame, if you keep it between frames, should be good enough, that's O(n))
3. Render your list of alpha blended objects, farthest first, nearest last.
For alpha blending to work correctly (and this applies to every platform except the dreamcast), you have to:
1. Render all opaque objects.
2. Make a list of your visible alpha blended objects. Roughly sort it by Z (a single iteration of a bubble sort of this object list per frame, if you keep it between frames, should be good enough, that's O(n))
3. Render your list of alpha blended objects, farthest first, nearest last.
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come.
-
- Posts: 197
- Joined: Fri Jul 01, 2005 2:50 am
Ok, I've got it to work now, the problem was rendering the alpha'ed parts too soon, and so when I put them to the end, It works fine (because my billboards were already in Z-Order). I now have it reading the RGB from one file and the Alpha channel from another file, so now it's all nice and smooth.
I might as well ask my next question here: I am trying to get a 2D layer to go over my game for the HUD and other things, I've setup the 512x512 texture exactly like the sample, but I need to know what sort of unsigned short will control the 4444 colour palette properly. Is it in the format 0xffffff? or do you need to use a bit-shifting macro? What I would like to know is if I want to set one of the pixels to colour ARGB 255,100,200,100 , how would I do that using the 4444 palette?
Thanks.
I might as well ask my next question here: I am trying to get a 2D layer to go over my game for the HUD and other things, I've setup the 512x512 texture exactly like the sample, but I need to know what sort of unsigned short will control the 4444 colour palette properly. Is it in the format 0xffffff? or do you need to use a bit-shifting macro? What I would like to know is if I want to set one of the pixels to colour ARGB 255,100,200,100 , how would I do that using the 4444 palette?
Thanks.
-
- Posts: 197
- Joined: Fri Jul 01, 2005 2:50 am