PageRenderTime 264ms CodeModel.GetById 111ms app.highlight 7ms RepoModel.GetById 144ms app.codeStats 0ms

/src/away3d/filters/DepthOfFieldFilter3D.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 130 lines | 87 code | 19 blank | 24 comment | 1 complexity | 451d7e3521a7997f9d5b712f8179151a MD5 | raw file
  1package away3d.filters
  2{
  3	import away3d.cameras.Camera3D;
  4	import away3d.containers.ObjectContainer3D;
  5	import away3d.core.managers.Stage3DProxy;
  6	import away3d.filters.tasks.Filter3DHDepthOfFFieldTask;
  7	import away3d.filters.tasks.Filter3DVDepthOfFFieldTask;
  8	
  9	import flash.display3D.textures.Texture;
 10	
 11	import flash.geom.Vector3D;
 12	
 13	public class DepthOfFieldFilter3D extends Filter3DBase
 14	{
 15		private var _focusTarget:ObjectContainer3D;
 16		private var _hDofTask:Filter3DHDepthOfFFieldTask;
 17		private var _vDofTask:Filter3DVDepthOfFFieldTask;
 18		
 19		/**
 20		 * Creates a new DepthOfFieldFilter3D object.
 21		 * @param blurX The maximum amount of horizontal blur to apply
 22		 * @param blurY The maximum amount of vertical blur to apply
 23		 * @param stepSize The distance between samples. Set to -1 to auto-detect with acceptable quality.
 24		 */
 25		public function DepthOfFieldFilter3D(maxBlurX:uint = 3, maxBlurY:uint = 3, stepSize:int = -1)
 26		{
 27			super();
 28			_hDofTask = new Filter3DHDepthOfFFieldTask(maxBlurX, stepSize);
 29			_vDofTask = new Filter3DVDepthOfFFieldTask(maxBlurY, stepSize);
 30			addTask(_hDofTask);
 31			addTask(_vDofTask);
 32		}
 33		
 34		/**
 35		 * The amount of pixels between each sample.
 36		 */
 37		public function get stepSize():int
 38		{
 39			return _hDofTask.stepSize;
 40		}
 41		
 42		public function set stepSize(value:int):void
 43		{
 44			_vDofTask.stepSize = _hDofTask.stepSize = value;
 45		}
 46		
 47		/**
 48		 * An optional target ObjectContainer3D that will be used to auto-focus on.
 49		 */
 50		public function get focusTarget():ObjectContainer3D
 51		{
 52			return _focusTarget;
 53		}
 54		
 55		public function set focusTarget(value:ObjectContainer3D):void
 56		{
 57			_focusTarget = value;
 58		}
 59		
 60		/**
 61		 * The distance from the camera to the point that is in focus.
 62		 */
 63		public function get focusDistance():Number
 64		{
 65			return _hDofTask.focusDistance;
 66		}
 67		
 68		public function set focusDistance(value:Number):void
 69		{
 70			_hDofTask.focusDistance = _vDofTask.focusDistance = value;
 71		}
 72		
 73		/**
 74		 * The distance between the focus point and the maximum amount of blur.
 75		 */
 76		public function get range():Number
 77		{
 78			return _hDofTask.range;
 79		}
 80		
 81		public function set range(value:Number):void
 82		{
 83			_vDofTask.range = _hDofTask.range = value;
 84		}
 85		
 86		/**
 87		 * The maximum amount of horizontal blur.
 88		 */
 89		public function get maxBlurX():uint
 90		{
 91			return _hDofTask.maxBlur;
 92		}
 93		
 94		public function set maxBlurX(value:uint):void
 95		{
 96			_hDofTask.maxBlur = value;
 97		}
 98		
 99		/**
100		 * The maximum amount of vertical blur.
101		 */
102		public function get maxBlurY():uint
103		{
104			return _vDofTask.maxBlur;
105		}
106		
107		public function set maxBlurY(value:uint):void
108		{
109			_vDofTask.maxBlur = value;
110		}
111		
112		override public function update(stage:Stage3DProxy, camera:Camera3D):void
113		{
114			if (_focusTarget)
115				updateFocus(camera);
116		}
117		
118		private function updateFocus(camera:Camera3D):void
119		{
120			var target:Vector3D = camera.inverseSceneTransform.transformVector(_focusTarget.scenePosition);
121			_hDofTask.focusDistance = _vDofTask.focusDistance = target.z;
122		}
123		
124		override public function setRenderTargets(mainTarget:Texture, stage3DProxy:Stage3DProxy):void
125		{
126			super.setRenderTargets(mainTarget, stage3DProxy);
127			_hDofTask.target = _vDofTask.getMainInputTexture(stage3DProxy);
128		}
129	}
130}