【问题标题】:Extreme tearing when I move the camera quickly当我快速移动相机时极度撕裂
【发布时间】: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 个巨大的顶点缓冲区而不是每个块有一个单独的顶点缓冲区,这个问题就会消失。

标签: c# xna tearing


【解决方案1】:

我有一个类似的问题 - 我发现我必须在设置所有 Effect 的参数后调用 pass.Apply()...

【讨论】:

    【解决方案2】:

    目前的修复是使用 1 个巨大的顶点缓冲区。我不喜欢它,但这似乎是可行的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 2015-09-05
      • 2022-07-26
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      • 2012-12-09
      相关资源
      最近更新 更多