我在XNA上遇到基元问题。正如您在链接http://imgur.com/12UTd2s中看到的那样,一些纹理墙是透明的,有些不是。有人可以解释为什么会发生这种情况并帮助我找到解决方案吗?
这是透视墙宣言:
testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 0, z2), new Vector3(1, 0, 0), new Vector2(0,0)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 0, z2 - 50), new Vector3(1, 0, 0), new Vector2(1,0)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 20, z2), new Vector3(1, 0, 0), new Vector2(0,1)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 20, z2), new Vector3(1, 0, 0), new Vector2(0,1)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 20, z2 - 50), new Vector3(1, 0, 0), new Vector2(1,1)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 0, z2 - 50), new Vector3(1, 0, 0), new Vector2(1,0)));
这里是我无法透露的隔离墙宣言:
testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 0, z1 - 50), new Vector3(-1, 0, 0), new Vector2(0,1)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 0, z1), new Vector3(-1, 0, 0), new Vector2(0,0)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 20, z1 - 50), new Vector3(-1, 0, 0), new Vector2(1,1)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 20, z1 - 50), new Vector3(-1, 0, 0), new Vector2(1,1)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 20, z1), new Vector3(-1, 0, 0), new Vector2(1,0)));
testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 0, z1), new Vector3(-1, 0, 0), new Vector2(0,0)));
剔除设置为无,x2,x1,z1,z2为顶点位置。有什么想法吗?
谢谢
答案 0 :(得分:2)
原因不是因为它们是透明的,而是因为您没有启用深度缓冲,所以墙壁将按照它们被绘制的顺序(从下到上)显示。
在渲染之前,您想要设置渲染状态:
Renderer.GraphicsDevice.DepthStencilState = DepthStencilState.Default;