本文介绍了问题与3D图元,XNA 4.0透明质感的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要画一个大集立方体,所有的(可能)每侧独特的纹理。一些纹理也具有透明度的部分。这是那些具有透明质感背后的冰块应通过透明的质感表现。然而,似乎在我画立方体的顺序决定是否透明工作或没有,这是我想避免的。看看这里:

I need to draw a large set of cubes, all with (possibly) unique textures on each side. Some of the textures also have parts of transparency. The cubes that are behind ones with transparent textures should show through the transparent texture. However, it seems that the order in which I draw the cubes decides if the transparency works or not, which is something I want to avoid. Look here:

cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"];

Block[] cubes = new Block[4];
cubes[0] = new Block(BlockType.leaves, new Vector3(0, 0, 3));
cubes[1] = new Block(BlockType.dirt, new Vector3(0, 1, 3));
cubes[2] = new Block(BlockType.log, new Vector3(0, 0, 4));
cubes[3] = new Block(BlockType.gold, new Vector3(0, 1, 4));


foreach(Block b in cubes) {
    b.shape.RenderShape(GraphicsDevice, cubeEffect);
}

这是在Draw方法的代码。它产生这样的结果:

This is the code in the Draw method. It produces this result:

如你所见,叶立方背后的纹理都没有对对方看到。当我数组中的反向索引3和0,我得到这个:

As you can see, the textures behind the leaf cube are not visible on the other side. When i reverse index 3 and 0 on in the array, I get this:

显然,图中的顺序是影响立方体。我怀疑它可能与混合模式做的,但我不知道从哪里开始的。

It is clear that the order of drawing is affecting the cubes. I suspect it may have to do with the blend mode, but I have no idea where to start with that.

推荐答案

您是依靠深度​​缓冲实现闭塞。这种技术只适用于不透明物体

You are relying on depth buffering to achieve occlusion. This technique only works for opaque objects.

要获得正确的咬合含有透明物体的场景:

To achieve correct occlusion for a scene containing transparent objects:


  1. 设置DepthBufferEnable和
    DepthBufferWriteEnable为true

  1. Set DepthBufferEnable andDepthBufferWriteEnable to true

绘制所有不透明几何

离开DepthBufferEnable设置为true,
,但改变DepthBufferWriteEnable为

Leave DepthBufferEnable set to true,but change DepthBufferWriteEnable tofalse

排序alpha混合对象从相机
的距离,然后绘制
他们为了从后向前

Sort alpha blended objects bydistance from the camera, then drawthem in order from back to front

深度提取分拣alpha混合对象肖恩哈格里夫斯

这篇关于问题与3D图元,XNA 4.0透明质感的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 08:23