Jump to content
  • Advertisement
Sign in to follow this  
Ademan555

Shadow Frustum

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

Cant fremember if its Frustum frustrum fustrum or whatever. Anyways... I'm hoping to begin implementing shadow mapping in opengl. And ive got a pretty good idea how I'm going to generate the modelview matrix for rendering the shadow map. (this is assuming point lights) Create a look at matrix from the light to the center of the object (or in this case the center of the object's bounding volume (ive chosen sphere unless anyone believes an OBB or AABB would be better) )But unfortunately I'm at a loss about creating the projection matrix. I assume it would need to be a perspective projection matrix since it is a point light. But my question is how would you create the projection matrix so that it JUST BARELY encloses the objects bounding volume (in this case a bounding sphere) thanks a ton -Dan

Share this post


Link to post
Share on other sites
Advertisement
Hrm, I suppose, i felt it was math-y enough, but i guess not. Could a mod move this to graphics programming and theory?

Thanks
-Dan

Share this post


Link to post
Share on other sites
Given the light location E, sphere center C, and sphere radius R. The frustum has unit-length direction vector D = (C-E)/, where L = Length(C-E). The near value is n = L-R. Notice that the point E+n*D is the closest sphere point to the light location. The far value is f = L+r. If you have a frustum just bounding the sphere, any rotation of that frustum about the view direction is valid. Choose an up vector U and a right vector R so that {D,U,R} is an orthonormal set: all unit-length vectors, mutually perpendicular, R = Cross(D,U).

For the next part of this, draw the 2D scenario for illustration. You have a circle with center C and radius R, and a light location E. The "x" axis is the line through E in the direction of R. The "y" axis is the line through E in the direction of D. Two rays emanate from E and are tangent to the circle. Let Q be the tangent point for the ray on the right. The triangle <C,Q,E> has an edge opposite C with length R and a hypotenuse of length L. The angle A between edges <C,Q> and <C,E> is determined by tan(A) = r/L. The field of view in the R direction is 2*A = 2*arctan(r/L). By the symmetry, the field of view in the U direction is also 2*A.

You can set the coordinate frame with
gluLookAt(E.x,E.y,E.z,E.x+D.x,E.y+D.y,E.z+D.z,U.x,U.y.U.z);
You can set the frustum with
gluPerspective(2*A,1,n,f);
where 1 is the aspect ratio. Naturally, you will need other OpenGL calls to correctly set up the matrix stack, especially for the frustum setup since you need the texture-matrix stack.

Share this post


Link to post
Share on other sites
Thanks a TON. (havent read the whole thing yet, so i may come back with questions) but thank you thank you thank you

cheeers
-Dan

Share this post


Link to post
Share on other sites
Yep, I ended up with some questions. First, is it necessary to use gluPerspective ? (as in is there a way to do it with just glFrustum or just fill in the matrix yourself) And second, should, for the light's modelview matrix, the "z" component vector be pointing towards the shadow caster, or away?

thanks a ton
-Dan

Share this post


Link to post
Share on other sites
You mentioned doing this in OpenGL. Is there a problem using gluPerspective? Same question about using gluLookAt.

To use glFrustum, you need to compute the left, right, bottom, and top frustum values. The angle A is as in my previous response. I should have mentioned that 2*A needs to be in degrees, but my calculations have it in radians. The frustum is symmetric, so left = -right and bottom = -top. Once again an appeal to right triangles and trigonometry produces right = near*tan(A). By the symmetry, top = right. Call glFrustum with the parameters in the correct order.

The vector D is just a direction. It is possible to orient the frustum so that it does not even contain a shadow caster.

Share this post


Link to post
Share on other sites
Well im actually trying to avoid use of the glu library, but aside from that I was hoping that I could avoid dealing in angles (to avoid unneccesary trig functions if at all possible)

thanks
cheers
-Dan

Share this post


Link to post
Share on other sites
have i understood that right? you want to do shadow mapping with a point light? i don't know if there's such a great difference between directX and opengl but i think what you're trying to achieve is only possible with rendering to a cubemap at the lights position...the usual shadowmapping only works for spotlights and directionallights

regards,
m4gnus

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!