Created
July 29, 2015 12:44
-
-
Save MatthewBarker/032c325ef8577c6d0188 to your computer and use it in GitHub Desktop.
Phaser glow filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint white: true*/ | |
/*global Phaser*/ | |
/** | |
* Defines a glow filter for Web GL. | |
* @module | |
*/ | |
Phaser.Filter.Glow = function (game) { | |
'use strict'; | |
Phaser.Filter.call(this, game); | |
this.fragmentSrc = [ | |
'precision lowp float;', | |
'varying vec2 vTextureCoord;', | |
'varying vec4 vColor;', | |
'uniform sampler2D uSampler;', | |
'void main() {', | |
'vec4 sum = vec4(0);', | |
'vec2 texcoord = vTextureCoord;', | |
'for(int xx = -4; xx <= 4; xx++) {', | |
'for(int yy = -3; yy <= 3; yy++) {', | |
'float dist = sqrt(float(xx*xx) + float(yy*yy));', | |
'float factor = 0.0;', | |
'if (dist == 0.0) {', | |
'factor = 2.0;', | |
'} else {', | |
'factor = 2.0/abs(float(dist));', | |
'}', | |
'sum += texture2D(uSampler, texcoord + vec2(xx, yy) * 0.002) * factor;', | |
'}', | |
'}', | |
'gl_FragColor = sum * 0.025 + texture2D(uSampler, texcoord);', | |
'}' | |
]; | |
}; | |
Phaser.Filter.Glow.prototype = Object.create(Phaser.Filter.prototype); | |
Phaser.Filter.Glow.prototype.constructor = Phaser.Filter.Glow; | |
module.exports = Phaser.Filter.Glow; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment