[gameprogrammer] Re: culled objects and shadow volumes

  • From: Sami Näätänen <sn.ml@xxxxxxxxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Fri, 1 May 2009 03:19:40 +0300

On Wednesday 29 April 2009 19:09:50 Alan Wolfe wrote:
> Hey Sami,
>
> Here's what i was thinking for my final solution tell me what you think...
> (heavily based on your idea, with a neat little twist for positional
> lights!)
>
> * when an object is first known to be frustum culled, iterate through all
> the lights that light the object (this is known inexpensively how i have it
> set up)
> * then for each light:
> *   Get the vector from the light source to the object (ie starting point
> and a vector) and make a ray from that vector, but using the objects
> location as the origin of the ray (or, for directional lights of course
> just use the direction vector as the vector)
> *   Find the ray's closest point to the frustum
> *   If the ray intersects the frustum you know it casts a shadow into the
> frustum so remember that you need to render the shadow for this object and
> continue onto the next light (a flag is kept for each of the possible
> lights, up to 8 total)
> *   If it doesn't intersect, check the distance of the closest point to the
> frustum
> *   If the light is directional, compare this distance to the bounding
> sphere radius.  If it's closer than the bounding sphere radius, it could
> cast a shadow into the frustum so remember that you need to render the
> shadow for this object.
> *   If the light is positional, calculate the "Radius Expansion Factor"...
> you get this by figuring out the distance of the object to the light and
> dividing the sphere radius by that distance.  What you have then is the
> knowledge of how big the shadow's radius will be along the ray at any
> distance from the light source. (ie it's the ratio that the radius of the
> shadow grows linearly over distance)
> *   Get the distance along the ray where the closest point to frustum is
> and multiply that distance by the radius expansion factor to get the radius
> of what the shadow is at that distance.  Check if that point on the ray is
> less than the expanded distance.  If it is, then you know you have to
> render the shadow
>
> What do you think, does that sound decent?

One thing to consider.

To catch all possibilities you need two tests for positional lights.
1. Nearest position to the frustum.
2. Furthest possible point from the object so that a normal plain in this 
point "touches" the frustum.

Example of the case 2: (Frustum marked as a square to make this more clear)
'.' is light source
'O' is the bounding sphere of an object.
'f' is area inside the frustum.
'F' marks the area inside the frustum where the shortest distance point from
    the light ray can be found.
'S' is a special point.

Using the nearest point test here tests at the corner marked with a F.
This is correct.
      fffff
      fffff
      ffffF
.   O 

But the next is not, even if the vector line would go a litle bit more away 
from the frustum, than this apparently straight line down from the light 
source through the center of the bounding sphere.
      .
      O
 ffffF
 fffff
 ffffS

This is because the expansion factor of the bounding sphere is higher than the 
factor of the change in distance. The correct testing point is in the area 
marked with an S.
 

> Hey also, i've been scouring my books (especially "real time collision
> detection") and the net and have been unable to find an algorithm for
> finding the closest point on a ray to a frustum.  Would you happen to have
> any hints there? (:

I think you have to split it as separate planes and then test the distance to 
these planes. You of course need to restrict the planes, which I think is the 
hardest part.

For finding the furthest possible test point touching the frustum, I think you 
could project the frustum corners to the line of the ray.

This projection could be usefull for the first problem too, but I'm not sure, 
and I really don't have time now to put in to this. Although this is very 
interesting problem.



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: