Sign in to follow this  
dirtysanchez

Now i'm stuck :)

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 this post


Link to post
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 this post


Link to post
Share on other sites
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)

Share this post


Link to post
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
Share on other sites
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):

0000000001111111
1234567890123456 //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:


0000000001111111
1234567890123456
----------------
BBB B BBBB

SSSs

fFFFFFf


Rendering in correct order (with blending) would result in:

0000000001111111
1234567890123456
----------------
BBB BBBB

SSSSs

fFFFFFf

Note that the color at column 09 should be Sf instead of Bf.

Share this post


Link to post
Share on other sites
Strange, I worked with alpha tested trees etc. and I never had that problem. I used
glAlphaFunc(GL_GREATER,0.5), turned blending OFF, and painted the background green. With 0.5, you wont get so rugged jaggies, if you don't like the result, you can use higher resolution textures.

EDIT: But if you want to let it blended at the edges, than you have to sort the leaves by depth.

(If I miss or misunderstood something, than sorry.) Now I see, but try disabling blend anyway.
/EDIT

Share this post


Link to post
Share on other sites
szecs - this is true,
when i disable blend and go into Alpha > 0.5 it is not doing any order problems, but the textures then have to be really well prepared.

This is why i'll probably switch from blending to Alpha tests.

Anyways, no need to go with this thread further - lemme do the alpha tests and forget about the problem ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this