三种混合透视和正交矩阵

问题描述 投票:0回答:1

我想要一个透视相机和一个相互对齐的正交相机。它们处于相同的位置、方向,并且 zfar 平面完全相同。 问题是,即使认为近、远值相同,我也会得到不同的 z 值,并且遮挡是错误的。想让我失踪吗?

const perspective_camera = new PerspectiveCamera(55, canvas.width / canvas.height, near, far);
const half_width = perspective_camera.far * Math.tan(perspective_camera.fov * 0.5 * (Math.PI / 180));
const half_height = half_width / perspective_camera.aspect;
const ortho_camera = new OrthographicCamera(-half_width, half_width, half_height, -half_height, near, far);
// Here one example of the problem in the Z
const aux1 = new Vector3(0, 0, 1);
const aux2 = new Vector3(0, 0, 1);
console.log(aux1.project(ortho_camera), aux2.project(half_height));
// Object { x: -0.00003130777409465268, y: -0.000001186705638256526, z: -0.999202652754963 }
// Object { x: -0.07660902355148393, y: -0.0029038270148180447, z: 0.9510807024824749 }
typescript three.js 3d webgl
1个回答
0
投票

透视投影的 Z 坐标不是线性的。请参阅如何在现代 OpenGL 中使用片段着色器中的 gl_FragCoord.z 线性渲染深度?。为了弥补这一点,您必须计算一个坐标,在正交投影之后,该坐标会产生与使用透视投影转换后具有相同 z 分量的坐标。基本上,您必须投影透视图并取消投影正交。请参阅 在 Three.js 中将 z 位置从透视转置为正交相机。由于正交投影矩阵和透视投影矩阵以不同的方式投影场景,因此不幸的是,场景在世界空间或视图空间中可能不相同。因此,您的问题没有简单的解决方案。我能看到的唯一可能性是在顶点着色器中执行特殊转换。但是,在这种情况下,您必须使用自己的特殊材质渲染场景。

© www.soinside.com 2019 - 2024. All rights reserved.