Help in blending

Started by
15 comments, last by fazekaim 19 years, 8 months ago
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.
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.
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?
hello ... how are you ?
go see nehe tutorial num #8 it will help you

bye !
ff8
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.
OK, sorry.

I missunderstood.

Thanks.
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

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.
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
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.

This topic is closed to new replies.

Advertisement