Jump to content
• ### What is your GameDev Story?

• Advertisement

# pushing the near plane of a frustum towards an AABB

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

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.

#### Share this post

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

#### Share this post

##### Share on other sites
I don't know how to project an AABB onto a vector.
What is the result of such an operation?

#### Share this post

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

#### Share this post

##### Share on other sites
Quote:
 Original post by SimmerDA 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.

#### Share this post

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

#### Share this post

##### Share on other sites
Quote:
 Original post by B_oldjyk: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

#### Share this post

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

#### Share this post

##### Share on other sites
Quote:
 Original post by B_oldIs (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.

#### Share this post

##### Share on other sites
How do I calculate the distance between this plane and the light?

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 14
• 14
• 45
• 22
• 27
• Advertisement
• ### Forum Statistics

• Total Topics
634044
• Total Posts
3015208
×

## 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!