Public Group

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

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

## 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 on other sites

[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 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.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013736
×