XNA grid sorting

I have a problem with trees in XNA. When I have a tree, I need to use alpha blending to make the transparent parts without leaves, but some parts of the model do not display correctly, and thus alpha blending fails. I want to know if it is possible to read the position of the grid in order to sort them, or is there another way to have transparent non-leaf parts. Sorting in the model will probably not work, because I want to look at this tree from all sides.

+4
source share
2 answers

Alpha blending in a 3D environment can be a difficult problem. A few years ago, Sean Hargreaves wrote an article article covering most of the main issues (a section called Animal Algorithm (your question specifically). In short: there is no technique to do what you want perfectly, so the question is: what compromises are you willing to make?

Performing alpha testing, rather than alpha mixing, may be the easiest solution. This is a binary test in which an opaque pixel appears or not, so the order in which these pixels are drawn does not really matter. This will give you hard edges, but it can still look pretty good if your textures have sufficient resolution; I know that World of Warcraft uses this technique, and I'm sure I remember seeing it in Diablo III.

You can use the built-in AlphaTestEffect to do this, or implement it yourself in a pixel shader.

+1
source

What you are looking for is called independent order transparency, and this can be achieved using the Peeling Depth method. If you DO NOT use a Reach XNA profile and can write custom shaders, you can implement this technique to achieve the right mix without worrying about the information grid level or re-sort them for the current frame / view.

Here is another implementation of DX9 (but easily adapted to XNA).

0
source

All Articles