# Now i'm stuck :)

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

## Recommended Posts

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

##### Share on other sites
Do you sort and render your leafs in correct order?

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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)

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by szecsYour 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.

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by szecsYour 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.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 45
• ### Forum Statistics

• Total Topics
632635
• Total Posts
3007566
• ### Who's Online (See full list)

There are no registered users currently online

×