如何有条不紊地选择透视投影的近剪裁平面距离? [英] How do I methodically choose the near clip plane distance for a perspective projection?

查看:21
本文介绍了如何有条不紊地选择透视投影的近剪裁平面距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 3D 场景和一个使用 gluPerspective.我有一个固定的 FOV,我知道任何几何体到相机的最小距离(它是第一人称视角,所以这是从视点到角色碰撞体积的最小距离).

I have a 3D scene and a camera defined using gluPerspective. I have a fixed FOV, and I know the minimum distance of any geometry to the camera (it is a first-person view, so that is the minimum distance from the viewpoint to the character's collision volume).

我如何选择最远的近剪裁平面(以获得最佳深度缓冲分辨率),无论玩家如何移动和看起来如何都不会导致任何剪裁?

How can I choose the farthest near clip plane (for the best depth buffer resolution) which will will not cause any clipping, no matter how the player moves and looks?

这些距离不是简单的相等,因为近平面的离原点比离中心更远.

These distances are not simply equal because the corners of the near plane are farther from the origin than the center.

推荐答案

公式:

nearPlane =nearestApproachToPlayer/sqrt(1 + tan(fov/2)2 · (aspectRatio2 + 1)))

nearPlane = nearestApproachToPlayer / sqrt(1 + tan(fov/2)2 · (aspectRatio2 + 1)))

JavaScript 代码:

  var nearPlane = nearestApproachToPlayer 
                  / Math.sqrt(1 + Math.pow(Math.tan(fov/180*Math.PI/2), 2)
                                  * (Math.pow(aspectRatio, 2) + 1));

推导:

在几何上,考虑以近剪裁平面为底、以尖为原点的金字塔.设 nearPlane 是金字塔的高度,wh 是金字塔底部的宽度和高度.

Geometrically, consider the pyramid whose base is the near clip plane and tip is the origin. Let nearPlane be the height of the pyramid, and w and h the width and height of the pyramid's base.

w = aspectRatio · h

FOV 决定金字塔高度轴边的斜率:

The FOV determines the slope of the height-axis sides of the pyramid:

斜率 = tan(fov/2)

h/nearPlane = 2 tan(fov/2)

h/2 = nearPlane tan(fov/2)

slope = tan(fov/2)

h/nearPlane = 2 tan(fov/2)

h/2 = nearPlane tan(fov/2)

近剪裁平面的任意角点距剪裁平面中心偏移(w/2, h/2),所以距离为sqrt((w/2)2 + (h/2)2).这个角点到原点的距离nearPlane与前一个距离形成的直角三角形的斜边,所以sqrt((w>/2)2 + (h/2)2 + nearPlane2).

Any corner point of the near clip plane is offset from the center of the clip plane by (w/2, h/2), so the distance is sqrt((w/2)2 + (h/2)2). The distance from the origin of this corner point is the hypotenuse of the right triangle formed by nearPlane and the former distance, so is sqrt((w/2)2 + (h/2)2 + nearPlane2).

我们希望到角点的距离等于任何几何体的最近距离.

We want that distance to the corner point to be equal to the closest approach of any geometry.

nearestApproachToPlayer = sqrt((w/2)2 + (h/2)2 + nearPlane2)

nearestApproachToPlayer = sqrt((w/2)2 + (h/2)2 + nearPlane2)

应用简单的代数产生上面给出的公式.

Applying straightforward algebra produces the formula given above.

我没有检查我的代数,但我已经凭经验测试了这个公式:如果我将 NearPlane 乘以 1.1,那么它会产生一个剪裁平面,对于各种纵横比,它只是有点太远了.我没有尝试过 60° 以外的其他 FOV.

I have not checked my algebra, but I have empirically tested the formula: if I multiply nearPlane by 1.1, then it produces a clip plane which is just a bit too far, for various aspect ratios. I have not tried different FOVs than 60°.

这篇关于如何有条不紊地选择透视投影的近剪裁平面距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆