Skip to content

Instantly share code, notes, and snippets.

@MatthewBarker
Created July 29, 2015 12:44
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save MatthewBarker/032c325ef8577c6d0188 to your computer and use it in GitHub Desktop.
Save MatthewBarker/032c325ef8577c6d0188 to your computer and use it in GitHub Desktop.
Phaser glow filter
/*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