Sign in to follow this  

Sorting transparent meshes (particularly trees, bushes and grass)

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

Hello, I have a little problem: I have my models separated into meshes, where each mesh has one material and some materials are blended. I implemented mesh sorting by distance computed each frame. Unfortunately, there are some artifacts. I've read about Radix sorting algorithm, but it is only for sorting numbers (strings), so how can I implement it for mesh sorting? Or is the better and easiest way for sorting meshes into correct order? Should I split mesh into triangles and render each separately by distance? Or get closest vertex from each mesh to camera and render this way? Btw I spent some time searching on the internet, on this forum, but i could not find much informations understandable for me :( Thanks a lot Stephe

Share this post


Link to post
Share on other sites
What do you mean by blended materials?
Materials with full transparent and full opaque parts? (You mentioned foliage in the title)

If so try using 'alpha testing' instead in the first round.

glAlphaFunc(GL_GREATER,0.5);
glEnable(GL_ALPHA_TEST);

and disable blending.

This way only parts with alpha > 0.5 will be draw in the frame-buffer and depth-buffer, so no need to do sorting.

Share this post


Link to post
Share on other sites
What you described is not blending. Blending is something like glass that can be seen through. Trees have leaves and blank space. There is no actual blending.

If you are using shaders you can check:
if(color.a < .001)
{
discard;
}

Share this post


Link to post
Share on other sites
What you described is not blending. Blending is something like glass that can be seen through. Trees have leaves and blank space. There is no actual blending.

If you are using shaders you can check:
if(color.a < .001)
{
discard;
}

Although I think what was previously suggested will work better.

Share this post


Link to post
Share on other sites
For foliage, the best way is to use alpha testing (either fixed function as szecs mentioned, or within a shader), with enabled alpha-to-coverage multisampling. The latter will give you nicely AA'ed edges, without requiring any sorting.

Share this post


Link to post
Share on other sites
Great, it works! I always thought, it is alpha blending => I always used to use glBlendFunc... I am happy that I dont need to sort these objects. Thanks

Share this post


Link to post
Share on other sites

This topic is 2959 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.

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