Skip to main content
GameDev.net gamedev.net
🔒 Locked

Point sprite alpha (DirectX 9 C++)

Started by GLForce Jan 7, 2006 at 7:05 PM 4 replies 3.8k views
Original Post
GLForce
GLForce
I have problems with point sprites. I've followed the sdk code and all worked fine, if you look at the point sprites alone. Because with the rest of the objects in ym engine, there is problem. Transperency seems to work in a strange way. Alpha states are set the same way that in the sdk code (D3DBLEND_ONE), and again it works alone. The problem is that it screws up when crossing with textured polygons with colorkey alpha. The "invisible" square of those transparent polygons get over the point sprite and erase it. It is hard to explain. To make it brief, i see a colored particle with a big transparent square in the middle. It seems to have a certain link with zwrite (in the code it is desactivated to avoid certain problems). I put the point sprites rendering after all other rendering, to make it works. But it does what i stated before. The problem is solved by rendering them before the textured polygons, but then the point sprites are always behind those polygons, wich is not always wanted. Ive put a screen shot to clarify it : http://killergl.pingouin.ca/psprite.JPG As you see, the crosshair in the middle is a textured polygon with colorkey alpha. The blue thing is a point sprite. And as i said the transparency does a strange thing and so we can see trough the point sprite at the grass texture. All this long text to say this : I do not necessarky want to solve this particular problem. What i would like is a clear tutorial (or commented code, or even not commented) to implement point sprite in a complete engine. Not just showing particles alone on a dark background. You understand ? Thanks.
"Do, or do not. There is no try." - Yoda
ViLiO
ViLiO
Hi,

Are you drawing the crosshair before or after the point sprites? Because you should be drawing all HUD/GUI elements last.

All the best,
ViLiO
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
Valor Knight
Valor Knight
Draw the sprites last so they blend on top of everything
There is no life without honor
GLForce
GLForce
I know that, i written it, that actually solve the problem. And it is ok for GUI elements because the particles are drawn behind the sprite. The problem is with things like billboard, wich even if they are in "2D" are 3d element of the scene and should be behind or in front of the point sprite according to their z values, you undertsand ? In this case the particle are always behind wich is strange in some situation (take for example a tree, with a fire before it that appear over the trunk but behind the leaves that are billoarded)
"Do, or do not. There is no try." - Yoda
pcwlai
pcwlai
I don't understand what your problem is from your description because I am not native English speaking. Though, from your screen short, I guess (as from my past experience), this is because of the transparence problem with anti-aliasing.

When you use color key to archieve transparence, DirectX will give the texture alpha channel. Map each pixel's alpha with respect to color key matching. When anti-aliasing is turned on for texturing (including mip-map filtering), alpha channel is anti-aliased (filtered) as well. This gives incorrect alpha values on hard edges (because of color key). When many transparent objects are drawm, the problem occurs.

I figureed out 3 ways to solve this. First is turn off filering. Second is to not use color key and supply the texture in full ARGB format with solve alpha edges (or hand tuned alpha channel). Third is to use alpha testing and set a relatively large value (around 0x64) to filter out those troublesome pixels).

Hope this helps. Or some other people can supply other better ways to solve it.
The poorest programmer in the game industry!!
GLForce
GLForce
Wow.

You certainly had difficulty to understand me because english is not my native language too (see, i'm from quebec canada, yeah i'm a "french canadian" as you call us).

And thank you. Your solutions work great. I've tried both desactivating filtering and adding alpha test. Both work. Now i wonder wich is more performance friendly. Assuming i'm desactivating and re-activating filtering at each pointsprite render call, and that from what i undertsand of alpha testing it tests each pixel, wich one should i choose ?

Thank you again.

Oops, i was wrong, desactivating filtering doesn't work. But my question is still good : Will alphatesting reduce performance ?

[Edited by - GLForce on January 8, 2006 10:33:19 AM]
"Do, or do not. There is no try." - Yoda

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.