nearest light

Started by
4 comments, last by Aressera 7 years, 10 months ago

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 ?

Advertisement

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.

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.

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.

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.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

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.

This topic is closed to new replies.

Advertisement