- Home /
Answer by sneftel · Jun 02, 2011 at 11:59 PM
Yeah, though the code may be a little involved: Get all the lights in the scene; perform a raycast to each one (or, for directional lights, a raycast to infinity in that light's "backwards" direction) ; for each one where the raycast doesn't hit a closer object than the light (or, in the case of directional lights, where it doesn't hit anything at all), compute the intensity given the distance to the light. Sum up all the resultant intensities, and also add in the ambient light.
If you need to support spotlights, you'll also need to make sure the position is within the light cone before you add the intensity in.
Answer by save · Jun 02, 2011 at 11:58 PM
I would guess that getting a per pixel solution equation for a specific point in 3d space would be a bit messy to achieve. If it's a single light source it would be easier, something like this perhaps: http://www.ehow.com/how_7240676_calculate-light-intensity.html
Otherwise you could look into what Unity does with shaders and attenuation: http://unity3d.com/support/documentation/Components/SL-Attenuation.html
I'd probably try to cheat this depending on nearest light source while checking their range and intensity and having ambient light into calculation to come up with a quick solution.
Your answer
![](https://koobas.hobune.stream/wayback/20220612094436im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Adding time before a script is initiated. 2 Answers
[CLOSED] Change intensity of a light with script (which isn´t attached to the light object) 1 Answer
How to turn on a light, then off with the same button. 1 Answer
Combinning light shading and slider? 1 Answer
Changing a bunch of lights intensity 2 Answers