Skip to content

Commit 913ccaf

Browse files
committed
Fixed the Pixelate filter, changing the dimensions uniform to a 2f and removing un-needed vecs from the fragment src. Also fixed the size getter and added sizeX and sizeY getters/setters (phaserjs#1780)
1 parent 8db0bfa commit 913ccaf

1 file changed

Lines changed: 57 additions & 14 deletions

File tree

filters/Pixelate.js

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@
44
*/
55

66
/**
7-
* This filter applies a pixelate effect making display objects appear 'blocky'
7+
* This filter applies a pixelate effect making display objects appear 'blocky'.
88
* @class PixelateFilter
9-
* @contructor
9+
* @constructor
1010
*/
1111
Phaser.Filter.Pixelate = function(game) {
1212

1313
Phaser.Filter.call(this, game);
1414

15-
this.passes = [this];
16-
1715
this.uniforms.invert = { type: '1f', value: 0 };
18-
this.uniforms.pixelSize = { type: '2f', value: { x: 10, y: 10 } };
19-
this.uniforms.dimensions = { type: '4fv', value: { x: 10000, y: 100, z: 10, w: 10 } };
16+
this.uniforms.pixelSize = { type: '2f', value: { x: 1.0, y: 1.0 } };
17+
this.uniforms.dimensions = { type: '2f', value: { x: 1000.0, y: 1000.0 } };
2018

2119
this.fragmentSrc = [
2220

2321
"precision mediump float;",
2422
"varying vec2 vTextureCoord;",
25-
"varying vec4 vColor;",
26-
"uniform vec2 testDim;",
27-
"uniform vec4 dimensions;",
23+
"uniform vec2 dimensions;",
2824
"uniform vec2 pixelSize;",
2925
"uniform sampler2D uSampler;",
3026

@@ -43,11 +39,12 @@ Phaser.Filter.Pixelate.prototype = Object.create(Phaser.Filter.prototype);
4339
Phaser.Filter.Pixelate.prototype.constructor = Phaser.Filter.Pixelate;
4440

4541
/**
46-
* This a point that describes the size of the blocs. x is the width of the block and y is the the height
47-
* @property size
48-
* @type Point
49-
*/
50-
Object.defineProperty(Phaser.Filter.prototype, 'size', {
42+
* An object with visible x and y properties that are used to define the size of the filter effect per pixel.
43+
*
44+
* @property size
45+
* @type Phaser.Point
46+
*/
47+
Object.defineProperty(Phaser.Filter.Pixelate.prototype, 'size', {
5148

5249
get: function() {
5350

@@ -63,3 +60,49 @@ Object.defineProperty(Phaser.Filter.prototype, 'size', {
6360
}
6461

6562
});
63+
64+
/**
65+
* A value that defines the horizontal size of the filter effect per pixel.
66+
*
67+
* @property sizeX
68+
* @type number
69+
*/
70+
Object.defineProperty(Phaser.Filter.Pixelate.prototype, 'sizeX', {
71+
72+
get: function() {
73+
74+
return this.uniforms.pixelSize.value.x;
75+
76+
},
77+
78+
set: function(value) {
79+
80+
this.dirty = true;
81+
this.uniforms.pixelSize.value.x = value;
82+
83+
}
84+
85+
});
86+
87+
/**
88+
* A value that defines the vertical size of the filter effect per pixel.
89+
*
90+
* @property sizeY
91+
* @type number
92+
*/
93+
Object.defineProperty(Phaser.Filter.Pixelate.prototype, 'sizeY', {
94+
95+
get: function() {
96+
97+
return this.uniforms.pixelSize.value.y;
98+
99+
},
100+
101+
set: function(value) {
102+
103+
this.dirty = true;
104+
this.uniforms.pixelSize.value.y = value;
105+
106+
}
107+
108+
});

0 commit comments

Comments
 (0)