package { import flare.basic.*; import flare.core.*; import flare.flsl.*; import flare.materials.*; import flare.materials.filters.*; import flare.primitives.*; import flare.system.*; import flash.display.*; import flash.display3D.*; import flash.events.*; /** * @author Ariel Nehmad */ public class Test60_ShadowProjector extends Sprite { [Embed(source = "../bin/chess2_noLightmaps.zf3d", mimeType = "application/octet-stream")] private var Map:Class; private var scene:Scene3D; private var proj:ShadowProjector3D; private var camera:Camera3D; public function Test60_ShadowProjector() { scene = new Viewer3D( this, "", 0.25 ); scene.autoResize = true; scene.addChildFromFile( new Map ); scene.addEventListener( Scene3D.COMPLETE_EVENT, completeEvent ); } private function completeEvent(e:Event):void { // remove original lights. var lights:Vector. = scene.getChildrenByClass( Light3D ); for each ( var l:Light3D in lights ) l.parent = null; proj = new ShadowProjector3D( "proj 1", ShadowProjector3D.QUALITY_BEST, 3 ); proj.setPosition( -100, 200, 200 ); proj.lookAt( 0, 0, 0 ); proj.far = 1000; proj.filter = 1000; proj.setParams( 0xffaa40, 0, 1, 1.5 ); proj.parent = scene; proj.debug = false; proj.addChild( new DebugLight( proj ) ); // disable the default light, we want to use the projector isntead. scene.lights.defaultLight = null; scene.lights.ambientColor.setTo( 0.1, 0.2, 0.4 ); // just debug to see the textures on screen. scene.addEventListener( Scene3D.POSTRENDER_EVENT, postRenderEvent ); } private function postRenderEvent(e:Event):void { // align the projector with the camera. if ( Input3D.keyDown( Input3D.Q ) ) { proj.world = scene.camera.world; proj.translateZ( 50 ); } if ( proj.depthTexture ) scene.drawQuadTexture( proj.depthTexture, 0, 0, 150, 150 ); if ( scene.lights.shadowMapTexture ) scene.drawQuadTexture( scene.lights.shadowMapTexture, 0, 150, 150, 150 ); } } }