Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

soconne

OpenGL OpenGL Alpha Test Leaves Sharp Edges

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!