forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixelate.js
65 lines (48 loc) · 1.66 KB
/
Pixelate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Original author of PixelateFilter: Mat Groves http://matgroves.com/ @Doormat23
* adapted for Phaser.js
*/
/**
* This filter applies a pixelate effect making display objects appear 'blocky'
* @class PixelateFilter
* @contructor
*/
Phaser.Filter.Pixelate = function(game) {
Phaser.Filter.call(this, game);
this.passes = [this];
this.uniforms.invert = { type: '1f', value: 0 };
this.uniforms.pixelSize = { type: '2f', value: { x: 10, y: 10 } };
this.uniforms.dimensions = { type: '4fv', value: { x: 10000, y: 100, z: 10, w: 10 } };
this.fragmentSrc = [
"precision mediump float;",
"varying vec2 vTextureCoord;",
"varying vec4 vColor;",
"uniform vec2 testDim;",
"uniform vec4 dimensions;",
"uniform vec2 pixelSize;",
"uniform sampler2D uSampler;",
"void main(void)",
"{",
"vec2 coord = vTextureCoord;",
"vec2 size = dimensions.xy/pixelSize;",
"vec2 color = floor( ( vTextureCoord * size ) ) / size + pixelSize/dimensions.xy * 0.5;",
"gl_FragColor = texture2D(uSampler, color);",
"}"
];
};
Phaser.Filter.Pixelate.prototype = Object.create(Phaser.Filter.prototype);
Phaser.Filter.Pixelate.prototype.constructor = Phaser.Filter.Pixelate;
/**
* This a point that describes the size of the blocs. x is the width of the block and y is the the height
* @property size
* @type Point
*/
Object.defineProperty(Phaser.Filter.prototype, 'size', {
get: function() {
return this.uniforms.pixelSize.value;
},
set: function(value) {
this.dirty = true;
this.uniforms.pixelSize.value = value;
}
});