Thursday, April 2, 2009

Casting Shadows in Papervision3D - ShadowCaster class

I've added shadows to my model today. Thanks to the amazing work of Andrew Zupko who did (and re-did) the classes for shadow casting in Papervision3D, I was able to integrate them very easily. I think this stand-alone class should make it into the trunk eventually.

I bumped into a problem though, when I setup the castPerFace parameter in the castModel method to true, it works perfectly. You can even see the shadow of the sides of the sphere which, in order to keep polygon count down, is not entirely smooth. You can see this "good" version below.

BUT, I don't really need per face casting, it adds some some processing to the already cpu intensive model and the non-per face casting method is perfect because it projects a bounding sphere of the model as a shadow. So given that my models are spheres, I could use the performance benefit of using the simpler shadow casting.

Here's the thing, shadows do weird things when setup without the per face casting. It's like the shadow is bouncing underneath the ball. Must surelly have something to do with the fact that it is turning but couldn't figure out the mathematics in the ShadowCaster class to be able to fix it, or at least play with it. What makes me think the it could be the ShadowCaster class and not the way I've implemented it (didn't include the clone hack for example) is because it works as expected with the per face casting.

I am going to leave it like that for now until I (or someone) finds a fix to this issue. This bad version can be found here.

1 comment:

  1. are you calling .invalidateTargets(); on each render tick? try it :)

    filed under "works for me"