pushing the near plane of a frustum towards an AABB

Started by
10 comments, last by B_old 17 years, 12 months ago
Hello, I have heard that shadow map precision is better the closer the near plane of the light is pushed towards the far plane. My objects have AABB for clipping. Now I would like to automatically push the near plane of the spotlight just so far that every AABB is still inside the frustum. Do you know how this can be accomplished? Thanks.
Advertisement
I don't know much about shadow techniques, but it's quite easy to project an AABB onto a given vector. Given this, you could project all of your AABBs onto the direction vector and use the minimum and maximum values for the near and far planes.

Let me know if you need further details.
I don't know how to project an AABB onto a vector.
What is the result of such an operation?
A simple way to do it is to just get all 8 points of your aabbox, which are the various combinations of +- min.xyz and max.xyz, and find their distance from the plane in question with any standard point distance from plane test.

vector3 test_vector = point on box - eye point;

float distance = dot( test_vector, view direction;







Quote:Original post by SimmerD
A simple way to do it is to just get all 8 points of your aabbox, which are the various combinations of +- min.xyz and max.xyz, and find their distance from the plane in question with any standard point distance from plane test.

vector3 test_vector = point on box - eye point;

float distance = dot( test_vector, view direction;
Here's an easier (and faster) way:
float center = dot(box.center, axis);float radius = dot(box.extents, axis.absolute());min = center - radius;max = center + radius;
The function absolute() returns a copy of the vector with each element set to its absolute value. The above assumes you have the AABBs stored in center-extents form, but if not, the conversion is simply:
center = (max + min) * 0.5f;extents = (max - min) * 0.5f;
If you have to do the conversion every time, you may loose some of the benefits of this method, but I'd think it would still be at least as fast as the 'test each corner' approach.
jyk:
my aabb's are set up the same way, assuming that halfspace is the same as extents.

But what do the min / max values I get, tell me?

Thanks for the help, both of you!

EDIT: what does axis stand for in your case?

[Edited by - B_old on April 21, 2006 12:06:15 PM]
Quote:Original post by B_old
jyk:
my aabb's are set up the same way, assuming that halfspace is the same as extents.

But what do the min / max values I get, tell me?

EDIT: what does axis stand for in your case?
As far as the problem of fitting a frustum or volume to a set of AABBs is concerned:

1. The axis in question is the 'direction' of the frustum or volume
2. Find the projection of each AABB onto this axis (just the min if you're only concerned with the near plane)
3. The normal of the near plane is the axis, and the distance is the minimum of all the 'min' values
4. The normal of the far plane is the negative of the axis, and the distance is the maximum of all the 'max' values
I'm not sure I understand.
Is (axis, min) the near plane I'm looking for?
In that case I think I'm actually looking for the distance this plane has from my light. Because that is the value I need to construct my projection matrix.
Quote:Original post by B_old
Is (axis, min) the near plane I'm looking for?
For the 'fit frustum to AABBs' problem, yes.
Quote:In that case I think I'm actually looking for the distance this plane has from my light. Because that is the value I need to construct my projection matrix.
I haven't done much with shadow rendering techniques, so I probably can't comment other than on the AABB projection issue. I'm sure others can fill in whatever's missing though.
How do I calculate the distance between this plane and the light?

This topic is closed to new replies.

Advertisement