diff --git a/filters/SampleFilter.js b/filters/SampleFilter.js index 853eedcb1..9364557b6 100644 --- a/filters/SampleFilter.js +++ b/filters/SampleFilter.js @@ -10,7 +10,7 @@ Phaser.Filter.SampleFilter = function (game) { * * uniform float time - The current number of elapsed milliseconds in the game. * uniform vec2 resolution - The dimensions of the filter. Can be set via setSize(width, height) - * uniform vec4 mouse - The mouse / touch coordinates taken from the pointer given to the update function, if any. + * uniform vec2 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: diff --git a/src/core/Filter.js b/src/core/Filter.js index 2ae1d577f..6aba84aef 100644 --- a/src/core/Filter.js +++ b/src/core/Filter.js @@ -5,7 +5,7 @@ */ /** -* This is a base Filter template to use for any Phaser filter development. +* This is a base Filter class to use for any Phaser filter development. * * @class Phaser.Filter * @constructor @@ -52,17 +52,38 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) { */ this.padding = 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. + */ + + var d = new Date(); + /** - * @property {object} uniforms - Default uniform mappings. + * @property {object} uniforms - Default uniform mappings. Compatible with ShaderToy and GLSLSandbox. */ this.uniforms = { - time: { type: '1f', value: 0 }, resolution: { type: '2f', value: { x: 256, y: 256 }}, - mouse: { type: '2f', value: { x: 0.0, y: 0.0 }} + time: { type: '1f', value: 0 }, + mouse: { type: '2f', value: { x: 0.0, y: 0.0 } }, + date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() *60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] }, + sampleRate: { type: '1f', value: 44100.0 }, + iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } }, + iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } }, + iChannel2: { type: 'sampler2D', value: null, textureData: { repeat: true } }, + iChannel3: { type: 'sampler2D', value: null, textureData: { repeat: true } } }; + // Copy over/replace any passed in the constructor + if (uniforms) + { + for (var key in uniforms) + { + this.uniforms[key] = uniforms[key]; + } + } + /** * @property {array} fragmentSrc - The fragment shader code. */