# nearest light

This topic is 923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i 'm going to implement nearest nth light from object,  is there effective algorithm to find nearest

nth light ?  Can a scenegraph make it ? can a oct make it ?

##### Share on other sites

that heavily depends on where and how your lights are stored, and how many there actually are. if there's like 100 or so lights there is probably no need for any additional indexing or pre-processing other than having a list of lights and positions.

##### Share on other sites

A sceen graph won't help you. An octree can help limit the sample space for each light if used properly, but only if the light has some sort of max range.

A very simple solution would just be to naively check each object against each light. But this really only works for point lights.

Let A be Vec3 position of some arbitrary object. Let B be Vec3 of some arbitrary point light.

C = B - A

Then take the scalar product of C. This will give you the distance between Object and Light. Do this for a list of them.

##### Share on other sites

If you want to get only the lights that have the most effect on the current object, you might be interested in distance and light intensity, not just distance.

The sun is pretty distant, but in broad daylight it has more effect on objects than a weak flashlight two inches away from a tree trunk.

Even in indoor-only games, tiny LED objects like EXIT signs or digital clocks will give off less light than overhead fluorescent strips.

##### Share on other sites
Not sure if I understand the question, but you could do a (squared)length/ distance check from the light's center to the object, minus the light's radius. Then store and sort them in the wanted order.

##### Share on other sites

In my engine, I compute the incident light intensity on each object's bounding sphere according to its power and distance attenuation parameters. I then sort the lights of each type (point, directional, spot) in separate lists, using a partial sort to only get the brightest few lights (as many as the shader/renderer supports). This is moderately fast (still a bottleneck though), but there may be a more sophisticated way. When gathering the initial set of lights in the scene, I also compute the bounding sphere/cone of point and spot lights (according to some intensity threshold, such as 1% of initial light intensity before distance attenuation) and test those against the view frustum to determine which lights are visible.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633704
• Total Posts
3013457
×