Jump to content
  • Advertisement
Sign in to follow this  
iedoc

masking/blending

This topic is 3906 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

hey, i finally got all this blending masking stuff down, but i just now realized i have a little problem. i masked a tree and it turned out perfect, but now when i go behind the wall or whatever, it stays in my view. i don't think it should be that big of a problem, but any help at all would be very much appreciated, thank you!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by iedoc
hey, i finally got all this blending masking stuff down, but i just now realized i have a little problem. i masked a tree and it turned out perfect, but now when i go behind the wall or whatever, it stays in my view. i don't think it should be that big of a problem, but any help at all would be very much appreciated, thank you!
What graphics API are you using? How are you doing the masking?

Share this post


Link to post
Share on other sites
I'm using opengl

first ones the mask, second ones the tree

glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);

glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
glBindTexture(GL_TEXTURE_2D, texture[2]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(10.1f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(10.1f, 10.1f,0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 10.1f, 0.0f);
glEnd();

glBlendFunc(GL_DST_COLOR, GL_ZERO);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(10.1f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(10.1f, 10.1f,0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 10.1f, 0.0f);
glEnd();

glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);

Share this post


Link to post
Share on other sites
Well, at the start you disable depth testing, so the tree gets drawn regardless of what's in front of it. I think you meant to disable depth writes however.

Share this post


Link to post
Share on other sites
shoot, i have another problem on this subject. now i have a list of trees, and it works all good and stuff, but when i look at trees one way, the trees behind it show up in front of it, but if i look at the trees from the other way, its fine, the trees behind don't show up. what could be causing this and what can i do to fix it?

Share this post


Link to post
Share on other sites
Woops, I forgot to mention that in my last post. This one's a bit tougher. The problem now is: the trees are drawn one after the other in no particular order. OpenGL doesn't care about sorting transparent primitives, it just draws them in the order you pass them. There are several solution (out the top of my head) to solve this, but all are a bit more involved:
1) The most prominent solution is to sort the trees yourself by distance from the camera and draw them in far to near order (first draw the tree that's farthest from the camera, all the way up to the nearest tree).
2) Depth peeling, but its benefits on mainstream GPUs are small compared to its cost.
3) Alpha masking or even better: alpha dithering. Many good things have been written on these subjects, but I'll just link you to a paper I myself like. There's also excellent reading material in the GPU Gems-series of books.

Cheers.

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!