Sorting Alpha Blended Polys... Still Necessary?

Started by
8 comments, last by Th0ughtCr1me 17 years, 5 months ago
Hi All, Is it still necessary to sort alpha-blended polys, or is there a better way of doing in on new graphics hardware. I have some trees that have alpha blending for the leaves, but depending on the draw order of the polys the wrong background can show through because of the z-buffering. How is this handled these days? Is a sorting algorithm still necessary? Do you really have to sort the individual polys in the tree model? Seems a little expensive. Thanks! Rael
Advertisement
1. render the static non alpha geometry

2. enable color writing

3. render the leaves again with the appropriate depth func

as long as you don t have semitransparent leaves everything will be fine
http://www.8ung.at/basiror/theironcross.html
For the general solution, sorting is still necessary (and probably will be for the foreseeable future). It is expensive, and that is why you don't see trees with lots of individual leaves. However, for some particular cases, there are optimizations that also work reasonably well.

If your leaf textures have alphas of either 0 or 1, then alpha-test will work just fine and you don't need to sort. Otherwise, you might try using alpha-test and dithering in place of true alpha-blending. It is a technique used for drawing grass and it works very well (for grass).

Basiror, I've seen the z-only pass technique used to reduce pixel processing, but how does your technique help here?
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
You can do two passes for leaves: 1) render the opaque parts by using alpha testing where alpha is greater then some threshold T (say 128). Make sure ztest and zwrite are both on and alphablending is off. 2) render the translucent part of the leaves with alpha test set to less then T with zwrite off and alpha blending on.

This will cause only the translucent edging of the leaves to have sort errors (and only with translucencies if rendered after other opaque geo), which is usually very small and harder to notice.
Thanks for the tips. I'll probably just go with a simple alpha bit test for now then, and leave the blending until later. I've plenty of other stuff like GUI and scripting to add before adding the bells and whistles.

Thanks!
Rael
Quote:Original post by JohnBolton
For the general solution, sorting is still necessary (and probably will be for the foreseeable future). It is expensive, and that is why you don't see trees with lots of individual leaves. However, for some particular cases, there are optimizations that also work reasonably well.

If your leaf textures have alphas of either 0 or 1, then alpha-test will work just fine and you don't need to sort. Otherwise, you might try using alpha-test and dithering in place of true alpha-blending. It is a technique used for drawing grass and it works very well (for grass).

Basiror, I've seen the z-only pass technique used to reduce pixel processing, but how does your technique help here?


You need to render the scene geometry first before rendering any alpha pass

as for the rest I missed it to mention the alpha test, sorry for the confusion

1. render static scene
2. enable alpha test
3. render leaves

Leaves usually don t have semi transparent pixel, so alphatesting will indeed do the job


Another thing I could think of

1. render static scene
2. enable alpha test
3. render leaves
4. enable alpha test & skip those pixels usually visible & disable color writes
5. render the leaves' polygons again
Now you have the depth information of the semi transparent pixels of the leaves
6. enable color writing & depthfunc( EQUAL)&same alpha test setting as in 4.
7. render the leaves again
Now you render those semi transparent parts of the leaf

This will work for the boundary leafs of the tree, e.g.:
you have a stam and a round top full of leaves

looking right to the center of the top you will hardly notice a difference since it should be pretty obaque this in comparsion to the background

looking at the sides of the leaves the semi transparent pixel of the polygon nearest to you will be visible

Those parts further away aren t

I haven t tested this but it might work.

http://www.8ung.at/basiror/theironcross.html
If you're using alpha testing, you don't have to treat any of the geometry any differently than geometry with fully opaque texturing.

If you're using alpha blending, then you either have to accept some artefacts, or do sorting. My general rule is that most people don't really notice the details of artefacts for depth complexity > 2, so my solution just deals with getting dc<=2 right.
You need the depth pass in order to render the alpha blended faces that are nearest to you correctly
http://www.8ung.at/basiror/theironcross.html
Quote:Original post by Basiror
You need the depth pass in order to render the alpha blended faces that are nearest to you correctly

If the leaves do not have "semi"-transparent pixels, then a single pass with alpha-test will work just fine. There is no need for a depth pass.

If the leaves do have "semi"-transparent pixels, then a depth pass will cause the transparent pixels of the closest leaves to blend with whatever is behind the tree (instead of with the other leaves behind them), and that will look no better than doing a single unsorted pass.

So, I still don't understand the purpose/benefit of the depth pass.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Though OpenGL biased, I like this paper:

linky
_______________ Play my Game at neonswarm.com

This topic is closed to new replies.

Advertisement