Point sprites and alpha blending issue

Member
Posts: 86
Joined: 2008.04
Post: #1
I have a bunch of point sprites that I am alpha blending around a sphere...
The sprite itself is a round yellow ball surrounded by empty alpha.

The problem is that sometimes the transparent edges of the underlying sphere "bleed" through and cover other sprites.
[Image: alpha.png]

Sometimes it works sometimes it doesn't (look at morocco versus congo)

Here is a snippet
Code:
    glBindTexture(GL_TEXTURE_2D, [glowTexture name]);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    
    glEnable(GL_POINT_SPRITE_OES);
    glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE);
    glPointSize(32.0f);


Thanks for any help
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
Looks like a drawing order problem. Although blending allows fragments that have already been drawn to show through part of your sprite, the area of the entire sprite still gets written to the depth buffer. If you try to subsequently draw another one behind it with depth testing enabled, the depth test will fail and you'll see results like the ones in your screenshot. Presumably, some of them are drawing correctly because they happen to be in back-to-front order in eye space.

The general solution to this is to sort your objects from furthest to nearest in eye space before drawing. This way, every blend operation takes place in front of the previous ones, and the depth test passes in all the places you want it to.
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Post: #3
Another way without sorting is to turn off writing into the depth buffer for your alpha-blended sprites. The downside being that you then can't depth test against those sprites (not usually an issue).

Code:
// Draw planet here

glDepthMask(GL_FALSE); // Turn off depth writes

// Draw sprites here

glDepthMask(GL_TRUE); // Turn back on depth writes
Quote this message in a reply
Member
Posts: 86
Joined: 2008.04
Post: #4
Let me just say that you guys are awesome :-)

That is exactly what the problem is and it works like a charm now....
I never thought of disabling the depth write...sheer genius ;-)

BTW - Is alpha blending preferred over alpha testing on the iphone in terms of performance?


Thanks again for your help
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #5
OptimisticMonkey Wrote:BTW - Is alpha blending preferred over alpha testing on the iphone in terms of performance?

Yes. I don't remember the specifics, but it has to do with the way the iPhone tile-based rendering works that somehow makes alpha testing horribly expensive.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Problem displaying point sprites Duddd 0 1,989 Feb 12, 2010 02:45 AM
Last Post: Duddd
  OpenGL ES alpha blending gizzerd91 7 8,737 Jul 29, 2009 08:11 AM
Last Post: gizzerd91