在XNA 4.0中绘制3d模型

本文关键字:绘制 3d 模型 XNA | 更新日期: 2023-09-27 18:11:18

我正在绘制几个模型,使用以下代码来设置渲染状态:

GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

一些模型渲染不正确。如果我改变一行代码:

GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;

现在,其他的不能正常工作。我在每个代码段使用了2个代码,但它仍然不起作用。

如何解决这个渲染问题?


截图:

我先画地面,然后画"道路"模型。

: https://i.stack.imgur.com/xH8qp.png

当我改变相机角度…: https://i.stack.imgur.com/Nbw3m.png

在XNA 4.0中绘制3d模型

你的问题看起来是Z-Fighting,这个问题是由试图渲染2个或更多的多边形在与相机的相同距离引起的。

绘制模型时,您可以禁用z缓冲区。DepthStencilState.None