nearClipPlane和farClipPlane在绘制模型时做什么



在MonoGame中绘制模型时,nearClipPlane和farClipPlane会做什么?

我正在尝试使用朋友在Blender中制作的模型进行3D绘图。我正在使用从在线教程中获得的一些代码来绘制,它工作正常。我只是好奇nearClipPlane和farClipPlane变量的作用。

private void DrawModel()
{
    foreach (var mesh in Basilisk_MFT.Meshes)
    {
        foreach (BasicEffect basicEffect in mesh.Effects)
        {
            basicEffect.EnableDefaultLighting();
            basicEffect.PreferPerPixelLighting = true;
            basicEffect.World = Matrix.Identity;
            var cameraUpVector = Vector3.UnitZ;
            basicEffect.View = Matrix.CreateLookAt(cameraPosition, cameraLookAtVector, cameraUpVector);
            float aspectRatio = graphics.PreferredBackBufferWidth / (float)graphics.PreferredBackBufferHeight;
            float fieldOfView = MathHelper.PiOver4;
            float nearClipPlane = 1;
            float farClipPlane = 200;
            basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(fieldOfView, aspectRatio, nearClipPlane, farClipPlane);
        }
        mesh.Draw();
    }
}

我假设这是 3D 空间或其他东西的最小和最大长度,但在调整值后我不确定。

近/远窗格定义 zbuffer 的范围(在 0-1 范围内)

无论如何,几何体和像素都会在硬件中"渲染"——但像素将被丢弃,因为它超出了 zbuffer 范围(我不知道在硬件中是否在技术上是这样解决的)

"距离"太大的另一个问题是Z-Fighting。在 zbuffer 的 0-1 范围内必须覆盖的距离越大,它们之间的差异就越小(在 0-1 范围内),因此浮点精度会导致 z 战斗(在非常接近的像素中闪烁,它们将"争夺"它们的 z 值)

最新更新