Friday, 14 October 2011

Dissapearing lights Frustrum Fix

For those having overactive culling of your lights here is a temporary script to fix it. Just create a new file called ExpandRenderBox.cs and copy paste this code in. Add this to your lights.
Edit: Fixed a semicolon.



using UnityEngine;
public class ExpandRenderBox : MonoBehaviour {

    public float boundSize = 1000;

    private void Start () {
        Mesh mesh = GetComponent<MeshFilter>().mesh;


        Vector3[] verts = mesh.vertices;
        int origCount = mesh.vertexCount;
        System.Array.Resize<Vector3>(ref verts, origCount + 2);

        Bounds bound = new Bounds(Vector3.zero, Vector3.one * boundSize);

        verts[origCount] = bound.min;
        verts[origCount + 1] = bound.max;

        mesh.vertices = verts;
        mesh.RecalculateBounds();

        Destroy(this);
    }

    private void OnDrawGizmos()
    {
        Gizmos.DrawWireCube(transform.position, Vector3.one * boundSize);
    }
}