【发布时间】:2012-02-24 13:03:16
【问题描述】:
我正在创建一个我的世界克隆,每当我稍微快一点移动相机时,块之间就会出现很大的撕裂,如下所示:
每个块都是 32x32x32 立方体,并且每种立方体都有一个顶点缓冲区,以防万一。我也在屏幕上绘制 2D 文本,我了解到我必须为每种绘图设置图形设备状态。这是我绘制立方体的方式:
GraphicsDevice.Clear(Color.LightSkyBlue);
#region 3D
// Set the device
device.BlendState = BlendState.Opaque;
device.DepthStencilState = DepthStencilState.Default;
device.RasterizerState = RasterizerState.CullCounterClockwise;
// Go through each shader and draw the cubes of that style
lock (GeneratedChunks)
{
foreach (KeyValuePair<CubeType, BasicEffect> KVP in CubeType_Effect)
{
// Iterate through each technique in this effect
foreach (EffectPass pass in KVP.Value.CurrentTechnique.Passes)
{
// Go through each chunk in our chunk map, and pluck out the cubetype we care about
foreach (Vector3 ChunkKey in GeneratedChunks)
{
if (ChunkMap[ChunkKey].CubeType_TriangleCounts[KVP.Key] > 0)
{
pass.Apply(); // assign it to the video card
KVP.Value.View = camera.ViewMatrix;
KVP.Value.Projection = camera.ProjectionMatrix;
KVP.Value.World = worldMatrix;
device.SetVertexBuffer(ChunkMap[ChunkKey].CubeType_VertexBuffers[KVP.Key]);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, ChunkMap[ChunkKey].CubeType_TriangleCounts[KVP.Key]);
}
}
}
}
}
#endregion
如果我站着不动,世界看起来还不错。我认为这可能是因为我处于窗口模式,但是当我切换全屏时,问题仍然存在。我还假设 XNA 本身是双缓冲的?或者谷歌告诉我的。
【问题讨论】:
-
这看起来不像撕裂(这是像素级的东西),看起来顶点在帧之间没有对齐。
-
您使用的是固定步长还是可变步长?
-
我没有在代码中的任何地方指定它应该或不应该,所以不管默认值是什么。我还注意到,如果我将每个立方体类型放入 1 个巨大的顶点缓冲区而不是每个块有一个单独的顶点缓冲区,这个问题就会消失。