2013-11-21 04:59:54 +00:00
|
|
|
/**
|
|
|
|
* A sample demonstrating how to create new Phaser Filters.
|
|
|
|
*/
|
|
|
|
Phaser.Filter.SampleFilter = function (game) {
|
|
|
|
|
2013-11-28 21:29:16 +00:00
|
|
|
Phaser.Filter.call(this, game);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* By default the following uniforms are already created and available:
|
|
|
|
*
|
|
|
|
* uniform float time - The current number of elapsed milliseconds in the game.
|
2014-08-28 01:20:49 +00:00
|
|
|
* uniform vec2 resolution - The dimensions of the filter. Can be set via setSize(width, height)
|
2013-11-28 21:29:16 +00:00
|
|
|
* uniform vec4 mouse - The mouse / touch coordinates taken from the pointer given to the update function, if any.
|
|
|
|
* uniform sampler2D uSampler - The current texture (usually the texture of the Sprite the shader is bound to)
|
|
|
|
*
|
|
|
|
* Add in any additional vars you require. Here is a new one called 'wobble' that is a 2f:
|
|
|
|
*
|
|
|
|
* this.uniforms.wobble = { type: '2f', value: { x: 0, y: 0 }};
|
|
|
|
*
|
|
|
|
* The supported types are: 1f, 1fv, 1i, 2f, 2fv, 2i, 2iv, 3f, 3fv, 3i, 3iv, 4f, 4fv, 4i, 4iv, mat2, mat3, mat4 and sampler2D.
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.uniforms.divisor = { type: '1f', value: 0.5 };
|
2014-03-23 16:54:20 +00:00
|
|
|
|
2013-11-28 21:29:16 +00:00
|
|
|
// The fragment shader source
|
|
|
|
this.fragmentSrc = [
|
|
|
|
|
|
|
|
"precision mediump float;",
|
2014-08-28 01:20:49 +00:00
|
|
|
"uniform vec2 resolution;",
|
2013-11-28 21:29:16 +00:00
|
|
|
"uniform float time;",
|
|
|
|
"uniform float divisor;",
|
|
|
|
|
|
|
|
"void main(void) {",
|
|
|
|
"vec2 uv = gl_FragCoord.xy / resolution.xy;",
|
|
|
|
"gl_FragColor = vec4(uv, divisor * sin(time), 0.0);",
|
|
|
|
"}"
|
|
|
|
];
|
2013-11-21 04:59:54 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Filter.SampleFilter.prototype = Object.create(Phaser.Filter.prototype);
|
|
|
|
Phaser.Filter.SampleFilter.prototype.constructor = Phaser.Filter.SampleFilter;
|
|
|
|
|
|
|
|
Phaser.Filter.SampleFilter.prototype.init = function (width, height, divisor) {
|
|
|
|
|
2014-03-23 16:54:20 +00:00
|
|
|
if (typeof divisor == 'undefined') { divisor = 0.5; }
|
2013-11-21 04:59:54 +00:00
|
|
|
|
2013-11-28 21:29:16 +00:00
|
|
|
this.setResolution(width, height);
|
|
|
|
this.uniforms.divisor.value = divisor;
|
2013-11-21 04:59:54 +00:00
|
|
|
|
2014-03-23 16:54:20 +00:00
|
|
|
};
|