├── .gitattributes ├── .gitignore ├── README.md └── src └── starling ├── effects ├── BaseFilterEffect.as ├── CRTEffect.as ├── CrossProcessEffect.as ├── FlashlightEffect.as ├── KaleidoscopeEffect.as ├── LineGlitchEffect.as ├── NewsprintEffect.as ├── PixelateEffect.as ├── SineWaveEffect.as ├── SpotlightEffect.as ├── VignetteEffect.as ├── WarpEffect.as └── assets │ └── cross-processing.jpg └── filters ├── CRTFilter.as ├── CrossProcessingFilter.as ├── FilterUtil.as ├── FlashlightFilter.as ├── KaleidoscopeFilter.as ├── LineGlitchFilter.as ├── NewsprintFilter.as ├── PixelateFilter.as ├── RadialBlurFilter.as ├── SineWaveFilter.as ├── SpotlightFilter.as ├── VignetteFilter.as └── WarpFilter.as /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | demo/ 11 | *.tmp 12 | *.bak 13 | *.swp 14 | *~.nib 15 | local.properties 16 | .classpath 17 | .settings/ 18 | .loadpath 19 | 20 | # External tool builders 21 | .externalToolBuilders/ 22 | 23 | # Locally stored "Eclipse launch configurations" 24 | *.launch 25 | 26 | # CDT-specific 27 | .cproject 28 | 29 | # PDT-specific 30 | .buildpath 31 | 32 | 33 | ################# 34 | ## Visual Studio 35 | ################# 36 | 37 | ## Ignore Visual Studio temporary files, build results, and 38 | ## files generated by popular Visual Studio add-ons. 39 | 40 | # User-specific files 41 | *.suo 42 | *.user 43 | *.sln.docstates 44 | 45 | # Build results 46 | 47 | [Dd]ebug/ 48 | [Rr]elease/ 49 | x64/ 50 | build/ 51 | [Bb]in/ 52 | [Oo]bj/ 53 | 54 | # MSTest test Results 55 | [Tt]est[Rr]esult*/ 56 | [Bb]uild[Ll]og.* 57 | 58 | *_i.c 59 | *_p.c 60 | *.ilk 61 | *.meta 62 | *.obj 63 | *.pch 64 | *.pdb 65 | *.pgc 66 | *.pgd 67 | *.rsp 68 | *.sbr 69 | *.tlb 70 | *.tli 71 | *.tlh 72 | *.tmp 73 | *.tmp_proj 74 | *.log 75 | *.vspscc 76 | *.vssscc 77 | .builds 78 | *.pidb 79 | *.log 80 | *.scc 81 | 82 | # Visual C++ cache files 83 | ipch/ 84 | *.aps 85 | *.ncb 86 | *.opensdf 87 | *.sdf 88 | *.cachefile 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | 102 | # TeamCity is a build add-in 103 | _TeamCity* 104 | 105 | # DotCover is a Code Coverage Tool 106 | *.dotCover 107 | 108 | # NCrunch 109 | *.ncrunch* 110 | .*crunch*.local.xml 111 | 112 | # Installshield output folder 113 | [Ee]xpress/ 114 | 115 | # DocProject is a documentation generator add-in 116 | DocProject/buildhelp/ 117 | DocProject/Help/*.HxT 118 | DocProject/Help/*.HxC 119 | DocProject/Help/*.hhc 120 | DocProject/Help/*.hhk 121 | DocProject/Help/*.hhp 122 | DocProject/Help/Html2 123 | DocProject/Help/html 124 | 125 | # Click-Once directory 126 | publish/ 127 | 128 | # Publish Web Output 129 | *.Publish.xml 130 | *.pubxml 131 | 132 | # NuGet Packages Directory 133 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 134 | #packages/ 135 | 136 | # Windows Azure Build Output 137 | csx 138 | *.build.csdef 139 | 140 | # Windows Store app package directory 141 | AppPackages/ 142 | 143 | # Others 144 | sql/ 145 | *.Cache 146 | ClientBin/ 147 | [Ss]tyle[Cc]op.* 148 | ~$* 149 | *~ 150 | *.dbmdl 151 | *.[Pp]ublish.xml 152 | *.pfx 153 | *.publishsettings 154 | 155 | # RIA/Silverlight projects 156 | Generated_Code/ 157 | 158 | # Backup & report files from converting an old project file to a newer 159 | # Visual Studio version. Backup files are not needed, because we have git ;-) 160 | _UpgradeReport_Files/ 161 | Backup*/ 162 | UpgradeLog*.XML 163 | UpgradeLog*.htm 164 | 165 | # SQL Server files 166 | App_Data/*.mdf 167 | App_Data/*.ldf 168 | 169 | ############# 170 | ## Windows detritus 171 | ############# 172 | 173 | # Windows image file caches 174 | Thumbs.db 175 | ehthumbs.db 176 | 177 | # Folder config file 178 | Desktop.ini 179 | 180 | # Recycle Bin used on file shares 181 | $RECYCLE.BIN/ 182 | 183 | # Mac crap 184 | .DS_Store 185 | 186 | 187 | ############# 188 | ## Python 189 | ############# 190 | 191 | *.py[co] 192 | 193 | # Packages 194 | *.egg 195 | *.egg-info 196 | dist/ 197 | build/ 198 | eggs/ 199 | parts/ 200 | var/ 201 | sdist/ 202 | develop-eggs/ 203 | .installed.cfg 204 | 205 | # Installer logs 206 | pip-log.txt 207 | 208 | # Unit test / coverage reports 209 | .coverage 210 | .tox 211 | 212 | #Translations 213 | *.mo 214 | 215 | #Mr Developer 216 | .mr.developer.cfg 217 | 218 | #FlashDevelop 219 | *.as3proj 220 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Starling-Filters 2 | 3 | A collection of filters for use with the [Starling AS3 framework](https://github.com/Gamua/Starling-Framework/). 4 | 5 | The `master` branch contains filters for use with `Starling 2.0`. 6 | 7 | For `Starling 1.x`, use filters from `archive` branch. 8 | 9 | 10 | ### Demo App (does not include all filters): 11 | 12 | [Demo](http://onebyonedesign.com/flash/starling/filters/demo/) 13 | -------------------------------------------------------------------------------- /src/starling/effects/BaseFilterEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | 26 | import starling.rendering.FilterEffect; 27 | import starling.rendering.Program; 28 | import starling.utils.RenderUtil; 29 | 30 | /** 31 | * Base Filter effect for Starling Filters 32 | * @author Devon O. 33 | */ 34 | public class BaseFilterEffect extends FilterEffect 35 | { 36 | 37 | protected var fragmentShader:String; 38 | protected var vertexShader:String; 39 | 40 | /** Create a new BaseFilter Effect */ 41 | public function BaseFilterEffect() 42 | { 43 | this.vertexShader = STD_VERTEX_SHADER; 44 | super(); 45 | } 46 | 47 | /** Create Program */ 48 | override protected function createProgram():Program 49 | { 50 | createShaders(); 51 | return Program.fromSource(this.vertexShader, this.fragmentShader); 52 | } 53 | 54 | /** Create Fragment and/or Vertex shaders */ 55 | protected function createShaders():void 56 | { 57 | // Override to create shader programs 58 | this.fragmentShader = RenderUtil.createAGALTexOperation("oc", "v0", 0, this.texture); 59 | } 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /src/starling/effects/CRTEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | 26 | import flash.display3D.Context3D; 27 | import flash.display3D.Context3DProgramType; 28 | import starling.effects.BaseFilterEffect; 29 | 30 | public class CRTEffect extends BaseFilterEffect 31 | { 32 | public var time:Number=0.0; 33 | public var speed:Number=10.0; 34 | 35 | public var fc0:Vector. = new [0.0, .25, .50, 1.0]; 36 | public var fc1:Vector. = new [Math.sqrt(.50), 2.5, 1.55, Math.PI]; 37 | public var fc2:Vector. = new [2.2, 1.4, 2.0, .2]; 38 | public var fc3:Vector. = new [3.5, 0.7, 1, 0.7]; 39 | public var fc4:Vector. = new [1, 0, 256, 4]; 40 | public var fc5:Vector. = new [1, 1, 1, .0000001]; 41 | 42 | /** Create Shaders */ 43 | override protected function createShaders():void 44 | { 45 | this.fragmentShader = 46 | 59 | +tex("ft2", "ft0.xy", 0, this.texture)+ 60 | 121 | } 122 | 123 | /** Before Draw */ 124 | override protected function beforeDraw(context:Context3D):void 125 | { 126 | super.beforeDraw(context); 127 | 128 | fc5[0] = time; 129 | 130 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.fc0, 1); 131 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, this.fc1, 1); 132 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 2, this.fc2, 1); 133 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 3, this.fc3, 1); 134 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 4, this.fc4, 1); 135 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 5, this.fc5, 1); 136 | } 137 | 138 | } 139 | 140 | } -------------------------------------------------------------------------------- /src/starling/effects/CrossProcessEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | 26 | import flash.display3D.Context3D; 27 | import flash.display3D.Context3DProgramType; 28 | import starling.effects.BaseFilterEffect; 29 | import starling.textures.Texture; 30 | 31 | public class CrossProcessEffect extends BaseFilterEffect 32 | { 33 | [Embed(source="assets/cross-processing.jpg")] 34 | private static const SAMPLE:Class; 35 | 36 | public var amount:Number = 1.0; 37 | 38 | private var sample:Texture; 39 | private var fc0:Vector. = new [1, .50, 0, .0]; 40 | 41 | /** Create a CrossProcess Effect */ 42 | public function CrossProcessEffect() 43 | { 44 | this.sample = Texture.fromBitmap(new SAMPLE()); 45 | } 46 | 47 | /** Dispose */ 48 | override public function dispose():void 49 | { 50 | this.sample.dispose(); 51 | super.dispose(); 52 | } 53 | 54 | /** Create Shaders */ 55 | override protected function createShaders():void 56 | { 57 | this.fragmentShader = 58 | tex("ft0", "v0", 0, this.texture)+ 59 | 65 | mov ft3.x, ft2.x 66 | 67 | // g 68 | mov ft1.x, ft0.y 69 | tex ft2, ft1.xy, fs1<2d, clamp, linear, mipnone> 70 | mov ft3.y, ft2.y 71 | 72 | // g 73 | mov ft1.x, ft0.z 74 | tex ft2, ft1.xy, fs1<2d, clamp, linear, mipnone> 75 | mov ft3.z, ft2.z 76 | 77 | // ft2 = mix (ft0, ft3, fc0.x) 78 | sub ft2.xyz, ft3.xyz, ft0.xyz 79 | mul ft2.xyz, ft2.xyz, fc0.x 80 | add ft2.xyz, ft2.xyz, ft0.xyz 81 | 82 | mov ft0.xyz, ft2.xyz 83 | 84 | mov oc, ft0 85 | ]]> 86 | } 87 | 88 | /** Before Draw */ 89 | override protected function beforeDraw(context:Context3D):void 90 | { 91 | this.fc0[0] = this.amount; 92 | 93 | context.setTextureAt(1, this.sample.base); 94 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.fc0, 1); 95 | 96 | super.beforeDraw(context); 97 | } 98 | 99 | /** After Draw */ 100 | override protected function afterDraw(context:Context3D):void 101 | { 102 | context.setTextureAt(1, null); 103 | super.afterDraw(context); 104 | } 105 | 106 | } 107 | 108 | } -------------------------------------------------------------------------------- /src/starling/effects/FlashlightEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | 26 | import flash.display3D.Context3D; 27 | import flash.display3D.Context3DProgramType; 28 | import starling.effects.BaseFilterEffect; 29 | 30 | public class FlashlightEffect extends BaseFilterEffect 31 | { 32 | private static const RADIAN:Number = Math.PI / 180; 33 | 34 | public var x:Number; 35 | public var y:Number; 36 | public var angle:Number; 37 | 38 | public var outerCone:Number = 10.0; 39 | public var innerCone:Number = 50.0; 40 | public var azimuth:Number = 0; 41 | 42 | public var a1:Number = .50; 43 | public var a2:Number = 10.0; 44 | public var a3:Number = 100.0; 45 | 46 | public var r:Number = 1.0; 47 | public var g:Number = 1.0; 48 | public var b:Number = 1.0; 49 | 50 | private var center:Vector. = new [1, 1, 0, 1]; 51 | private var vars:Vector. = new [1, 1, 1, 1]; 52 | private var lightColor:Vector. = new [1, 1, 1, 1]; 53 | private var attenuation:Vector. = new [.50, 10, 100, 1]; 54 | private var smoothStep:Vector. = new [2, 3, 1, 1]; 55 | 56 | /** Create Shaders */ 57 | override protected function createShaders():void 58 | { 59 | this.fragmentShader = 60 | 121 | // Sample 122 | +tex("ft6", "v0.xy", 0, this.texture)+ 123 | 127 | } 128 | 129 | /** Before Draw */ 130 | override protected function beforeDraw(context:Context3D):void 131 | { 132 | this.center[0] = (this.x * this.texture.width) / this.texture.root.nativeWidth; 133 | this.center[1] = (this.y * this.texture.height) / this.texture.root.nativeHeight; 134 | 135 | this.vars[0] = this.angle * RADIAN; // angle 136 | this.vars[1] = this.azimuth * RADIAN; // azimuth 137 | this.vars[2] = this.outerCone * RADIAN; // outer cone angle 138 | this.vars[3] = this.innerCone * RADIAN; // inner cone angle 139 | 140 | this.lightColor[0] = this.r; 141 | this.lightColor[1] = this.g; 142 | this.lightColor[2] = this.b; 143 | 144 | this.attenuation[0] = this.a1; 145 | this.attenuation[1] = this.a2; 146 | this.attenuation[2] = this.a3; 147 | 148 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.center, 1); 149 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, this.vars, 1); 150 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 2, this.lightColor, 1); 151 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 3, this.attenuation, 1); 152 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 4, this.smoothStep, 1); 153 | 154 | super.beforeDraw(context); 155 | } 156 | } 157 | 158 | } -------------------------------------------------------------------------------- /src/starling/effects/KaleidoscopeEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | 26 | import flash.display3D.Context3D; 27 | import flash.display3D.Context3DProgramType; 28 | import starling.effects.BaseFilterEffect; 29 | 30 | public class KaleidoscopeEffect extends BaseFilterEffect 31 | { 32 | public var time:Number=0.0; 33 | public var speed:Number = 10.0; 34 | public var levels:Number = 3.50; 35 | 36 | public var fc0:Vector. = new [1, 0, Math.PI, 2 * Math.PI]; 37 | public var fc1:Vector. = new [1e-10, Math.PI / 2, 0, 4]; 38 | public var fc2:Vector. = new [-1, 1, Math.PI/levels, 0.0]; 39 | public var fc3:Vector. = new [.1, .2, 2, 0]; 40 | 41 | /** Create Shaders */ 42 | override protected function createShaders():void 43 | { 44 | this.fragmentShader = 45 | +tex("oc", "ft6.xy", 0, this.texture); 139 | } 140 | 141 | /** Before Draw */ 142 | override protected function beforeDraw(context:Context3D):void 143 | { 144 | super.beforeDraw(context); 145 | 146 | fc2[2] = Math.PI / levels; 147 | fc2[3] = time; 148 | fc3[3] = texture.height / texture.width; 149 | 150 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.fc0, 1); 151 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, this.fc1, 1); 152 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 2, this.fc2, 1); 153 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 3, this.fc3, 1); 154 | } 155 | 156 | } 157 | 158 | } -------------------------------------------------------------------------------- /src/starling/effects/LineGlitchEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Devon O. Wolfgang & William Erndt 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | import flash.display3D.Context3D; 26 | import flash.display3D.Context3DProgramType; 27 | 28 | public class LineGlitchEffect extends BaseFilterEffect 29 | { 30 | private static const RADIAN:Number = Math.PI / 180; 31 | private var fc0:Vector. = new [1.0, 1.0, 1.0, 2.0]; 32 | 33 | public var _size:Number; 34 | public var _angle:Number; 35 | public var _distance:Number; 36 | 37 | public function LineGlitchEffect() 38 | {} 39 | 40 | /** Create Shaders */ 41 | override protected function createShaders():void 42 | { 43 | this.fragmentShader = 44 | + tex("ft1", "ft1.xy", 0, this.texture) + 67 | + tex ("ft2", "ft2.xy", 0, this.texture) + 72 | ; 82 | } 83 | 84 | /** Before draw */ 85 | override protected function beforeDraw(context:Context3D):void 86 | { 87 | super.beforeDraw(context); 88 | 89 | // average out size 90 | var s:Number = (this.texture.width + this.texture.height) * .50; 91 | this.fc0[0] = this._size / s; 92 | this.fc0[1] = this._angle * RADIAN; 93 | this.fc0[2] = this._distance; 94 | 95 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.fc0, 1); 96 | } 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /src/starling/effects/NewsprintEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | 26 | import flash.display3D.Context3D; 27 | import flash.display3D.Context3DProgramType; 28 | import starling.effects.BaseFilterEffect; 29 | 30 | public class NewsprintEffect extends BaseFilterEffect 31 | { 32 | private static const RADIAN:Number = Math.PI/180; 33 | 34 | public var size:Number; 35 | public var scale:Number; 36 | public var angle:Number; 37 | 38 | private var vars:Vector. = new [1.0, 1.0, 1.0, 1.0]; 39 | private var constants:Vector. = new [4.0, 5.0, 10.0, 3.0];; 40 | 41 | /** Create shaders */ 42 | override protected function createShaders():void 43 | { 44 | this.fragmentShader = 45 | tex("ft0", "v0", 0, this.texture)+ 46 | ; 78 | } 79 | 80 | /** Before draw */ 81 | override protected function beforeDraw(context:Context3D):void 82 | { 83 | this.vars[0] = this.angle * RADIAN; 84 | this.vars[1] = this.scale; 85 | this.vars[2] = this.size; 86 | 87 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.vars, 1); 88 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, this.constants, 1); 89 | 90 | super.beforeDraw(context); 91 | } 92 | } 93 | 94 | } -------------------------------------------------------------------------------- /src/starling/effects/PixelateEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Devon O. Wolfgang & William Erndt 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | import flash.display3D.Context3D; 26 | import flash.display3D.Context3DProgramType; 27 | 28 | public class PixelateEffect extends BaseFilterEffect 29 | { 30 | private var fc0:Vector. = new [1, 1, 1, 1]; 31 | 32 | public var _sizeX:int; 33 | public var _sizeY:int; 34 | 35 | public function PixelateEffect() 36 | {} 37 | 38 | /** Create Shaders */ 39 | override protected function createShaders():void 40 | { 41 | this.fragmentShader = 42 | + tex("oc", "ft0.xy", 0, this.texture); 49 | } 50 | 51 | /** Before draw */ 52 | override protected function beforeDraw(context:Context3D):void 53 | { 54 | super.beforeDraw(context); 55 | 56 | this.fc0[0] = this._sizeX / this.texture.width; 57 | this.fc0[1] = this._sizeY / this.texture.height; 58 | this.fc0[2] = this.fc0[0] * .50; 59 | this.fc0[3] = this.fc0[1] * .50; 60 | 61 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.fc0, 1); 62 | } 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /src/starling/effects/SineWaveEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Devon O. Wolfgang & William Erndt 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | import flash.display3D.Context3D; 26 | import flash.display3D.Context3DBlendFactor; 27 | import flash.display3D.Context3DProgramType; 28 | 29 | public class SineWaveEffect extends BaseFilterEffect 30 | { 31 | private var fc0:Vector. = new [1, 1, 1, 1]; 32 | private var fc1:Vector. = new [1, 1, 1, 1]; 33 | 34 | public var _amplitude:Number 35 | public var _ticker:Number; 36 | public var _frequency:Number; 37 | public var _isHorizontal:Boolean; 38 | public var _alpha:Number; 39 | 40 | public function SineWaveEffect() 41 | {} 42 | 43 | /** Create Shaders */ 44 | override protected function createShaders():void 45 | { 46 | this.fragmentShader = 47 | +tex("ft3", "ft0", 0, this.texture)+ 62 | ; 67 | } 68 | 69 | /** Before draw */ 70 | override protected function beforeDraw(context:Context3D):void 71 | { 72 | super.beforeDraw(context); 73 | 74 | this.fc0[1] = this._amplitude / this.texture.height; 75 | this.fc0[2] = this._ticker; 76 | this.fc0[3] = this._frequency; 77 | 78 | this.fc1[0] = int(this._isHorizontal); 79 | this.fc1[1] = int(!this._isHorizontal); 80 | this.fc1[2] = this._alpha; 81 | 82 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.fc0, 1); 83 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, this.fc1, 1); 84 | } 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /src/starling/effects/SpotlightEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | import flash.display3D.Context3D; 26 | import flash.display3D.Context3DProgramType; 27 | 28 | public class SpotlightEffect extends BaseFilterEffect 29 | { 30 | 31 | private var center:Vector. = new [1, 1, 1, 1]; 32 | private var vars:Vector. = new [1, 1, 1, 1]; 33 | private var lightColor:Vector. = new [1, 1, 1, 0]; 34 | 35 | // Shader constants 36 | public var _x:Number; 37 | public var _y:Number; 38 | public var _corona:Number; 39 | public var _radius:Number; 40 | public var _red:Number=1.0; 41 | public var _green:Number=1.0; 42 | public var _blue:Number=1.0; 43 | 44 | public function SpotlightEffect() 45 | {} 46 | 47 | /** Create Shaders */ 48 | override protected function createShaders():void 49 | { 50 | this.fragmentShader = 51 | tex("ft1", "v0", 0, this.texture)+ 52 | 73 | } 74 | 75 | /** Before draw */ 76 | override protected function beforeDraw(context:Context3D):void 77 | { 78 | super.beforeDraw(context); 79 | 80 | this.center[0] = (this._x * this.texture.width) / this.texture.root.width; 81 | this.center[1] = (this._y * this.texture.height) / this.texture.root.height; 82 | this.center[2] = this._radius; 83 | this.center[3] = this._corona; 84 | 85 | // texture ratio to produce rounded lights on rectangular textures 86 | this.vars[3] = texture.height / texture.width; 87 | 88 | this.lightColor[0] = this._red; 89 | this.lightColor[1] = this._green; 90 | this.lightColor[2] = this._blue; 91 | 92 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.center, 1); 93 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, this.vars, 1); 94 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 2, this.lightColor, 1); 95 | } 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /src/starling/effects/VignetteEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | 26 | import flash.display3D.Context3D; 27 | import flash.display3D.Context3DProgramType; 28 | import starling.effects.BaseFilterEffect; 29 | 30 | public class VignetteEffect extends BaseFilterEffect 31 | { 32 | public var centerX:Number; 33 | public var centerY:Number; 34 | public var amount:Number; 35 | public var radius:Number; 36 | public var size:Number; 37 | public var useSepia:Boolean; 38 | 39 | private var center:Vector. = new [1, 1, 1, 1]; 40 | private var vars:Vector. = new [.50, .50, .50, .50]; 41 | 42 | private var sepia1:Vector. = new [0.393, 0.769, 0.189, 0.000]; 43 | private var sepia2:Vector. = new [0.349, 0.686, 0.168, 0.000]; 44 | private var sepia3:Vector. = new [0.272, 0.534, 0.131, 0.000]; 45 | 46 | private var noSepia1:Vector. = new [1.0, 0.0, 0.0, 0.000]; 47 | private var noSepia2:Vector. = new [0.0, 1.0, 0.0, 0.000]; 48 | private var noSepia3:Vector. = new [0.0, 0.0, 1.0, 0.000]; 49 | 50 | /** Create Shaders */ 51 | override protected function createShaders():void 52 | { 53 | this.fragmentShader = 54 | 72 | +tex("ft1", "v0", 0, this.texture)+ 73 | 83 | } 84 | 85 | /** Before Draw */ 86 | override protected function beforeDraw(context:Context3D):void 87 | { 88 | var halfSize:Number = this.size * .50; 89 | this.center[0] = this.centerX - halfSize 90 | this.center[1] = this.centerY - halfSize; 91 | 92 | this.vars[0] = this.amount; 93 | this.vars[1] = this.radius; 94 | this.vars[3] = this.size; 95 | 96 | // to sepia or not to sepia 97 | var s1:Vector. = this.useSepia ? this.sepia1 : this.noSepia1; 98 | var s2:Vector. = this.useSepia ? this.sepia2 : this.noSepia2; 99 | var s3:Vector. = this.useSepia ? this.sepia3 : this.noSepia3; 100 | 101 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.center, 1); 102 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, this.vars, 1); 103 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 2, s1, 1); 104 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 3, s2, 1); 105 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 4, s3, 1); 106 | 107 | super.beforeDraw(context); 108 | } 109 | 110 | } 111 | 112 | } -------------------------------------------------------------------------------- /src/starling/effects/WarpEffect.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Devon O. Wolfgang & William Erndt 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.effects 24 | { 25 | import flash.display3D.Context3D; 26 | import flash.display3D.Context3DBlendFactor; 27 | import flash.display3D.Context3DProgramType; 28 | 29 | public class WarpEffect extends BaseFilterEffect 30 | { 31 | private var mLeft:Vector. = new [0.0, 0.0, 0.0, 0.0]; 32 | private var mRight:Vector. = new [1.0, 1.0, 1.0, 1.0]; 33 | private var mVars:Vector. = new [1.0, 2.0, 3.0, 0.0]; 34 | 35 | public var l1:Number; 36 | public var l2:Number; 37 | public var l3:Number; 38 | public var l4:Number; 39 | public var r1:Number; 40 | public var r2:Number; 41 | public var r3:Number; 42 | public var r4:Number; 43 | 44 | public function WarpEffect() 45 | {} 46 | 47 | /** Create Shaders */ 48 | override protected function createShaders():void 49 | { 50 | this.fragmentShader = 51 | + tex("ft5", "ft4.xy", 0, this.texture) + 86 | 99 | } 100 | 101 | /** Before draw */ 102 | override protected function beforeDraw(context:Context3D):void 103 | { 104 | super.beforeDraw(context); 105 | 106 | this.mLeft[0] = this.l1; 107 | this.mLeft[1] = this.l2; 108 | this.mLeft[2] = this.l3; 109 | this.mLeft[3] = this.l4; 110 | 111 | this.mRight[0] = this.r1; 112 | this.mRight[1] = this.r2; 113 | this.mRight[2] = this.r3; 114 | this.mRight[3] = this.r4; 115 | 116 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, mLeft, 1); 117 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, mRight, 1); 118 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 2, mVars, 1); 119 | } 120 | } 121 | 122 | } -------------------------------------------------------------------------------- /src/starling/effects/assets/cross-processing.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devon-o/Starling-Filters/842d46d19bf2e13c88939d9c981872a5f58464e2/src/starling/effects/assets/cross-processing.jpg -------------------------------------------------------------------------------- /src/starling/filters/CRTFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | 26 | import starling.effects.CRTEffect; 27 | import starling.events.EnterFrameEvent; 28 | import starling.events.Event; 29 | import starling.rendering.FilterEffect; 30 | 31 | /** 32 | * Creates a CRT screen effect 33 | * @author Devon O. 34 | */ 35 | public class CRTFilter extends FragmentFilter 36 | { 37 | 38 | /** 39 | * Create a new CRTFilter 40 | * @param autoUpdate should effect upate automatically 41 | */ 42 | public function CRTFilter(autoUpdate:Boolean=true) 43 | { 44 | super(); 45 | this.autoUpdate = autoUpdate; 46 | } 47 | 48 | /** Dispose */ 49 | override public function dispose():void 50 | { 51 | removeEventListener(Event.ENTER_FRAME, onUpdate); 52 | super.dispose(); 53 | } 54 | 55 | /** Auto Update */ 56 | public function set autoUpdate(value:Boolean):void 57 | { 58 | if (value) 59 | addEventListener(Event.ENTER_FRAME, onUpdate); 60 | else 61 | removeEventListener(Event.ENTER_FRAME, onUpdate); 62 | 63 | } 64 | public function get autoUpdate():Boolean { return hasEventListener(EnterFrameEvent.ENTER_FRAME); } 65 | 66 | /** Red */ 67 | public function set red(value:Number):void 68 | { 69 | (this.effect as CRTEffect).fc3[1] = value; 70 | setRequiresRedraw(); 71 | } 72 | public function get red():Number { return (this.effect as CRTEffect).fc3[1]; } 73 | 74 | /** Green */ 75 | public function set green(value:Number):void 76 | { 77 | (this.effect as CRTEffect).fc3[2] = value; 78 | setRequiresRedraw() 79 | } 80 | public function get green():Number { return (this.effect as CRTEffect).fc3[2]; } 81 | 82 | /** Blue */ 83 | public function set blue(value:Number):void 84 | { 85 | (this.effect as CRTEffect).fc3[3] = value; 86 | setRequiresRedraw(); 87 | } 88 | public function get blue():Number { return (this.effect as CRTEffect).fc3[3]; } 89 | 90 | /** Brightness */ 91 | public function set brightness(value:Number):void 92 | { 93 | (this.effect as CRTEffect).fc4[0] = value; 94 | setRequiresRedraw(); 95 | } 96 | public function get brightness():Number { return (this.effect as CRTEffect).fc4[0]; } 97 | 98 | /** Distortion */ 99 | public function set distortion(value:Number):void 100 | { 101 | (this.effect as CRTEffect).fc4[1] = value; 102 | setRequiresRedraw(); 103 | } 104 | public function get distortion():Number { return (this.effect as CRTEffect).fc4[1]; } 105 | 106 | /** Scanline Frequency */ 107 | public function set frequency(value:Number):void 108 | { 109 | (this.effect as CRTEffect).fc4[2] = value; 110 | setRequiresRedraw(); 111 | } 112 | public function get frequency():Number { return (this.effect as CRTEffect).fc4[2]; } 113 | 114 | /** Scanline Intensity */ 115 | public function set intensity(value:Number):void 116 | { 117 | (this.effect as CRTEffect).fc4[3] = value; 118 | setRequiresRedraw(); 119 | } 120 | public function get intensity():Number { return (this.effect as CRTEffect).fc4[3]; } 121 | 122 | /** Speed */ 123 | public function set speed(value:Number):void 124 | { 125 | (this.effect as CRTEffect).speed = value; 126 | onUpdate(null); 127 | }; 128 | public function get speed():Number { return (this.effect as CRTEffect).speed; } 129 | 130 | // Implementation 131 | 132 | /** Create Effect */ 133 | override protected function createEffect():FilterEffect 134 | { 135 | return new CRTEffect(); 136 | } 137 | 138 | // Events 139 | 140 | /** On Update */ 141 | public function onUpdate(e:Event):void 142 | { 143 | (this.effect as CRTEffect).time += (this.effect as CRTEffect).speed / 512; 144 | setRequiresRedraw(); 145 | } 146 | } 147 | 148 | } -------------------------------------------------------------------------------- /src/starling/filters/CrossProcessingFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | 26 | import starling.effects.CrossProcessEffect; 27 | import starling.rendering.FilterEffect; 28 | 29 | /** 30 | * Performs a color cross process effect 31 | * @author Devon O. 32 | */ 33 | 34 | public class CrossProcessingFilter extends FragmentFilter 35 | { 36 | 37 | private var _amount:Number; 38 | 39 | /** Create a new CrossProcessing Filter */ 40 | public function CrossProcessingFilter(amount:Number=1.0) 41 | { 42 | this._amount = amount; 43 | super(); 44 | } 45 | 46 | /** Amount */ 47 | public function set amount(value:Number):void 48 | { 49 | this._amount = value; 50 | FilterUtil.applyEffectProperty("amount", this._amount, this.effect, setRequiresRedraw); 51 | } 52 | public function get amount():Number { return this._amount; } 53 | 54 | // Implementation 55 | 56 | /** Create effect */ 57 | override protected function createEffect():FilterEffect 58 | { 59 | var e:CrossProcessEffect = new CrossProcessEffect(); 60 | e.amount=this._amount; 61 | return e; 62 | } 63 | 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/starling/filters/FilterUtil.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | import starling.rendering.FilterEffect; 26 | 27 | /** 28 | * Collection of static utility methods for filter effects 29 | * @author Devon O. 30 | */ 31 | public class FilterUtil 32 | { 33 | /** 34 | * Apply property to FilterEffect 35 | * @param prop Name of property to set 36 | * @param value Value to set property 37 | * @param effect FilterEffect containing property 38 | * @param update Function to call after setting property 39 | */ 40 | public static function applyEffectProperty(prop:String, value:*, effect:FilterEffect, update:Function):void 41 | { 42 | if (effect==null) 43 | return; 44 | 45 | try 46 | { 47 | effect[prop] = value; 48 | update(); 49 | } 50 | catch (e:Error) 51 | { 52 | trace("[FilterUtil] ERROR: Could not set ("+prop+") to ("+value+") on ("+effect+")", e); 53 | } 54 | } 55 | 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /src/starling/filters/FlashlightFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | 26 | import starling.effects.FlashlightEffect; 27 | import starling.rendering.FilterEffect; 28 | 29 | /** 30 | * Creates Flashlight effect 31 | * @author Devon O. 32 | */ 33 | public class FlashlightFilter extends FragmentFilter 34 | { 35 | private var _x:Number; 36 | private var _y:Number; 37 | private var _angle:Number; 38 | 39 | /** 40 | * Create a new Flashlight Filter 41 | * @param x x position 42 | * @param y y position 43 | * @param angle angle of light cone 44 | */ 45 | public function FlashlightFilter(x:Number=0.0, y:Number=0.0, angle:Number=0.0) 46 | { 47 | this._x = x; 48 | this._y = y; 49 | this._angle = angle; 50 | 51 | super(); 52 | } 53 | 54 | /** X position */ 55 | public function set x(value:Number):void 56 | { 57 | this._x = value; 58 | (this.effect as FlashlightEffect).x = value; 59 | setRequiresRedraw(); 60 | } 61 | public function get x():Number { return this._x; } 62 | 63 | /** Y position */ 64 | public function set y(value:Number):void 65 | { 66 | this._y = value; 67 | (this.effect as FlashlightEffect).y = value; 68 | setRequiresRedraw(); 69 | } 70 | public function get y():Number { return this._y; } 71 | 72 | /** Angle */ 73 | public function set angle(value:Number):void 74 | { 75 | this._angle = value; 76 | (this.effect as FlashlightEffect).angle = value; 77 | setRequiresRedraw(); 78 | } 79 | public function get angle():Number { return this._angle; } 80 | 81 | /** Outer cone */ 82 | public function set outerCone(value:Number):void 83 | { 84 | (this.effect as FlashlightEffect).outerCone = value; 85 | setRequiresRedraw(); 86 | } 87 | public function get outerCone():Number { return (this.effect as FlashlightEffect).outerCone; } 88 | 89 | /** Inner cone */ 90 | public function set innerCone(value:Number):void 91 | { 92 | (this.effect as FlashlightEffect).innerCone = value; 93 | setRequiresRedraw(); 94 | } 95 | public function get innerCone():Number { return (this.effect as FlashlightEffect).innerCone; } 96 | 97 | /** Azimuth */ 98 | public function set azimuth(value:Number):void 99 | { 100 | (this.effect as FlashlightEffect).azimuth = value; 101 | setRequiresRedraw(); 102 | } 103 | public function get azimuth():Number { return (this.effect as FlashlightEffect).azimuth; } 104 | 105 | /** Attenuation 1 */ 106 | public function set attenuation1(value:Number):void 107 | { 108 | (this.effect as FlashlightEffect).a1 = value; 109 | setRequiresRedraw(); 110 | } 111 | public function get attenuation1():Number { return (this.effect as FlashlightEffect).a1; } 112 | 113 | /** Attenuation 2 */ 114 | public function set attenuation2(value:Number):void 115 | { 116 | (this.effect as FlashlightEffect).a2 = value; 117 | setRequiresRedraw(); 118 | } 119 | public function get attenuation2():Number { return (this.effect as FlashlightEffect).a2; } 120 | 121 | /** Attenuation 3 */ 122 | public function set attenuation3(value:Number):void 123 | { 124 | (this.effect as FlashlightEffect).a3 = value; 125 | setRequiresRedraw(); 126 | } 127 | public function get attenuation3():Number { return (this.effect as FlashlightEffect).a3; } 128 | 129 | /** Red */ 130 | public function set red(value:Number):void 131 | { 132 | (this.effect as FlashlightEffect).r = value; 133 | setRequiresRedraw(); 134 | } 135 | public function get red():Number { return (this.effect as FlashlightEffect).r; } 136 | 137 | /** Green */ 138 | public function set green(value:Number):void 139 | { 140 | (this.effect as FlashlightEffect).g = value; 141 | setRequiresRedraw(); 142 | } 143 | public function get green():Number { return (this.effect as FlashlightEffect).g ; } 144 | 145 | /** Blue */ 146 | public function set blue(value:Number):void 147 | { 148 | (this.effect as FlashlightEffect).b = value; 149 | setRequiresRedraw(); 150 | } 151 | public function get blue():Number { return (this.effect as FlashlightEffect).b; } 152 | 153 | // Implementation 154 | 155 | /** Create Effect */ 156 | override protected function createEffect():FilterEffect 157 | { 158 | var e:FlashlightEffect = new FlashlightEffect(); 159 | e.x = this._x; 160 | e.y = this._y; 161 | e.angle = this._angle; 162 | return e; 163 | } 164 | } 165 | 166 | } -------------------------------------------------------------------------------- /src/starling/filters/KaleidoscopeFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | 26 | import starling.effects.KaleidoscopeEffect; 27 | import starling.events.EnterFrameEvent; 28 | import starling.events.Event; 29 | import starling.rendering.FilterEffect; 30 | 31 | /** 32 | * Creates a Kaleidoscope Effect 33 | * @author Devon O. 34 | */ 35 | public class KaleidoscopeFilter extends FragmentFilter 36 | { 37 | 38 | /** 39 | * Create a new CRTFilter 40 | * @param autoUpdate should effect upate automatically 41 | */ 42 | public function KaleidoscopeFilter(autoUpdate:Boolean=false) 43 | { 44 | super(); 45 | this.autoUpdate = autoUpdate; 46 | } 47 | 48 | /** Dispose */ 49 | override public function dispose():void 50 | { 51 | removeEventListener(Event.ENTER_FRAME, onUpdate); 52 | super.dispose(); 53 | } 54 | 55 | /** Auto Update */ 56 | public function set autoUpdate(value:Boolean):void 57 | { 58 | if (value) 59 | addEventListener(Event.ENTER_FRAME, onUpdate); 60 | else 61 | removeEventListener(Event.ENTER_FRAME, onUpdate); 62 | 63 | } 64 | public function get autoUpdate():Boolean { return hasEventListener(EnterFrameEvent.ENTER_FRAME); } 65 | 66 | 67 | /** Levels */ 68 | public function set levels(value:Number):void 69 | { 70 | (this.effect as KaleidoscopeEffect).levels = value; 71 | setRequiresRedraw(); 72 | }; 73 | public function get levels():Number { return (this.effect as KaleidoscopeEffect).levels; } 74 | 75 | /** Speed */ 76 | public function set speed(value:Number):void 77 | { 78 | (this.effect as KaleidoscopeEffect).speed = value; 79 | setRequiresRedraw(); 80 | }; 81 | public function get speed():Number { return (this.effect as KaleidoscopeEffect).speed; } 82 | 83 | /** Time */ 84 | public function set time(value:Number):void 85 | { 86 | (this.effect as KaleidoscopeEffect).time = value; 87 | setRequiresRedraw(); 88 | } 89 | public function get time():Number { return (this.effect as KaleidoscopeEffect).time; } 90 | 91 | // Implementation 92 | 93 | /** Create Effect */ 94 | override protected function createEffect():FilterEffect 95 | { 96 | return new KaleidoscopeEffect(); 97 | } 98 | 99 | // Events 100 | 101 | /** On Update */ 102 | public function onUpdate(e:Event):void 103 | { 104 | time += (this.effect as KaleidoscopeEffect).speed / 512; 105 | } 106 | 107 | } 108 | 109 | } -------------------------------------------------------------------------------- /src/starling/filters/LineGlitchFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Devon O. Wolfgang & William Erndt 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | import starling.effects.LineGlitchEffect; 26 | import starling.rendering.FilterEffect; 27 | 28 | /** 29 | * Creates an angled line glitch image effect 30 | * @author Devon O. 31 | */ 32 | public class LineGlitchFilter extends FragmentFilter 33 | { 34 | private var _size:Number; 35 | private var _angle:Number; 36 | private var _distance:Number; 37 | 38 | /** 39 | * Create a new LineGlitchFilter 40 | * @param size Size of lines (roughly in pixels) 41 | * @param angle Angle of lines in degrees 42 | * @param distance Distance of lines (0-1) 43 | */ 44 | public function LineGlitchFilter(size:Number=2, angle:Number=45, distance:Number=.01) 45 | { 46 | this._size = size; 47 | this._angle = angle; 48 | this._distance = distance; 49 | this.padding.setTo(1, 1, 1, 1); 50 | } 51 | 52 | /** Size of lines (roughly in pixels) */ 53 | public function get size():Number { return this._size; } 54 | public function set size(value:Number):void 55 | { 56 | // size cannot be <=0 57 | if (value<=0) 58 | value = 1; 59 | 60 | this._size = value; 61 | FilterUtil.applyEffectProperty("_size", this._size, this.effect, setRequiresRedraw); 62 | } 63 | 64 | /** Angle in degrees */ 65 | public function get angle():Number { return this._angle; } 66 | public function set angle(value:Number):void 67 | { 68 | this._angle = value; 69 | FilterUtil.applyEffectProperty("_angle", this._angle, this.effect, setRequiresRedraw); 70 | } 71 | 72 | /** Distance of lines (best in range of 0-1) */ 73 | public function get distance():Number { return this._distance; } 74 | public function set distance(value:Number):void 75 | { 76 | this._distance = value; 77 | FilterUtil.applyEffectProperty("_distance", this._distance, this.effect, setRequiresRedraw); 78 | } 79 | 80 | /** Create effect */ 81 | override protected function createEffect():FilterEffect 82 | { 83 | var effect:LineGlitchEffect = new LineGlitchEffect(); 84 | effect._size = this._size; 85 | effect._angle = this._angle; 86 | effect._distance = this._distance; 87 | return effect; 88 | } 89 | } 90 | 91 | } -------------------------------------------------------------------------------- /src/starling/filters/NewsprintFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | 26 | import starling.effects.NewsprintEffect; 27 | import starling.rendering.FilterEffect; 28 | 29 | /** 30 | * Creates a funky 'news print'/half tone effect 31 | * @author Devon O. 32 | */ 33 | public class NewsprintFilter extends FragmentFilter 34 | { 35 | private var _size:Number; 36 | private var _scale:Number; 37 | private var _angle:Number 38 | 39 | /** 40 | * Create a new Newsprint Filter 41 | * @param size size of effect 42 | * @param scale scale of effect 43 | * @param angle angle of effect (in degrees) 44 | */ 45 | public function NewsprintFilter(size:Number=120.0, scale:Number=3.0, angle:Number=0.0) 46 | { 47 | this._size = size; 48 | this._scale = scale; 49 | this._angle = angle; 50 | super(); 51 | } 52 | 53 | /** Size */ 54 | public function set size(value:Number):void 55 | { 56 | this._size = value; 57 | (this.effect as NewsprintEffect).size = value; 58 | setRequiresRedraw(); 59 | } 60 | public function get size():Number { return this._size; } 61 | 62 | /** Scale */ 63 | public function set scale(value:Number):void 64 | { 65 | this._scale = value; 66 | (this.effect as NewsprintEffect).scale = value; 67 | setRequiresRedraw(); 68 | } 69 | public function get scale():Number { return this._scale; } 70 | 71 | /** Angle */ 72 | public function set angle(value:Number):void 73 | { 74 | this._angle = value; 75 | (this.effect as NewsprintEffect).angle = value; 76 | setRequiresRedraw(); 77 | } 78 | public function get angle():Number { return this._angle; } 79 | 80 | // Implementation 81 | 82 | /** Create effect */ 83 | override protected function createEffect():FilterEffect 84 | { 85 | var e:NewsprintEffect = new NewsprintEffect(); 86 | e.size = this._size; 87 | e.scale = this._scale; 88 | e.angle = this._angle; 89 | return e; 90 | } 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /src/starling/filters/PixelateFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Devon O. Wolfgang & William Erndt 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | import starling.effects.PixelateEffect; 26 | import starling.rendering.FilterEffect; 27 | 28 | /** 29 | * Creates a pixelated image effect 30 | * @author Devon O. 31 | */ 32 | public class PixelateFilter extends FragmentFilter 33 | { 34 | private var _sizeX:int; 35 | private var _sizeY:int; 36 | 37 | /** 38 | * Create a new PixelateFilter 39 | * @param sizeX Size of 'pixel' in horizontal dimension 40 | * @param sizeY Size of 'pixel' in vertical dimension 41 | */ 42 | public function PixelateFilter(sizeX:int=8,sizeY:int=8) 43 | { 44 | this._sizeX = sizeX; 45 | this._sizeY = sizeY; 46 | } 47 | 48 | /** Size of X Pixelation (roughly in pixels) */ 49 | public function get sizeX():int { return this._sizeX; } 50 | public function set sizeX(value:int):void 51 | { 52 | this._sizeX = value; 53 | FilterUtil.applyEffectProperty("_sizeX", this._sizeX, this.effect, setRequiresRedraw); 54 | } 55 | 56 | /** Size of Y Pixelation (roughly in pixels) */ 57 | public function get sizeY():int { return this._sizeY; } 58 | public function set sizeY(value:int):void 59 | { 60 | this._sizeY = value; 61 | FilterUtil.applyEffectProperty("_sizeY", this._sizeY, this.effect, setRequiresRedraw); 62 | } 63 | 64 | /** Create effect */ 65 | override protected function createEffect():FilterEffect 66 | { 67 | var effect:PixelateEffect = new PixelateEffect(); 68 | effect._sizeX = this._sizeX; 69 | effect._sizeY = this._sizeY; 70 | return effect; 71 | } 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /src/starling/filters/RadialBlurFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang | Rob Lockhart (http://importantlittlegames.com/) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | 26 | import starling.filters.FragmentFilter; 27 | import starling.filters.IFilterHelper; 28 | import starling.rendering.FilterEffect; 29 | import starling.rendering.Painter; 30 | import starling.textures.Texture; 31 | 32 | /** 33 | * RadialBlurFilter 34 | * Creates a Circular/Spin Blur around a specified normalized point. 35 | * For best results, apply to a Power-Of-Two texture. 36 | * 37 | * @author Devon O. 38 | */ 39 | public class RadialBlurFilter extends FragmentFilter 40 | { 41 | /** Radian Conversion */ 42 | private static const RADIAN:Number=Math.PI/180; 43 | 44 | /** Horizontal position */ 45 | private var _x:Number; 46 | 47 | /** Vertical position */ 48 | private var _y:Number; 49 | 50 | /** Blur angle/amount */ 51 | private var _angle:Number; 52 | 53 | /** Number of samples */ 54 | private var samples:int; 55 | 56 | /** Number of passes */ 57 | private var passes:int; 58 | 59 | /** Radial Blur Effect */ 60 | private var blurEffect:RadialBlurEffect; 61 | 62 | /** 63 | * Create a new RadialBlurFilter 64 | * @param x X position of blur center (0-1) 65 | * @param y Y position of blur center (0-1) 66 | * @param angle Angle in degrees and amount of blur effect 67 | * @param samples Number samples used to produce blur. The higher the number, the better the effect, but performance may degrade. 68 | * @param passes Number of passes to apply to filter (1 pass=1 draw call) 69 | */ 70 | public function RadialBlurFilter(x:Number, y:Number, angle:Number, samples:int=10, passes:int=1) 71 | { 72 | this._x=x; 73 | this._y=y; 74 | this._angle=angle; 75 | this.samples=samples; 76 | this.passes=passes; 77 | } 78 | 79 | /** Get number of passes */ 80 | override public function get numPasses():int 81 | { 82 | return this.passes; 83 | } 84 | 85 | /** Process */ 86 | override public function process(painter:Painter, helper:IFilterHelper, input0:Texture=null, input1:Texture=null, input2:Texture=null, input3:Texture=null):Texture 87 | { 88 | var p:Number=this.numPasses; 89 | var outTexture:Texture=input0; 90 | var inTexture:Texture; 91 | while (p > 0) 92 | { 93 | inTexture=outTexture; 94 | outTexture=super.process(painter, helper, inTexture); 95 | 96 | p--; 97 | 98 | if (inTexture!=input0) 99 | helper.putTexture(inTexture); 100 | } 101 | return outTexture; 102 | } 103 | 104 | /** Create Effect */ 105 | override protected function createEffect():FilterEffect 106 | { 107 | this.blurEffect=new RadialBlurEffect(this.samples); 108 | this.blurEffect.cx=this._x; 109 | this.blurEffect.cy=this._y; 110 | this.blurEffect.angle=this._angle*RADIAN; 111 | return this.blurEffect; 112 | } 113 | 114 | /** X Position (0-1) */ 115 | public function get x():Number { return this._x; } 116 | public function set x(value:Number):void 117 | { 118 | this._x=value; 119 | applyProperty("cx", this._x); 120 | } 121 | 122 | /** Y Position (0-1) */ 123 | public function get y():Number { return this._y; } 124 | public function set y(value:Number):void 125 | { 126 | this._y=value; 127 | applyProperty("cy", this._y); 128 | } 129 | 130 | /** Angle/Amount of Blur */ 131 | public function get angle():Number { return this._angle; } 132 | public function set angle(value:Number):void 133 | { 134 | this._angle=value; 135 | applyProperty("angle", this._angle*RADIAN); 136 | } 137 | 138 | /** Apply effect property to Effect instance */ 139 | private function applyProperty(prop:String, value:*):void 140 | { 141 | if (this.blurEffect==null) 142 | return; 143 | 144 | this.blurEffect[prop]=value; 145 | setRequiresRedraw(); 146 | } 147 | } 148 | } 149 | 150 | import flash.display3D.Context3D; 151 | import flash.display3D.Context3DProgramType; 152 | import starling.rendering.FilterEffect; 153 | import starling.rendering.Program; 154 | 155 | /** FilterEffect for RadialBlurFilter */ 156 | 157 | class RadialBlurEffect extends FilterEffect 158 | { 159 | 160 | /** Angle of blur */ 161 | public var angle:Number; 162 | 163 | /** Center X */ 164 | public var cx:Number; 165 | 166 | /** Center Y */ 167 | public var cy:Number; 168 | 169 | /** Number of samples */ 170 | private var samples:int; 171 | 172 | // Shader Constants 173 | private var fc0:Vector. = new [0.0, 1.0, 0.0, 0.0]; 174 | private var fc1:Vector. = new [1.0, 1.0, 1.0, 1.0]; 175 | 176 | /** 177 | * Create a new RadialBlurEffect 178 | * @param samples Number of samples 179 | */ 180 | public function RadialBlurEffect(samples:int) 181 | { 182 | this.samples=samples; 183 | } 184 | 185 | /** Create Program */ 186 | override protected function createProgram():Program 187 | { 188 | var agal:String=createShader(); 189 | return Program.fromSource(STD_VERTEX_SHADER, agal); 190 | } 191 | 192 | /** Before Draw */ 193 | override protected function beforeDraw(context:Context3D):void 194 | { 195 | super.beforeDraw(context); 196 | 197 | this.fc0[3] = -this.samples*.50; 198 | 199 | this.fc1[0] = (this.cx * this.texture.width) / this.texture.root.nativeWidth; 200 | this.fc1[1] = (this.cy * this.texture.height) / this.texture.root.nativeHeight; 201 | this.fc1[2] = this.angle; 202 | this.fc1[3] = this.samples; 203 | 204 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, this.fc0, 1); 205 | context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 1, this.fc1, 1); 206 | } 207 | 208 | /** Create Shader */ 209 | private function createShader():String 210 | { 211 | var s:String = ""; 212 | 213 | // total 214 | s+="mov ft1.xyzw, fc0.xxxx \n"; 215 | 216 | // subtract offset from uv 217 | s+="sub ft0.xy, v0.xy, fc1.xy \n"; 218 | 219 | // loop counter 220 | s+="mov ft0.z, fc0.w \n"; 221 | for (var i:int=0; i < this.samples; i++) 222 | { 223 | // theta = counter*(angle/numSamples) 224 | s+="mov ft2.x, fc1.z \n"; 225 | s+="div ft2.x, ft2.x, fc1.w \n"; 226 | s+="mul ft2.x, ft2.x, ft0.z \n"; 227 | 228 | // (sin(theta), cos(theta)) 229 | s+="sin ft3.x, ft2.x \n"; 230 | s+="cos ft3.y, ft2.x \n"; 231 | 232 | // x = dp2((cx,cy), (cos,-sin)) 233 | // y = dp2((cx,cy), (sin, cos)) 234 | 235 | s+="mul ft5.y, ft0.x, ft3.x \n"; 236 | s+="mul ft5.z, ft0.y, ft3.y \n"; 237 | s+="add ft5.y, ft5.y, ft5.z \n"; 238 | 239 | s+="neg ft3.x, ft3.x \n" 240 | 241 | s+="mul ft5.x, ft0.x, ft3.y \n"; 242 | s+="mul ft5.w, ft0.y, ft3.x \n"; 243 | s+="add ft5.x, ft5.x, ft5.w \n"; 244 | 245 | // add offset back in 246 | s+="add ft5.xy, ft5.xy, fc1.xy \n"; 247 | 248 | // sample 249 | s+="tex ft6, ft5.xy, fs0<2d, nomip, clamp> \n"; 250 | 251 | // total+=sample 252 | s+="add ft1, ft1, ft6 \n"; 253 | 254 | // increase loop counter 255 | s+="add ft0.z, ft0.z, fc0.y \n"; 256 | } 257 | 258 | // outpuColor=total/numSamples 259 | s+="div oc, ft1.xyzw, fc1.wwww \n"; 260 | 261 | return s; 262 | } 263 | } -------------------------------------------------------------------------------- /src/starling/filters/SineWaveFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Devon O. Wolfgang & William Erndt 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | import starling.effects.SineWaveEffect; 26 | import starling.rendering.FilterEffect; 27 | import starling.utils.Padding; 28 | 29 | /** 30 | * Creates a sine wave image effect 31 | * @author Devon O. 32 | */ 33 | public class SineWaveFilter extends FragmentFilter 34 | { 35 | private static const MIN_PADDING:int=25; 36 | 37 | private var _amplitude:Number 38 | private var _ticker:Number; 39 | private var _frequency:Number; 40 | private var _isHorizontal:Boolean=true; 41 | private var _alpha:Number=1.0; 42 | 43 | /** 44 | * Create a new SineWaveFilter 45 | * @param amplitude Amplitude of sine wave (for best result, pass the largest expected amount) 46 | * @param frequency Frequency of sine wave 47 | * @param ticker Time ticker (use for animation) 48 | */ 49 | public function SineWaveFilter(amplitude:Number=0.0, frequency:Number=0.0, ticker:Number=0.0) 50 | { 51 | this._amplitude = amplitude; 52 | this._frequency = frequency; 53 | this._ticker = ticker; 54 | // Provide enough padding to fit amplitude comfortably 55 | this.padding.setToUniform(amplitude*2); 56 | } 57 | 58 | /** Amplitude of Sine Wave */ 59 | public function get amplitude():Number { return this._amplitude; } 60 | public function set amplitude(value:Number):void 61 | { 62 | this._amplitude = value; 63 | FilterUtil.applyEffectProperty("_amplitude", this._amplitude, this.effect, setRequiresRedraw); 64 | } 65 | 66 | /** Frequency of Sine Wave */ 67 | public function get frequency():Number { return this._frequency; } 68 | public function set frequency(value:Number):void 69 | { 70 | this._frequency = value; 71 | FilterUtil.applyEffectProperty("_frequency", this._frequency, this.effect, setRequiresRedraw); 72 | } 73 | 74 | /** Ticker (increase at rate of speed (e.g. .01) for animation) */ 75 | public function get ticker():Number { return this._ticker; } 76 | public function set ticker(value:Number):void 77 | { 78 | this._ticker = value; 79 | FilterUtil.applyEffectProperty("_ticker", this._ticker, this.effect, setRequiresRedraw); 80 | } 81 | 82 | /** Alpha value of effect (0 - 1) Default = 1.0 */ 83 | public function get alpha():Number { return this._alpha; } 84 | public function set alpha(value:Number):void 85 | { 86 | this._alpha = value; 87 | FilterUtil.applyEffectProperty("_alpha", this._alpha, this.effect, setRequiresRedraw); 88 | } 89 | 90 | /** Is Wave horizontal or not */ 91 | public function get isHorizontal():Boolean { return this._isHorizontal; } 92 | public function set isHorizontal(value:Boolean):void 93 | { 94 | this._isHorizontal = value; 95 | FilterUtil.applyEffectProperty("_isHorizontal", this._isHorizontal, this.effect, setRequiresRedraw); 96 | } 97 | 98 | /** Create effect */ 99 | override protected function createEffect():FilterEffect 100 | { 101 | var effect:SineWaveEffect = new SineWaveEffect(); 102 | effect._amplitude = this._amplitude; 103 | effect._frequency = this._frequency; 104 | effect._ticker = this._ticker; 105 | effect._alpha = this._alpha; 106 | effect._isHorizontal = this._isHorizontal; 107 | return effect; 108 | } 109 | } 110 | 111 | } -------------------------------------------------------------------------------- /src/starling/filters/SpotlightFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | import starling.effects.SpotlightEffect; 26 | import starling.rendering.FilterEffect; 27 | 28 | /** 29 | * Creates a Spotlight effect 30 | * @author Devon O. 31 | */ 32 | public class SpotlightFilter extends FragmentFilter 33 | { 34 | private var sEffect:SpotlightEffect; 35 | 36 | private var _x:Number; 37 | private var _y:Number; 38 | private var _radius:Number; 39 | private var _corona:Number; 40 | 41 | private var _r:Number=1.0; 42 | private var _g:Number=1.0; 43 | private var _b:Number=1.0; 44 | 45 | /** 46 | * Create a new Spotlight Filter 47 | * @param x x position of center of effect (0-1) 48 | * @param y y position of center of effect (0-1) 49 | * @param radius light radius (0-1) 50 | * @param corona light corona 51 | */ 52 | public function SpotlightFilter(x:Number=0.0, y:Number=0.0, radius:Number=.25, corona:Number=2.0) 53 | { 54 | this._x=x; 55 | this._y=y; 56 | this._radius=radius; 57 | this._corona=corona; 58 | } 59 | 60 | /** X Position (0-1) */ 61 | public function get x():Number { return this._x; } 62 | public function set x(value:Number):void 63 | { 64 | this._x = value; 65 | if (this.sEffect != null) 66 | { 67 | this.sEffect._x = this._x; 68 | setRequiresRedraw(); 69 | } 70 | } 71 | 72 | /** Y Position (0-1) */ 73 | public function get y():Number { return this._y; } 74 | public function set y(value:Number):void 75 | { 76 | this._y = value; 77 | if (this.sEffect != null) 78 | { 79 | this.sEffect._y = this._y; 80 | setRequiresRedraw(); 81 | } 82 | } 83 | 84 | /** Corona */ 85 | public function get corona():Number { return this._corona; } 86 | public function set corona(value:Number):void 87 | { 88 | this._corona = value; 89 | if (this.sEffect != null) 90 | { 91 | this.sEffect._corona = this._corona; 92 | setRequiresRedraw(); 93 | } 94 | } 95 | 96 | /** Radius (0-1) */ 97 | public function get radius():Number{ return this._radius; } 98 | public function set radius(value:Number):void 99 | { 100 | this._radius = value; 101 | if (this.sEffect != null) 102 | { 103 | this.sEffect._radius = this._radius; 104 | setRequiresRedraw(); 105 | } 106 | } 107 | 108 | /** Red */ 109 | public function get red():Number { return this._r; } 110 | public function set red(value:Number):void 111 | { 112 | this._r = value; 113 | if (this.sEffect != null) 114 | { 115 | this.sEffect._red = this._r; 116 | setRequiresRedraw(); 117 | } 118 | } 119 | 120 | /** Green */ 121 | public function get green():Number { return this._g; } 122 | public function set green(value:Number):void 123 | { 124 | this._g = value; 125 | if (this.sEffect != null) 126 | { 127 | this.sEffect._green = this._g; 128 | setRequiresRedraw(); 129 | } 130 | } 131 | 132 | /** Blue */ 133 | public function get blue():Number { return this._b; } 134 | public function set blue(value:Number):void 135 | { 136 | this._b = value; 137 | if (this.sEffect != null) 138 | { 139 | this.sEffect._blue = this._b; 140 | setRequiresRedraw(); 141 | } 142 | } 143 | 144 | /** Create effect */ 145 | override protected function createEffect():FilterEffect 146 | { 147 | this.sEffect = new SpotlightEffect(); 148 | this.sEffect._x = this._x; 149 | this.sEffect._y = this._y; 150 | this.sEffect._corona = this._corona; 151 | this.sEffect._radius = this._radius; 152 | this.sEffect._red = this._r; 153 | this.sEffect._green = this._g; 154 | this.sEffect._blue = this._b; 155 | return this.sEffect; 156 | } 157 | } 158 | 159 | } -------------------------------------------------------------------------------- /src/starling/filters/VignetteFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Devon O. Wolfgang 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | 26 | import starling.effects.VignetteEffect; 27 | import starling.rendering.FilterEffect; 28 | 29 | /** 30 | * Creates a Vignette effect on images with an option sepia tone 31 | * @author Devon O. 32 | */ 33 | public class VignetteFilter extends FragmentFilter 34 | { 35 | private var _centerX:Number; 36 | private var _centerY:Number; 37 | private var _amount:Number; 38 | private var _radius:Number; 39 | private var _size:Number; 40 | private var _useSepia:Boolean; 41 | 42 | /** 43 | * Create a new Vignette Filter 44 | * @param size Size of effect 45 | * @param radius Radius of effect 46 | * @param amount Amount of effect 47 | * @param cx Center X of effect 48 | * @param cy Center Y of effect 49 | * @param sepia Should/Should not use Sepia 50 | */ 51 | public function VignetteFilter(size:Number=.50, radius:Number=1.0, amount:Number=0.7, cx:Number=.50, cy:Number=.50, sepia:Boolean=false) 52 | { 53 | this._centerX = cx; 54 | this._centerY = cy; 55 | this._amount = amount; 56 | this._radius = radius; 57 | this._size = size; 58 | this._useSepia = sepia; 59 | super(); 60 | } 61 | 62 | /** Center X */ 63 | public function set centerX(value:Number):void 64 | { 65 | this._centerX = value; 66 | (this.effect as VignetteEffect).centerX = value; 67 | setRequiresRedraw(); 68 | } 69 | public function get centerX():Number { return this._centerX; } 70 | 71 | /** Center Y */ 72 | public function set centerY(value:Number):void 73 | { 74 | this._centerY = value; 75 | (this.effect as VignetteEffect).centerY = value; 76 | setRequiresRedraw(); 77 | } 78 | public function get centerY():Number { return this._centerY; } 79 | 80 | /** Amount */ 81 | public function set amount(value:Number):void 82 | { 83 | this._amount = value; 84 | (this.effect as VignetteEffect).amount = value; 85 | setRequiresRedraw(); 86 | } 87 | public function get amount():Number { return this._amount; } 88 | 89 | /** Radius */ 90 | public function set radius(value:Number):void 91 | { 92 | this._radius = value; 93 | (this.effect as VignetteEffect).radius = value; 94 | setRequiresRedraw(); 95 | } 96 | public function get radius():Number { return this._radius; } 97 | 98 | /** Size */ 99 | public function set size(value:Number):void 100 | { 101 | this._size = value; 102 | (this.effect as VignetteEffect).size = value; 103 | setRequiresRedraw(); 104 | } 105 | public function get size():Number { return this._size; } 106 | 107 | /** Use Sepia */ 108 | public function set useSepia(value:Boolean):void 109 | { 110 | this._useSepia = value; 111 | (this.effect as VignetteEffect).useSepia = value; 112 | setRequiresRedraw(); 113 | } 114 | public function get useSepia():Boolean { return this._useSepia; } 115 | 116 | // Implementation 117 | 118 | /** Create Effect */ 119 | override protected function createEffect():FilterEffect 120 | { 121 | var e:VignetteEffect = new VignetteEffect(); 122 | e.centerX = this._centerX; 123 | e.centerY = this._centerY; 124 | e.amount = this._amount; 125 | e.radius = this._radius; 126 | e.size = this._size; 127 | e.useSepia = this._useSepia; 128 | return e; 129 | } 130 | } 131 | 132 | } -------------------------------------------------------------------------------- /src/starling/filters/WarpFilter.as: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Devon O. Wolfgang & William Erndt 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package starling.filters 24 | { 25 | import starling.effects.WarpEffect; 26 | import starling.rendering.FilterEffect; 27 | 28 | /** 29 | * Creates a warped image effect 30 | * @author Devon O. 31 | */ 32 | public class WarpFilter extends FragmentFilter 33 | { 34 | private var _l1:Number 35 | private var _l2:Number; 36 | private var _l3:Number; 37 | private var _l4:Number; 38 | private var _r1:Number 39 | private var _r2:Number; 40 | private var _r3:Number; 41 | private var _r4:Number; 42 | 43 | /** Create a new WarpFilter */ 44 | public function WarpFilter() 45 | { 46 | this._l1=this._l2=this._l3=this._l4 = 0.0; 47 | this._r1=this._r2=this._r3=this._r4 = 1.0; 48 | } 49 | 50 | /** Top left control */ 51 | public function get l1():Number { return this._l1; } 52 | public function set l1(value:Number):void 53 | { 54 | this._l1 = value; 55 | FilterUtil.applyEffectProperty("l1", this._l1, this.effect, setRequiresRedraw); 56 | } 57 | 58 | /** Top middle left control */ 59 | public function get l2():Number { return this._l2; } 60 | public function set l2(value:Number):void 61 | { 62 | this._l2 = value; 63 | FilterUtil.applyEffectProperty("l2", this._l2, this.effect, setRequiresRedraw); 64 | } 65 | 66 | /** Bottom middle left control */ 67 | public function get l3():Number { return this._l3; } 68 | public function set l3(value:Number):void 69 | { 70 | this._l3 = value; 71 | FilterUtil.applyEffectProperty("l3", this._l3, this.effect, setRequiresRedraw); 72 | } 73 | 74 | /** Bottom left control */ 75 | public function get l4():Number { return this._l4; } 76 | public function set l4(value:Number):void 77 | { 78 | this._l4 = value; 79 | FilterUtil.applyEffectProperty("l4", this._l4, this.effect, setRequiresRedraw); 80 | } 81 | 82 | /** Top right control */ 83 | public function get r1():Number { return this._r1; } 84 | public function set r1(value:Number):void 85 | { 86 | this._r1 = value; 87 | FilterUtil.applyEffectProperty("r1", this._r1, this.effect, setRequiresRedraw); 88 | } 89 | 90 | /** Top middle right control */ 91 | public function get r2():Number { return this._r2; } 92 | public function set r2(value:Number):void 93 | { 94 | this._r2 = value; 95 | FilterUtil.applyEffectProperty("r2", this._r2, this.effect, setRequiresRedraw); 96 | } 97 | 98 | /** Bottom middle right control */ 99 | public function get r3():Number { return this._r3; } 100 | public function set r3(value:Number):void 101 | { 102 | this._r3 = value; 103 | FilterUtil.applyEffectProperty("r3", this._r3, this.effect, setRequiresRedraw); 104 | } 105 | 106 | /** Bottom right control */ 107 | public function get r4():Number { return this._r4; } 108 | public function set r4(value:Number):void 109 | { 110 | this._r4 = value; 111 | FilterUtil.applyEffectProperty("r4", this._r4, this.effect, setRequiresRedraw); 112 | } 113 | 114 | /** Create effect */ 115 | override protected function createEffect():FilterEffect 116 | { 117 | var effect:WarpEffect = new WarpEffect(); 118 | effect.l1 = this._l1; 119 | effect.l2 = this._l2; 120 | effect.l3 = this._l3; 121 | effect.l4 = this._l4; 122 | effect.r1 = this._r1; 123 | effect.r2 = this._r2; 124 | effect.r3 = this._r3; 125 | effect.r4 = this._r4; 126 | return effect; 127 | } 128 | } 129 | 130 | } --------------------------------------------------------------------------------