alpha blended quads obscure one another?

Started by
4 comments, last by deathkrush 16 years ago
I'm having an odd problem I couldn't find a reasonable solution to. I basically draw 3 quads on the screen and texture them with a tree texture and use alpha blending to make the black background trnasparent. All is good, but if looking at them from one angle, they obscure each other, while looking at them from the opposite angle everything is fine. Here are links to 2 images that will explain this better. Obscured: Not Obscured (viewing from opposite side): I found that if I turn off depth testing, the problem goes away, but that is not an option as the trees become indifferent to the z coordinates as you can imagine they draw through everything.
Advertisement
Two options: disable z-WRITES when you render the trees (continue to do z-testing), or leave z-writing enabled but enable alpha test so as to kill all pixels with alpha less than (some small alpha value here, e.g. 8).
Quote:Original post by emeyex
Two options: disable z-WRITES when you render the trees (continue to do z-testing), or leave z-writing enabled but enable alpha test so as to kill all pixels with alpha less than (some small alpha value here, e.g. 8).


Thanks! the z-writes method worked, I tried enabling alpha testing but my quads just disappear all together.

With alpha testing you should provide a small value in the range [0;1], so when emeyex mentioned 8 I guess he meant 8/255 ~ 0.3.

Note that with z-writes disabled you'll have to render the blended quads front to back or your trees could be rendered in the wrong order (the most distant tree covering the closest tree).

Disabling z-writes is mostly appropriate for additive blending (particle effects like fire) but not for vegetation. You really should try and use alpha testing or alpha-to-coverage.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Here is my tree routine:

void drawTree() {glEnable(GL_BLEND); // Enable BlendingglBlendFunc(GL_DST_COLOR,GL_ZERO); // Blend Screen Color With Zero (Black)	//glDepthMask(FALSE);//disable zwritesglEnable(GL_ALPHA_TEST);glAlphaFunc(GL_LESS, 0.3);glBindTexture(GL_TEXTURE_2D, texture[4]);	// Select The Mask TextureglBegin(GL_QUADS);          glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0, 0.0);    glTexCoord2f(1.0f, 0.0f); glVertex2f(150.0, 0.0);    glTexCoord2f(1.0f, 1.0f); glVertex2f(150.0, 250.0);    glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0, 250.0);glEnd();glBlendFunc(GL_ONE, GL_ONE);				glBindTexture(GL_TEXTURE_2D, texture[5]); // Select The Image Texture glBegin(GL_QUADS);       glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0, 0.0);    glTexCoord2f(1.0f, 0.0f); glVertex2f(150.0, 0.0);    glTexCoord2f(1.0f, 1.0f); glVertex2f(150.0, 250.0);    glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0, 250.0);glEnd();glDisable(GL_BLEND);glDisable(GL_ALPHA_TEST);}


With Alpha testing enabled nothing shows up :(
Does the texture have a proper alpha channel? I think it's required for alpha testing.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)

This topic is closed to new replies.

Advertisement