OpenGL Alpha Test Leaves Sharp Edges

Started by
18 comments, last by soconne 20 years, 3 months ago
I''m trying to render bushes and trees in a terrain game I''m working on and I''m getting really crappy results. I load a bmp file into an array, create an alpha component, and set the alpha to 0 where ever there is white, and 255 elsewhere. I then call: glAlphaFunc(GL_GREATER, 0); glEnable(GL_ALPHA_TEST); But here''s what I get http://cs.selu.edu/~soconnell/images/sample.JPG What I want is something like this taken from the Unreal2 Engine Runtime demo http://cs.selu.edu/~soconnell/images/sample2.JPG How can I get those nice smooth eges on all the leaves like the Unreal2 Engine does? Anybody know of the way they do it? I''ve tried blending using the alpha component and even blending in the white, but I get crappy results. I''d like to get those smoooth edges Unreal2 and many other games get. I don''t think they have to sort the geometry, do they?
Author Freeworld3Dhttp://www.freeworld3d.org
Advertisement
that kinda thing is done via blending, generaly with a gradual blend from one alpha value to another and not a simple ''yes, no'' affair like you have.

And yes, they would sort the alpha blended stuff
If they are doing a ''gradual'' blend then they would get gradual blend in the picture, but they don''t. They simply have a hard edge.

Has anybody done this themselves?
Author Freeworld3Dhttp://www.freeworld3d.org
Remember that as well as texture colours being smoothed with bilinear filtering (or whatever) so is your alpha component in the texture. So change to glAlphaFunc(GL_LESS, 0.5), which will generate a smooth edge inbetween the green and white texels. And since you don''t need blending you don''t have to sort them either.

Although you''ll get the white bleeding onto the edges of your leaves then, so loading an image (like .png) where you can create an alpha channel separate from your colours lets you paint the green over the edge to stop that.

If you don''t have anything handy to load pngs then you can load a regular bmp and a greyscale one, then combine them as one texture, taking the greyscale as the alpha intensity.

quote:Original post by oconnellseanm
If they are doing a ''gradual'' blend then they would get gradual blend in the picture, but they don''t. They simply have a hard edge.


I dare say if you looked hard enuff you''d see a slight blend, maybe only 2 texels or so

Hey thanks a lot guys. I tried using 0.5 instead of 0, and not it looks A LOT better.
Author Freeworld3Dhttp://www.freeworld3d.org
quote:Original post by _the_phantom_
quote:Original post by oconnellseanm
If they are doing a ''gradual'' blend then they would get gradual blend in the picture, but they don''t. They simply have a hard edge.


I dare say if you looked hard enuff you''d see a slight blend, maybe only 2 texels or so

And I dare say that those two texels blending are not the result of drawing the gemoetry blended, but because Unreal2 has some nice FSAA enabled



Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

i got the same problem some time ago, fixed it with blending, i just REPLACED glAlphaFunc(..) + glEnable(GL_ALPHA_TEST) with this:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
I had also tried that but didn''t get desireable results. You should try calling glAlphaFunc with 0.6 or more for the alpha, it works awsome for me now. All the edges of leaves and bushes look great!
Author Freeworld3Dhttp://www.freeworld3d.org
Actually, that U2 shot uses both blending and alphatest, and no FSAA. Look at the spot near the middle of the left edge, where you can see the sandy beach between the leaves. You can clearly see the seam between yellow beach and green grass through the leaf on the left. Also at the bottom left corner some of the closest leaves are obviously translucent (near the edges), especially the dark leaf in the very front with a little hole and a protrusion to the left.

My guess is it''s an artistic choice to make the leaves blend into the background a little while avoiding the "square blur" of non-alphatested blending at the edges. That means the polygons must be sorted.

Blending is also useful if you want to fade out "detail plants" at a distance. Notice there''s no foliage visible on the other side of the river. Perhaps they use alpha to fade things in as you get closer.

This topic is closed to new replies.

Advertisement