Now i'm stuck :)

Started by
14 comments, last by Lord_Evil 14 years, 7 months ago
Damn i forgot what was the proper Blending to be used in this situation..?

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        RENDER_gameobjects(1);
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);



Why do i see those tiny borders around the leafs which have other leafs in the background...
Xynapse | http://szczerbiec.net/
Advertisement
The image link is invalid.
Do you sort and render your leafs in correct order?
Hmm... For such things as leaves, with large regions that are either fully transparent or fully opaque, and only small regions that are semi-transparent, I seem to recall (and I'll warn you that I may be mis-remembering to some degree) seeing a method that only writes to the depth buffer when the pixel is full opaque, with depth testing on. This is, of course, technically inaccurate, but with such small regions of semi-transparency, and of presumably fairly similar colour, it might well not be terribly noticeable.

How to implement this method in OpenGL I'm afraid that I don't know, offhand. ^^;

Note that I'm afraid that, like Brother Bob, I don't see your image, and so don't know how applicable this might be to your case.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

http://lh6.ggpht.com/_1R4EwDkKW0E/SqjlUWsMTVI/AAAAAAAABMA/DKCzVxc4OUw/blenderror.jpg

Sorry, bout the image - dunno why picasa does not show up those images correctly... try with the link
Xynapse | http://szczerbiec.net/
Your textures are wrong. (Your code is fine I think)
Use photoshop, and replace the blue (or white?) background color of the texture with the color of the edges of the leave (green).

Edit: do you use alpha testing? You have already solved that problem in an other thread as I recall.
glAlphaFunc(GL_GREATER,0.5)
With blending you'd need to render the leaves in the correct order - back-to-front.

You could use alpha-to-coverage to overcome that limitation with aceptable visual results. Another approach could be a method developed by valve which they use to render alpha-tested text smoothly. I don't remember the name, however. Maybe someone can fill in that gap.
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!
Quote:Original post by szecs
Your textures are wrong. (Your code is fine I think)
Use photoshop, and replace the blue (or white?) background color of the texture with the color of the edges of the leave (green).

If you look at the picture, you can see that the errors are only located above the horizon. Also, the errors are not everywhere, only on some leafs, while others blend correctly with the background (see the large bottom-most leaf touching the ground on the front tree for example). The bright border is most likely the sky, not the "key color" of the texture.
The reason why i am asking is that i need to proove to my gfx team that they to the textures incorrectly.

I have kinda sorted that out by:

	glEnable(GL_TEXTURE_2D);	glEnable(GL_ALPHA_TEST);	glAlphaFunc(GL_GREATER,0.05); 		glEnable(GL_BLEND);	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    RENDER_gameobjects(1);	glDisable(GL_BLEND);	glDisable(GL_ALPHA_TEST);	glDisable(GL_TEXTURE_2D);


They are rendered properly now.

Thanks to all of you guys
Xynapse | http://szczerbiec.net/
Quote:Original post by szecs
Your textures are wrong. (Your code is fine I think)
Use photoshop, and replace the blue (or white?) background color of the texture with the color of the edges of the leave (green).

The problem can't be solved with changing the textures alone. If a leaf is blended with the scene the current color of the back buffer added to the result. Now if you render a fron leaf first the sky/background will be blended with the leaf at its border.

When you render a leaf that is (partially) behind the first one it won't be blended at the first one's border because the depth value of the first leaf's border is already written and thus the fragment of the second leaf is discarded.

Example (upper case letter means opaque, lower case letter means transparent):
00000000011111111234567890123456 //column----------------BBBBBBBBBBBBBBBB //background (depth = 1.0)    sSSSSSSSs    //second leaf (depth = 0.5)      fFFFFFf        //first leaf (depth = 0.3)


Now look at column 09:

When you render the first leaf, the color is a combination of B and f (Bf).
The depth is now 0.3, so rendering the second leaf would discard the S color and the color would still be Bf. The final result would then be:

00000000011111111234567890123456 ----------------BBB     B   BBBB          SSSs          fFFFFFf        


Rendering in correct order (with blending) would result in:
00000000011111111234567890123456 ----------------BBB         BBBB         SSSSs          fFFFFFf        

Note that the color at column 09 should be Sf instead of Bf.
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!

This topic is closed to new replies.

Advertisement