PageRenderTime 20ms CodeModel.GetById 7ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/src/away3d/filters/tasks/Filter3DBrightPassTask.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 51 lines | 43 code | 8 blank | 0 comment | 0 complexity | 36b72bbed4978afae1aa60369b9633f8 MD5 | raw file
 1package away3d.filters.tasks
 2{
 3	import away3d.cameras.Camera3D;
 4	import away3d.core.managers.Stage3DProxy;
 5	
 6	import flash.display3D.Context3DProgramType;
 7	
 8	import flash.display3D.textures.Texture;
 9	
10	public class Filter3DBrightPassTask extends Filter3DTaskBase
11	{
12		private var _brightPassData:Vector.<Number>;
13		private var _threshold:Number;
14		
15		public function Filter3DBrightPassTask(threshold:Number = .75)
16		{
17			super();
18			_threshold = threshold;
19			_brightPassData = Vector.<Number>([threshold, 1/(1 - threshold), 0, 0]);
20		}
21		
22		public function get threshold():Number
23		{
24			return _threshold;
25		}
26		
27		public function set threshold(value:Number):void
28		{
29			_threshold = value;
30			_brightPassData[0] = value;
31			_brightPassData[1] = 1/(1 - value);
32		}
33		
34		override protected function getFragmentCode():String
35		{
36			return "tex ft0, v0, fs0 <2d,linear,clamp>	\n" +
37				"dp3 ft1.x, ft0.xyz, ft0.xyz	\n" +
38				"sqt ft1.x, ft1.x				\n" +
39				"sub ft1.y, ft1.x, fc0.x		\n" +
40				"mul ft1.y, ft1.y, fc0.y		\n" +
41				"sat ft1.y, ft1.y				\n" +
42				"mul ft0.xyz, ft0.xyz, ft1.y	\n" +
43				"mov oc, ft0					\n";
44		}
45		
46		override public function activate(stage3DProxy:Stage3DProxy, camera3D:Camera3D, depthTexture:Texture):void
47		{
48			stage3DProxy.context3D.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, _brightPassData, 1);
49		}
50	}
51}