Sorting transparent meshes (particularly trees, bushes and grass)

Started by
4 comments, last by stephe 14 years, 5 months ago
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
Advertisement
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.
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;
}

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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

This topic is closed to new replies.

Advertisement