Jump to content
  • Advertisement
Sign in to follow this  
poigwym

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Edited by ninnghazad

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!