Complex Spotlight Shadow Caster for Papervision3D
Monday, June 8th, 2009
Simulates the projection of shadows coming from a spotlight light source onto irregular surfaces. In the supplied example, an animated MD2 model (from Quake 2) is casting a shadow onto the inside of a sphere. Supported parameters include shadow color, alpha, blur, falloff and texture map size, as well as position, rotation and field of view. This evolves out of the projection work posted previously.
Source:
SpotlightShadowCasterManager.as
Usage:
After instantiating the manager –
_shadowCaster = new SpotlightShadowCasterManager();
– assign one or more DisplayObject3D’s that will block the light from the spotlight:
_shadowCaster.registerShadowCasterObject(myMesh);
Then register one or more meshes that can have shadows cast upon it with registerShadowCasterObject. As the second argument, you must supply a BitmapMaterial utilized by the mesh on which the manager will draw the shadows. Usually, you’ll want to create a CompositeMaterial, with the BitmapMaterial most likely at the top of the stack. It might look something like this:
var compositeMaterial = new CompositeMaterial(); compositeMaterial.addMaterial( new ColorMaterial(0x888888) ); var mat:BitmapMaterial = new BitmapMaterial( new BitmapData(1,1) ); // .. the bitmapdata will get overwritten, // but must contain _something_ var sphere:TriangleMesh3D = new Sphere(compositeMaterial, 1000); _shadowCaster.registerShadowReceiverObject(sphere, mat);
To update the shadow textures, call
_shadowCaster.update();
– probably in your onEnterFrame or onRenderTick function.
That’s enough to get going. From there, it’s just a matter of adjusting the projector’s position and orientation in relation to the objects in your scene with the properties projectorPosition, projectorPitch, and projectorRoll. Check the source for the various configurable properties like blur, alpha, color, etc.
Limitations, bugs:



