Jump to content
  • Advertisement
Sign in to follow this  
Brigs

alpha blended quads obscure one another?

This topic is 3826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Here is my tree routine:



void drawTree() {

glEnable(GL_BLEND); // Enable Blending
glBlendFunc(GL_DST_COLOR,GL_ZERO); // Blend Screen Color With Zero (Black)

//glDepthMask(FALSE);//disable zwrites

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_LESS, 0.3);

glBindTexture(GL_TEXTURE_2D, texture[4]); // Select The Mask 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();

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 :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!