Jump to content
• Advertisement

Public Group

# how to get the minimum distance from light to an object

This topic is 2899 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

[color="#333333"]I am implementing some shadow mapping algorithms, eg. Opacity Shadow Maps, all of which need to split the frustum along the direction of the light. Thus the first problem comes to me is how to [color="#333333"]calculate the minima and maxima distance from the light to an object[color="#333333"], so that I can split the frustum of the light with min+(max-min)/n*i, i represents the ith layer, and n is the total number of layers.

[color="#333333"]One idea is to do this in CPU, transform every vertex into the light space, and pick up the minima and maxima z value. However, I am rendering an object which contains several thousand points, thus I have to do the matrix multiplication several thousand times for all the points, which will cost large amount of time.
[font="Trebuchet MS"] [/font]
[font="Trebuchet MS"][color="#333333"]Is there any better ways?[/font]

#### Share this post

##### Share on other sites
Advertisement

[color="#333333"]I am implementing some shadow mapping algorithms, eg. Opacity Shadow Maps, all of which need to split the frustum along the direction of the light. Thus the first problem comes to me is how to [color="#333333"]calculate the minima and maxima distance from the light to an object[color="#333333"], so that I can split the frustum of the light with min+(max-min)/n*i, i represents the ith layer, and n is the total number of layers.

[color="#333333"]One idea is to do this in CPU, transform every vertex into the light space, and pick up the minima and maxima z value. However, I am rendering an object which contains several thousand points, thus I have to do the matrix multiplication several thousand times for all the points, which will cost large amount of time.
[font="Trebuchet MS"] [/font]
[font="Trebuchet MS"][color="#333333"]Is there any better ways?[/font]

You could try a geometry shader to do this, but in general you don't have any information about neighbouring vertices in the vertex shader. If you want to make this faster on the CPU turn SSE2 on in VS compiler settings, the CPU can also do SIMD instructions like the GPU just less at once and there is a penalty for moving to and from SSE2 registers.

#### Share this post

##### Share on other sites
To improve performance, calculate a bounding volume of the mesh in advance (e.g. a bounding-sphere or AABB), and then find the min/max distances between the bounding volume and the light instead.

#### Share this post

##### Share on other sites

• Advertisement
• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• Advertisement

• ### Popular Now

• 9
• 11
• 15
• 21
• 26
• 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!