[gameprogrammer] Re: culled objects and shadow volumes

  • From: Alan Wolfe <alan.wolfe@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Wed, 29 Apr 2009 09:09:50 -0700

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?

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? (:

Thanks again for your help!
Alan

On Tue, Apr 28, 2009 at 11:12 AM, Alan Wolfe <alan.wolfe@xxxxxxxxx> wrote:

> Man, you have been a great help, thank you again Sami (:
>
>
> On Tue, Apr 28, 2009 at 10:55 AM, Sami Näätänen <sn.ml@xxxxxxxxxxxxxxx>wrote:
>
>> On Tuesday 28 April 2009 18:42:11 Alan Wolfe wrote:
>> > That is some pretty good advice, thanks Sami.
>> >
>> > I found this late last night and this technique talks about expanding
>> the
>> > view frustum and then doing regular object culling so you don't have to
>> > create the shadow volumes or test which direction the shadows will be
>> cast.
>> >
>> > http://www.gamedev.net/columns/hardcore/shadowcast/
>> >
>> > I'm going to have to look at the pros and cons of your method vs this
>> > method and see which makes more sense for my game cause I was thinking
>> this
>> > article was the best way, but now im not so sure (:
>>
>> It really depends on the light positions and types of the lights you use.
>> If
>> all the lights have short intencity fallout radius then adding that
>> maximum
>> radius to the frustum is enough and this is easier to the CPU, but it will
>> stress the GPU more.
>> If the light sources are always quite a bit higer than the objects then
>> extending the frustum might be an option regardless of the intencity
>> fallout
>> radius.
>>
>> The thoughest cases are the ones where long shadows are generated from the
>> objects that are nearly in the same level as the lights. the toughest
>> example
>> would be sun set and sun rise. Also all kinds of columns are potential
>> long
>> shadow producers.
>>
>>
>> Also consider that the idea of checking the smallest distance to the
>> frustum
>> position on the OL line is not full proof when the OL line is nearly
>> parallel
>> with the frustum. In the extreme case the OL line can even go away from
>> the
>> frustum and still the shadow volume would intersect the frustum. But these
>> cases can be handled separately if such cases exist. These come in to play
>> when the light source is near an object as this heavily alters the shape
>> of
>> the objects shadow volume. This can be solved by simply calculating the
>> same
>> condition used in the single test individually for the furthest and the
>> nearest point in the OL line that has a perpendicular point in the
>> frustum.
>> If either test is true then the shadow volume will intersect the frustum.
>> The
>> nearest position of course can't be closer to the light source L than the
>> object O itself.
>> Also there might be extreme cases where the whole frustum is inside the
>> objects shadow volume. This means simply that we don't use the light
>> source
>> for this scene.
>>
>>
>> So it might be better to implement both methods and use one of them
>> depending
>> on the combination of the light source and the object.
>>
>> > Thanks!
>>
>> Clad that I could help you.
>>
>>
>> ---------------------
>> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>>
>>
>>
>

Other related posts: