viewport | 用于视锥体计算的标准化视口坐标。 |
z | 从摄像机原点开始的 Z 深度(将在该位置计算四角)。 |
eye | 要使用的摄像机眼投影矩阵。 |
outCorners | 包含视锥体四角矢量的输出数组。不能为 null,且长度必须 >= 4。 |
给定视口坐标,计算指向指定摄像机深度处视锥体四角的视图空间矢量。
The order of the corners is lower left, upper left, upper right, lower right.CalculateFrustumCorners
can be used to efficiently calculate the world space position of a pixel in an image effect shader. See standard assets implementation of global fog.
using UnityEngine;
public class ExampleClass : MonoBehaviour { void Update() { // this example shows the different camera frustums when using asymmetric projection matrices (like those used by OpenVR).
var camera = GetComponent<Camera>(); Vector3[] frustumCorners = new Vector3[4]; camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), camera.farClipPlane, Camera.MonoOrStereoscopicEye.Mono, frustumCorners);
for (int i = 0; i < 4; i++) { var worldSpaceCorner = camera.transform.TransformVector(frustumCorners[i]); Debug.DrawRay(camera.transform.position, worldSpaceCorner, Color.blue); }
camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), camera.farClipPlane, Camera.MonoOrStereoscopicEye.Left, frustumCorners);
for (int i = 0; i < 4; i++) { var worldSpaceCorner = camera.transform.TransformVector(frustumCorners[i]); Debug.DrawRay(camera.transform.position, worldSpaceCorner, Color.green); }
camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), camera.farClipPlane, Camera.MonoOrStereoscopicEye.Right, frustumCorners);
for (int i = 0; i < 4; i++) { var worldSpaceCorner = camera.transform.TransformVector(frustumCorners[i]); Debug.DrawRay(camera.transform.position, worldSpaceCorner, Color.red); } } }
这些视锥体如下图所示:。