PageRenderTime 28ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/away3d/materials/methods/ColorTransformMethod.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 73 lines | 49 code | 8 blank | 16 comment | 0 complexity | 24dc242791cd93ea4c82e7f8025c9168 MD5 | raw file
 1package away3d.materials.methods
 2{
 3	import away3d.arcane;
 4	import away3d.core.managers.Stage3DProxy;
 5	import away3d.materials.compilation.ShaderRegisterCache;
 6	import away3d.materials.compilation.ShaderRegisterElement;
 7	
 8	import flash.geom.ColorTransform;
 9	
10	use namespace arcane;
11	
12	/**
13	 * ColorTransformMethod provides a shading method that changes the colour of a material analogous to a
14	 * ColorTransform object.
15	 */
16	public class ColorTransformMethod extends EffectMethodBase
17	{
18		private var _colorTransform:ColorTransform;
19		
20		/**
21		 * Creates a new ColorTransformMethod.
22		 */
23		public function ColorTransformMethod()
24		{
25			super();
26		}
27		
28		/**
29		 * The ColorTransform object to transform the colour of the material with.
30		 */
31		public function get colorTransform():ColorTransform
32		{
33			return _colorTransform;
34		}
35		
36		public function set colorTransform(value:ColorTransform):void
37		{
38			_colorTransform = value;
39		}
40		
41		/**
42		 * @inheritDoc
43		 */
44		override arcane function getFragmentCode(vo:MethodVO, regCache:ShaderRegisterCache, targetReg:ShaderRegisterElement):String
45		{
46			var code:String = "";
47			var colorMultReg:ShaderRegisterElement = regCache.getFreeFragmentConstant();
48			var colorOffsReg:ShaderRegisterElement = regCache.getFreeFragmentConstant();
49			vo.fragmentConstantsIndex = colorMultReg.index*4;
50			code += "mul " + targetReg + ", " + targetReg.toString() + ", " + colorMultReg + "\n" +
51				"add " + targetReg + ", " + targetReg.toString() + ", " + colorOffsReg + "\n";
52			return code;
53		}
54		
55		/**
56		 * @inheritDoc
57		 */
58		override arcane function activate(vo:MethodVO, stage3DProxy:Stage3DProxy):void
59		{
60			var inv:Number = 1/0xff;
61			var index:int = vo.fragmentConstantsIndex;
62			var data:Vector.<Number> = vo.fragmentData;
63			data[index] = _colorTransform.redMultiplier;
64			data[index + 1] = _colorTransform.greenMultiplier;
65			data[index + 2] = _colorTransform.blueMultiplier;
66			data[index + 3] = _colorTransform.alphaMultiplier;
67			data[index + 4] = _colorTransform.redOffset*inv;
68			data[index + 5] = _colorTransform.greenOffset*inv;
69			data[index + 6] = _colorTransform.blueOffset*inv;
70			data[index + 7] = _colorTransform.alphaOffset*inv;
71		}
72	}
73}