Last active
December 15, 2016 17:34
Basic implementation of the ColorOffsetFilter described in the Starling manual.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ================================================================================================= | |
// | |
// Starling Framework | |
// Copyright Gamua. All Rights Reserved. | |
// | |
// This program is free software. You can redistribute and/or modify it | |
// in accordance with the terms of the accompanying license agreement. | |
// | |
// ================================================================================================= | |
package starling.extensions | |
{ | |
import starling.filters.FragmentFilter; | |
import starling.rendering.FilterEffect; | |
public class ColorOffsetFilter extends FragmentFilter | |
{ | |
public function ColorOffsetFilter(redOffset:Number=0, greenOffset:Number=0, | |
blueOffset:Number=0, alphaOffset:Number=0):void | |
{ | |
colorOffsetEffect.redOffset = redOffset; | |
colorOffsetEffect.greenOffset = greenOffset; | |
colorOffsetEffect.blueOffset = blueOffset; | |
colorOffsetEffect.alphaOffset = alphaOffset; | |
} | |
override protected function createEffect():FilterEffect | |
{ | |
return new ColorOffsetEffect(); | |
} | |
private function get colorOffsetEffect():ColorOffsetEffect | |
{ | |
return effect as ColorOffsetEffect; | |
} | |
public function get redOffset():Number { return colorOffsetEffect.redOffset; } | |
public function set redOffset(value:Number):void { colorOffsetEffect.redOffset = value; } | |
public function get greenOffset():Number { return colorOffsetEffect.greenOffset; } | |
public function set greenOffset(value:Number):void { colorOffsetEffect.greenOffset = value; } | |
public function get blueOffset():Number { return colorOffsetEffect.blueOffset; } | |
public function set blueOffset(value:Number):void { colorOffsetEffect.blueOffset = value; } | |
public function get alphaOffset():Number { return colorOffsetEffect.alphaOffset; } | |
public function set alphaOffset(value:Number):void { colorOffsetEffect.alphaOffset = value; } | |
} | |
} | |
import flash.display3D.Context3D; | |
import flash.display3D.Context3DProgramType; | |
import starling.rendering.FilterEffect; | |
import starling.rendering.Program; | |
import starling.utils.RenderUtil; | |
class ColorOffsetEffect extends FilterEffect | |
{ | |
private var _offsets:Vector.<Number>; | |
public function ColorOffsetEffect() | |
{ | |
_offsets = new Vector.<Number>(4, true); | |
} | |
override protected function createProgram():Program | |
{ | |
var vertexShader:String = STD_VERTEX_SHADER; | |
var fragmentShader:String = [ | |
tex("ft0", "v0", 0, texture), | |
"add oc, ft0, fc0" | |
].join("\n"); | |
return Program.fromSource(vertexShader, fragmentShader); | |
} | |
override protected function beforeDraw(context:Context3D):void | |
{ | |
context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, _offsets); | |
super.beforeDraw(context); | |
} | |
public function get redOffset():Number { return _offsets[0]; } | |
public function set redOffset(value:Number):void { _offsets[0] = value; } | |
public function get greenOffset():Number { return _offsets[1]; } | |
public function set greenOffset(value:Number):void { _offsets[1] = value; } | |
public function get blueOffset():Number { return _offsets[2]; } | |
public function set blueOffset(value:Number):void { _offsets[2] = value; } | |
public function get alphaOffset():Number { return _offsets[3]; } | |
public function set alphaOffset(value:Number):void { _offsets[3] = value; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment