Sorting meshes in XNA

蓝咒 提交于 2019-12-23 15:33:57

问题


I have problem with trees in XNA. When I have tree, I need to use alpha blending to make non-leaf parts transparent, but some parts of model are not correctly displayed and thus alpha blending fails. I want to know if there is possibility to read mesh position to sort them or is there any other way to have transparent non-leaf parts. Sorting in model probably won't work because I want to look at this tree from all angles.


回答1:


Alpha blending in a 3D environment can be a tricky issue. Shawn Hargreaves wrote an article several years ago that touches on most of the major issues (the section titled Painter's Algorithm deals with your question specifically). Long story short: there exists no technique to do what you want perfectly, so the question becomes: what trade-offs are you willing to make?

Doing alpha testing rather than alpha blending may be the simplest solution. It's a binary test, where an opaque pixel either appears or doesn't, so the order in which those pixels are drawn is largely irrelevant. This will give you hard edges, but it can still look pretty good if your textures have enough resolution; I know World of Warcraft uses this technique, and I'm pretty 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.




回答2:


What you're looking for is called order indepdendent transparency and this can be achieved using a method called "Depth peeling". If you are NOT using the Reach profile of XNA and can write custom shaders - you can implement this technique to achieve correct blending without worrying about mesh level information or having to re-sort them for the current frame/view.

Here is one more DX9 (but easily adapted to XNA) implementation.



来源:https://stackoverflow.com/questions/13938674/sorting-meshes-in-xna

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!