Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First off, I own Unity Pro.

I've been looking in to occluding lights when they aren't being viewed for a while now to improve performance. The main methods I ran in to were using BecameVisible() and testing the camera frustum.

My main problem was that if the player is viewing an area that would be lit by the light, I still want the light to be on.

Currently I'm using a method which checks to see if the lit area is in the camera frustum, but the problem is sometimes lights are in the frustum without actually being visible by the player (e.g. a wall between them and the player). I've tried raycasting to them but you can never get detailed enough for the actual lit area (the best I could figure was using renderer.bounds.extent and to calculate the maximum lit points from the light).

Does anyone know of an easy way in Unity Pro to occlude lights? Or could you tell me a good way to use that camera fulcrum method I was talking about?

share|improve this question
You can check if the camera frustum and the lights frustum intersect, but I expect unity is already doing this. – Archy Feb 27 '13 at 9:15
In Unity Pro, OcclusionCulling should handle lights too. – Archy Feb 27 '13 at 9:24
Alright, my artist had said that Occlusion Culling wouldn't work for lights. So I'd probably just set my various light sources as occludees in the occlusion areas I already have set up? – Timothy Williams Feb 27 '13 at 19:05
And something like checking the camera and light frustum against eachother may work, though I'd need it to work in 360 degrees. – Timothy Williams Feb 27 '13 at 19:06
Occlusion culling seems to not be working with lights, despite what the artist and I try. How exactly would I occlude a light? – Timothy Williams Mar 4 '13 at 23:37

You could write your own script to occlude lights. Something like this attached to the main camera:

List<Light> Lights = new List<Light>();
const float OccludeDist = 100;
void Update()
    foreach (Light light in Lights)
        if ((transform.position - light.transform.position).sqrMagnitude > OccludeDist * OccludeDist))
            light.enabled = false;
            light.enabled = true;

You could also check if the point is within an angle on the Y axis of the camera (the other axes will just give you pain). Be a bit generous with the angle, maybe 2 times the camera's frustrum, so that lights won't turn off when they're lighting areas within the camera's view. If you choose to add this additional optimization (which probably won't be necessary), make sure you use the distance as the broadphase because it's a lot less costly.

share|improve this answer
Nice and simple :) – Ḟḹáḿíṅḡ Ⱬỏḿƀíé Jun 29 '15 at 15:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.