viewport | 用于视锥体计算的归一化视口坐标。 |
z | 从相机原点计算角点的 Z 深度。 |
eye | 要使用的相机眼睛投影矩阵。 |
outCorners | 视锥体角点向量的输出数组。不能为 null,长度必须 >= 4。 |
给定视口坐标,计算指向指定相机深度处的四个视锥体角点的视图空间向量。
角点的顺序为左下、左上、右上、右下。CalculateFrustumCorners
可用于有效地计算图像效果着色器中像素的世界空间位置。请参阅全局雾的标准资源实现。
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); } } }
可以在以下图像中看到:.