Jump to content
  • Advertisement
Sign in to follow this  
fazekaim

Help in blending

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

Hello, I have blending problem presented with these pictures http://delfin.klte.hu/~fazekaim/tree2.jpg http://delfin.klte.hu/~fazekaim/tree1.jpg So, I execute this statements: gl.glEnable(GL.GL_BLEND); gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ); ... drawing the tree and as You can see, the tree's bark is visible behind the leaves, but the other leaves aren't. Any idea could be helpfull. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Either disable depth writes while drawing the leaves (and make sure you draw the leaves last), or use alpha test to completely reject fragments outside the leaves instead of drawing them as transparent pixels.

Check out glDepthMask and/or glAlphaFunc. You don't need both in this case, one of them is enough.

Share this post


Link to post
Share on other sites
If I disable depth functions, I see all background leaves behind all points of every leaf.
My problem is, that where the leaf texture is transparent, only the bark that I can see.

Thanks a lot, by the way.

How cam the alphafunc solve my problem?

Share this post


Link to post
Share on other sites
hello ... how are you ?
go see nehe tutorial num #8 it will help you

bye !
ff8

Share this post


Link to post
Share on other sites
I didn't say you should disable depth test, I said depth writes. Depth testing should be enabled.

Alpha test is probably the easiest way, assuming the alpha channel in the leaf texture is either 0 or 1 for leaf/no leaf. Then you could set the alpha function to drop every fragment with alpha not equal to 1. That way, the parts with no leaf at all will not be drawn at all. Using alpha blending, the leaf is still drawn although you won't see the parts outside the leaf, but the depth buffer will be updated.

Share this post


Link to post
Share on other sites
Brother Bob: The ALPHA_TEST resolved my problem. Thanks.
But, a new one is on: using glBlendFunc, I can blend the leaves normally, but with alpha testing, every leaf has a little white silhouette.

http://delfin.klte.hu/~fazekaim/c.jpg

Share this post


Link to post
Share on other sites
I think the borders looks a little bit too big to be what I think it is. The problem is, I think, that you don't set the alpha test to pass fragments with an alpha of 1 only, no other fragmens should pass. Try set the alpha function to GL_EQUAL with reference 1 and see if the white edge dissapears.

Otherwise, post a link to the leaf texture so I can have a look at it, because, sa I said, the white edge looks a little bit different than I would expect if this is the problem.

Share this post


Link to post
Share on other sites
With GL_EQUAL, the borders disappear, but from a long distance a leaves disappear too. Mipmapping could be the reason?

http://delfin.klte.hu/~fazekaim/equal1.jpg
http://delfin.klte.hu/~fazekaim/equal2.jpg
http://delfin.klte.hu/~fazekaim/equal3.jpg

Share this post


Link to post
Share on other sites
Ok, then it was as I thought then. Yes, mipmapping is why the leaves gets smaller. Or rather, bad mipmap levels, not mipmapping itself. Using a standard box-filter or so (pretty much what gluBuild2DMipmaps and SGIS_generate_mipmap uses) to generate lower mipmap levels is, generally, not going to work well with this technique. You have a few options.

The simple solution is; don't use mipmaps. Just use the base level and GL_LINEAR for filtering.

You can also choose a different color outside the leaf, a color that matches the color of the leaf itself. Instead of white, choose a orange-brown color, so that the edge that was white now is a part of the leaf, so to speak. Then you can set the alpha test reference to something other lower 1.

However, this also means the image itself must have an alpha channel of the leaf's shape. You can't use a color key to create the alpha channel when loading the texture, since the color key would be the same as the leaf color.

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!