43 lines
941 B
C#
43 lines
941 B
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class GpuCullCamera : MonoBehaviour
|
||
|
|
{
|
||
|
|
public static GpuCullCamera inst;
|
||
|
|
|
||
|
|
public Camera cam;
|
||
|
|
|
||
|
|
Plane[] cameraFrustumPlanes = new Plane[6];
|
||
|
|
[HideInInspector]
|
||
|
|
public Vector4[] frustumPlanes = new Vector4[6];
|
||
|
|
|
||
|
|
private void OnEnable()
|
||
|
|
{
|
||
|
|
inst = this;
|
||
|
|
cam = Camera.main;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Start is called before the first frame update
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update is called once per frame
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
private void LateUpdate()
|
||
|
|
{
|
||
|
|
cameraFrustumPlanes = GeometryUtility.CalculateFrustumPlanes(cam);
|
||
|
|
for (int i = 0; i < cameraFrustumPlanes.Length; i++)
|
||
|
|
{
|
||
|
|
Vector3 normal = -cameraFrustumPlanes[i].normal;
|
||
|
|
frustumPlanes[i] = new Vector4(normal.x, normal.y, normal.z, -cameraFrustumPlanes[i].distance);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|