PageRenderTime 872ms CodeModel.GetById 629ms app.highlight 6ms RepoModel.GetById 235ms app.codeStats 0ms

/src/away3d/filters/BloomFilter3D.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 93 lines | 75 code | 16 blank | 2 comment | 3 complexity | 0f7857b11d82b7b6bb5c1cb60680f8f6 MD5 | raw file
 1package away3d.filters
 2{
 3	import away3d.core.managers.Stage3DProxy;
 4	import away3d.filters.tasks.Filter3DBloomCompositeTask;
 5	import away3d.filters.tasks.Filter3DBrightPassTask;
 6	import away3d.filters.tasks.Filter3DHBlurTask;
 7	import away3d.filters.tasks.Filter3DVBlurTask;
 8	
 9	import flash.display3D.textures.Texture;
10	
11	public class BloomFilter3D extends Filter3DBase
12	{
13		private var _brightPassTask:Filter3DBrightPassTask;
14		private var _vBlurTask:Filter3DVBlurTask;
15		private var _hBlurTask:Filter3DHBlurTask;
16		private var _compositeTask:Filter3DBloomCompositeTask;
17		
18		public function BloomFilter3D(blurX:uint = 15, blurY:uint = 15, threshold:Number = .75, exposure:Number = 2, quality:int = 3)
19		{
20			super();
21			_brightPassTask = new Filter3DBrightPassTask(threshold);
22			_hBlurTask = new Filter3DHBlurTask(blurX);
23			_vBlurTask = new Filter3DVBlurTask(blurY);
24			_compositeTask = new Filter3DBloomCompositeTask(exposure);
25			
26			if (quality > 4)
27				quality = 4;
28			else if (quality < 0)
29				quality = 0;
30			
31			_hBlurTask.textureScale = (4 - quality);
32			_vBlurTask.textureScale = (4 - quality);
33			// composite's main input texture is from vBlur, so needs to be scaled down
34			_compositeTask.textureScale = (4 - quality);
35			
36			addTask(_brightPassTask);
37			addTask(_hBlurTask);
38			addTask(_vBlurTask);
39			addTask(_compositeTask);
40		}
41		
42		override public function setRenderTargets(mainTarget:Texture, stage3DProxy:Stage3DProxy):void
43		{
44			_brightPassTask.target = _hBlurTask.getMainInputTexture(stage3DProxy);
45			_hBlurTask.target = _vBlurTask.getMainInputTexture(stage3DProxy);
46			_vBlurTask.target = _compositeTask.getMainInputTexture(stage3DProxy);
47			// use bright pass's input as composite's input
48			_compositeTask.overlayTexture = _brightPassTask.getMainInputTexture(stage3DProxy);
49			
50			super.setRenderTargets(mainTarget, stage3DProxy);
51		}
52		
53		public function get exposure():Number
54		{
55			return _compositeTask.exposure;
56		}
57		
58		public function set exposure(value:Number):void
59		{
60			_compositeTask.exposure = value;
61		}
62		
63		public function get blurX():uint
64		{
65			return _hBlurTask.amount;
66		}
67		
68		public function set blurX(value:uint):void
69		{
70			_hBlurTask.amount = value;
71		}
72		
73		public function get blurY():uint
74		{
75			return _vBlurTask.amount;
76		}
77		
78		public function set blurY(value:uint):void
79		{
80			_vBlurTask.amount = value;
81		}
82		
83		public function get threshold():Number
84		{
85			return _brightPassTask.threshold;
86		}
87		
88		public function set threshold(value:Number):void
89		{
90			_brightPassTask.threshold = value;
91		}
92	}
93}