PageRenderTime 60ms CodeModel.GetById 30ms app.highlight 5ms RepoModel.GetById 23ms app.codeStats 1ms

/src/away3d/filters/tasks/Filter3DXFadeCompositeTask.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 72 lines | 59 code | 13 blank | 0 comment | 3 complexity | f80d1b5477a86b50ce06959df1d07a3e 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 Filter3DXFadeCompositeTask extends Filter3DTaskBase
17	{
18		private var _data:Vector.<Number>;
19		private var _overlayTexture:TextureBase;
20		
21		public function Filter3DXFadeCompositeTask(amount:Number)
22		{
23			super();
24			if (amount < 0)
25				amount = 0;
26			else if (amount > 1)
27				amount = 1;
28			_data = Vector.<Number>([ amount, 0, 0, 0 ]);
29		}
30		
31		public function get overlayTexture():TextureBase
32		{
33			return _overlayTexture;
34		}
35		
36		public function set overlayTexture(value:TextureBase):void
37		{
38			_overlayTexture = value;
39		}
40		
41		public function get amount():Number
42		{
43			return _data[0];
44		}
45		
46		public function set amount(value:Number):void
47		{
48			_data[0] = value;
49		}
50		
51		override protected function getFragmentCode():String
52		{
53			return "tex ft0, v0, fs0 <2d,nearest>	\n" +
54				"tex ft1, v0, fs1 <2d,nearest>	\n" +
55				"sub ft1, ft1, ft0				\n" +
56				"mul ft1, ft1, fc0.x			\n" +
57				"add oc, ft1, ft0				\n";
58		}
59		
60		override public function activate(stage3DProxy:Stage3DProxy, camera3D:Camera3D, depthTexture:Texture):void
61		{
62			var context:Context3D = stage3DProxy._context3D;
63			context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, _data, 1);
64			context.setTextureAt(1, _overlayTexture);
65		}
66		
67		override public function deactivate(stage3DProxy:Stage3DProxy):void
68		{
69			stage3DProxy._context3D.setTextureAt(1, null);
70		}
71	}
72}