在XNA中对网格进行排序 [英] Sorting meshes in XNA

查看:115
本文介绍了在XNA中对网格进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XNA中的树有问题.当我有树时,我需要使用alpha混合使非叶子部分透明,但是模型的某些部分无法正确显示,因此alpha混合失败.我想知道是否有可能读取网格位置来对它们进行排序,或者是否有其他方法可以使透明的非叶部分成为可能. 对模型进行排序可能无法正常工作,因为我想从各个角度来看这棵树.

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.

推荐答案

在3D环境中进行Alpha混合可能是一个棘手的问题.肖恩·哈格里夫斯(Shawn Hargreaves)撰写了文章涉及大多数主要问题(画家的算法部分专门针对您的问题).长话短说:没有一种技术可以完美地完成您想要的事情,所以问题就变成了:您愿意做出什么权衡?

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?

进行alpha测试而不是进行alpha混合可能是最简单的解决方案.这是一个二进制测试,其中出现或不出现不透明的像素,因此这些像素的绘制顺序基本上无关紧要.这将为您提供坚硬的边缘,但是如果您的纹理具有足够的分辨率,它仍然可以看起来非常不错.我知道《魔兽世界》使用了这种技术,而且我很确定自己记得在《暗黑破坏神III》中看到过这种技术.

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.

您可以使用内置的AlphaTestEffect进行此操作,也可以自己在像素着色器中实现.

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

这篇关于在XNA中对网格进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆