PageRenderTime 305ms CodeModel.GetById 110ms app.highlight 4ms RepoModel.GetById 187ms app.codeStats 1ms

/src/away3d/filters/tasks/Filter3DBloomCompositeTask.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 74 lines | 61 code | 13 blank | 0 comment | 0 complexity | dbbecc7f58b277eca20088910ade5a5d MD5 | raw file
 1package away3d.filters.tasks
 2{
 3	import away3d.arcane;
 4	import away3d.cameras.Camera3D;
 5	import away3d.core.managers.Stage3DProxy;
 6	
 7	import flash.display3D.Context3D;
 8	
 9	import flash.display3D.Context3DProgramType;
10	
11	import flash.display3D.textures.Texture;
12	import flash.display3D.textures.TextureBase;
13	
14	use namespace arcane;
15	
16	public class Filter3DBloomCompositeTask extends Filter3DTaskBase
17	{
18		private var _data:Vector.<Number>;
19		private var _overlayTexture:TextureBase;
20		private var _exposure:Number;
21		
22		public function Filter3DBloomCompositeTask(exposure:Number)
23		{
24			super();
25			_data = Vector.<Number>([ 0.299, 0.587, 0.114, 1 ]); // luminance projection, 1
26			this.exposure = exposure;
27		}
28		
29		public function get overlayTexture():TextureBase
30		{
31			return _overlayTexture;
32		}
33		
34		public function set overlayTexture(value:TextureBase):void
35		{
36			_overlayTexture = value;
37		}
38		
39		override protected function getFragmentCode():String
40		{
41			var code:String;
42			code = "tex ft0, v0, fs0 <2d,linear,clamp>	\n" +
43				"tex ft1, v0, fs1 <2d,linear,clamp>	\n" +
44				"dp3 ft2.x, ft1, fc0\n" +
45				"sub ft2.x, fc0.w, ft2.x\n" +
46				"mul ft0, ft0, ft2.x\n";
47			code += "add oc, ft0, ft1					\n";
48			return code;
49		}
50		
51		override public function activate(stage3DProxy:Stage3DProxy, camera3D:Camera3D, depthTexture:Texture):void
52		{
53			var context:Context3D = stage3DProxy._context3D;
54			context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, _data, 1);
55			context.setTextureAt(1, _overlayTexture);
56		}
57		
58		override public function deactivate(stage3DProxy:Stage3DProxy):void
59		{
60			stage3DProxy._context3D.setTextureAt(1, null);
61		}
62		
63		public function get exposure():Number
64		{
65			return _exposure;
66		}
67		
68		public function set exposure(exposure:Number):void
69		{
70			_exposure = exposure;
71			_data[3] = 1 + _exposure / 10;
72		}
73	}
74}