• Advertisement
Sign in to follow this  

Blending for Tree with alpha mapped leafs

This topic is 2686 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

Hey folks

I'am trying to render some low polygon trees composed of planes with a alpha mapped leaf on it. So i have to use blending.
No I have the problem, that it is not possible to render the leafs ordered, so I get wired results with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). I tried now many different settings but I diden't get a useful result. Is there a good solution for this problem ?

p.s. i use a glsl shader for rendering where I use the texture alpha channel as gl_FragColor.a.

Share this post


Link to post
Share on other sites
Advertisement
jep but this gives even more wired results because then the trees and the terrain has no more z-ordering

Share this post


Link to post
Share on other sites
You need to turn on z-testing as well.
However, enabling z-testing will only reduce this artifact, not eliminate it -- you will still have some of these "missing pixels" in small areas around the edge of the leaves.

You can fix that by turning off alpha-blending, and just using alpha-testing...
However, without alpha-blending, you'll have jagged edges. You can fix that by enabling alpha-to-coverage in conjunction with MSAA.

N.B. you can implement alpha-testing in your shader with something like:
float ref = 0.0; // alpha reference
if( texture.a <= ref ) discard; // alpha test


An alternative approach that I read recently is to render the background and your trees to separate render-targets and then composite them.

Share this post


Link to post
Share on other sites
hm so this would be a solution:

- disable Blending, enable Depth Test
- rendering terrain

- enable blending, disable Depth Test
- rendering trees ordered from far to near

Share this post


Link to post
Share on other sites
yea the simple alpha test in the shader gives quite good results. thx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement