SHARE
TWEET

Untitled

a guest May 25th, 2019 13 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package hcmair.starling.effects
  2. {
  3.     import flash.display3D.Context3D;
  4.     import flash.display3D.Context3DProgramType;
  5.  
  6.     import starling.rendering.FilterEffect;
  7.     import starling.rendering.Program;
  8.  
  9.     public class ColorMaskEffect extends FilterEffect
  10.     {
  11.         private var _offsets:Vector.<Number>;
  12.  
  13.         public function ColorMaskEffect()
  14.         {
  15.             _offsets = new Vector.<Number>(1, true);
  16.         }
  17.  
  18.         override protected function createProgram():Program
  19.         {
  20.             var vertexShader:String = STD_VERTEX_SHADER;
  21.             var fragmentShader:String =
  22.                 "tex ft0, v0, fs0 <2d, linear> \n" + // read the pixel
  23.                 "sub ft1, ft1, ft1 \n" + // fill ft1 with zero
  24.                 "sge ft0.w, ft0.w, ft1.w \n" + // set the alpha to 1 if greater than zero
  25.                 "mov oc, ft0" // move it to the output
  26.  
  27.             return Program.fromSource(vertexShader, fragmentShader);
  28.         }
  29.  
  30.         override protected function beforeDraw(context:Context3D):void
  31.         {
  32.             context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, _offsets);
  33.             super.beforeDraw(context);
  34.         }
  35.  
  36.         public function get maskColor():uint { return _offsets[0]; }
  37.         public function set maskColor(value:uint):void { _offsets[0] = value; }
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top