Sign in to follow this  
mede

Blending for Tree with alpha mapped leafs

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

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