-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPostprocessing.js
62 lines (40 loc) · 1.63 KB
/
Postprocessing.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
Postprocessing = {}
Postprocessing.init = function(game) {
// From http://glslsandbox.com/e#18578.0
var fragmentSrc = [
"precision mediump float;",
"uniform float time;",
"uniform vec2 resolution;",
"uniform vec2 mouse;",
"float noise(vec2 pos) {",
"return fract(sin(dot(pos, vec2(12.9898 - time,78.233 + time))) * 43758.5453);",
"}",
"void main( void ) {",
"vec2 normalPos = gl_FragCoord.xy / resolution.xy;",
"float pos = (gl_FragCoord.y / resolution.y);",
"float mouse_dist = length(vec2((mouse.x - normalPos.x) * (resolution.x / resolution.y) , mouse.y - normalPos.y));",
"float distortion = clamp(1.0 - (mouse_dist + 0.1) * 3.0, 0.0, 1.0);",
"pos -= (distortion * distortion) * 0.1;",
"float c = sin(pos * 400.0) * 0.4 + 0.4;",
"c = pow(c, 0.2);",
"c *= 0.2;",
"float band_pos = fract(time * 0.1) * 2.0 - 1.0;",
"c += clamp( (1.0 - abs(band_pos - pos) * 10.0), 0.0, 1.0) * 0.1;",
"c += distortion * 0.08;",
"// noise",
"c += (noise(gl_FragCoord.xy) - 0.5) * (0.09);",
"gl_FragColor = vec4( c, c*0.5, c, 0.0 );",
"}"
];
this.filter = new Phaser.Filter(game, null, fragmentSrc);
this.filter.setResolution(800, 600);
var sprite = game.add.sprite();
sprite.width = 800;
sprite.height = 600;
//sprite.alpha = 0.5;
sprite.filters = [ this.filter ];
return sprite;
}
Postprocessing.update = function(coords) {
this.filter.update(coords);
}