Skip to content

Commit 967497c

Browse files
committed
Added a few new uniforms and tidied things up.
1 parent 86cfc71 commit 967497c

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

filters/SampleFilter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Phaser.Filter.SampleFilter = function (game) {
1010
*
1111
* uniform float time - The current number of elapsed milliseconds in the game.
1212
* uniform vec2 resolution - The dimensions of the filter. Can be set via setSize(width, height)
13-
* uniform vec4 mouse - The mouse / touch coordinates taken from the pointer given to the update function, if any.
13+
* uniform vec2 mouse - The mouse / touch coordinates taken from the pointer given to the update function, if any.
1414
* uniform sampler2D uSampler - The current texture (usually the texture of the Sprite the shader is bound to)
1515
*
1616
* Add in any additional vars you require. Here is a new one called 'wobble' that is a 2f:

src/core/Filter.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
/**
8-
* This is a base Filter template to use for any Phaser filter development.
8+
* This is a base Filter class to use for any Phaser filter development.
99
*
1010
* @class Phaser.Filter
1111
* @constructor
@@ -52,17 +52,38 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
5252
*/
5353
this.padding = 0;
5454

55+
/*
56+
* The supported types are: 1f, 1fv, 1i, 2f, 2fv, 2i, 2iv, 3f, 3fv, 3i, 3iv, 4f, 4fv, 4i, 4iv, mat2, mat3, mat4 and sampler2D.
57+
*/
58+
59+
var d = new Date();
60+
5561
/**
56-
* @property {object} uniforms - Default uniform mappings.
62+
* @property {object} uniforms - Default uniform mappings. Compatible with ShaderToy and GLSLSandbox.
5763
*/
5864
this.uniforms = {
5965

60-
time: { type: '1f', value: 0 },
6166
resolution: { type: '2f', value: { x: 256, y: 256 }},
62-
mouse: { type: '2f', value: { x: 0.0, y: 0.0 }}
67+
time: { type: '1f', value: 0 },
68+
mouse: { type: '2f', value: { x: 0.0, y: 0.0 } },
69+
date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() *60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] },
70+
sampleRate: { type: '1f', value: 44100.0 },
71+
iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } },
72+
iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } },
73+
iChannel2: { type: 'sampler2D', value: null, textureData: { repeat: true } },
74+
iChannel3: { type: 'sampler2D', value: null, textureData: { repeat: true } }
6375

6476
};
6577

78+
// Copy over/replace any passed in the constructor
79+
if (uniforms)
80+
{
81+
for (var key in uniforms)
82+
{
83+
this.uniforms[key] = uniforms[key];
84+
}
85+
}
86+
6687
/**
6788
* @property {array} fragmentSrc - The fragment shader code.
6889
*/

0 commit comments

Comments
 (0)