当我快速移动相机时极度撕裂

发布于 2024-12-08 09:06:27 字数 1686 浏览 1 评论 0原文

我正在创建一个 Minecraft 克隆,每当我移动相机时,即使稍微快一点,块之间也会出现很大的撕裂,如下所示:

http://imgur.com/oTtN2

每个块都是 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 本身是双缓冲的?或者谷歌是这么告诉我的。

I am creating a minecraft clone, and whenever I move the camera even a little bit fast there is a big tear between the chunks as shown here:

http://imgur.com/oTtN2

Each chunk is 32x32x32 cubes and has a single vertex buffer for each kind of cube, in case it matters. I am drawing 2D text on the screen as well, and I learned that I had to set the graphic device state for each kind of drawing. Here is how I'm drawing the cubes:

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

The world looks fine if I'm standing still. I thought this might be because I'm in windowed mode, but when I toggled full screen the problem persisted. I also assume that XNA is double buffered by itself? Or so google has told me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

筱武穆 2024-12-15 09:06:27

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

I had a similar issue - I found that I had to call pass.Apply() after setting all of the Effect's parameters...

浅忆流年 2024-12-15 09:06:27

到目前为止的修复方法是使用 1 个巨大的顶点缓冲区。我不喜欢它,但这似乎就是唯一有效的方法。

The fix so far has been to use 1 giant vertex buffer. I don't like it, but that's all that seems to work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文