forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Filter resolution to a 2f and added Blur and Marble filters.
- Loading branch information
1 parent
378ffc7
commit 00a9897
Showing
17 changed files
with
219 additions
and
77 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
var game = new Phaser.Game(800, 600, Phaser.WEBGL, 'phaser-example', { preload: preload, create: create }); | ||
|
||
function preload() { | ||
|
||
game.load.image('phaser', 'assets/sprites/phaser2.png'); | ||
game.load.script('filterX', '../filters/BlurX.js'); | ||
game.load.script('filterY', '../filters/BlurY.js'); | ||
|
||
} | ||
|
||
function create() { | ||
|
||
var logo = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser'); | ||
logo.anchor.setTo(0.5, 0.5); | ||
|
||
var blurX = game.add.filter('BlurX'); | ||
var blurY = game.add.filter('BlurY'); | ||
|
||
logo.filters = [blurX, blurY]; | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* A horizontal blur filter by Mat Groves http://matgroves.com/ @Doormat23 | ||
*/ | ||
Phaser.Filter.BlurX = function (game) { | ||
|
||
Phaser.Filter.call(this, game); | ||
|
||
this.uniforms.blur = { type: '1f', value: 1 / 512 }; | ||
|
||
this.fragmentSrc = [ | ||
|
||
"precision mediump float;", | ||
"varying vec2 vTextureCoord;", | ||
"varying float vColor;", | ||
"uniform float blur;", | ||
"uniform sampler2D uSampler;", | ||
|
||
"void main(void) {", | ||
"vec4 sum = vec4(0.0);", | ||
|
||
"sum += texture2D(uSampler, vec2(vTextureCoord.x - 4.0*blur, vTextureCoord.y)) * 0.05;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x - 3.0*blur, vTextureCoord.y)) * 0.09;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x - 2.0*blur, vTextureCoord.y)) * 0.12;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x - blur, vTextureCoord.y)) * 0.15;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y)) * 0.16;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x + blur, vTextureCoord.y)) * 0.15;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x + 2.0*blur, vTextureCoord.y)) * 0.12;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x + 3.0*blur, vTextureCoord.y)) * 0.09;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x + 4.0*blur, vTextureCoord.y)) * 0.05;", | ||
|
||
"gl_FragColor = sum;", | ||
|
||
"}" | ||
]; | ||
|
||
}; | ||
|
||
Phaser.Filter.BlurX.prototype = Object.create(Phaser.Filter.prototype); | ||
Phaser.Filter.BlurX.prototype.constructor = Phaser.Filter.BlurX; | ||
|
||
Object.defineProperty(Phaser.Filter.BlurX.prototype, 'blur', { | ||
|
||
get: function() { | ||
return this.uniforms.blur.value / (1/7000); | ||
}, | ||
|
||
set: function(value) { | ||
this.uniforms.blur.value = (1/7000) * value; | ||
} | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* A vertical blur filter by Mat Groves http://matgroves.com/ @Doormat23 | ||
*/ | ||
Phaser.Filter.BlurY = function (game) { | ||
|
||
Phaser.Filter.call(this, game); | ||
|
||
this.uniforms.blur = { type: '1f', value: 1 / 512 }; | ||
|
||
this.fragmentSrc = [ | ||
|
||
"precision mediump float;", | ||
"varying vec2 vTextureCoord;", | ||
"varying float vColor;", | ||
"uniform float blur;", | ||
"uniform sampler2D uSampler;", | ||
|
||
"void main(void) {", | ||
"vec4 sum = vec4(0.0);", | ||
|
||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - 4.0*blur)) * 0.05;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - 3.0*blur)) * 0.09;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - 2.0*blur)) * 0.12;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - blur)) * 0.15;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y)) * 0.16;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + blur)) * 0.15;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + 2.0*blur)) * 0.12;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + 3.0*blur)) * 0.09;", | ||
"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + 4.0*blur)) * 0.05;", | ||
|
||
"gl_FragColor = sum;", | ||
|
||
"}" | ||
|
||
]; | ||
|
||
}; | ||
|
||
Phaser.Filter.BlurY.prototype = Object.create(Phaser.Filter.prototype); | ||
Phaser.Filter.BlurY.prototype.constructor = Phaser.Filter.BlurY; | ||
|
||
Object.defineProperty(Phaser.Filter.BlurY.prototype, 'blur', { | ||
|
||
get: function() { | ||
return this.uniforms.blur.value / (1/7000); | ||
}, | ||
|
||
set: function(value) { | ||
this.uniforms.blur.value = (1/7000) * value; | ||
} | ||
|
||
}); |
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
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
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
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
Oops, something went wrong.