1+ /* global define, require */
2+ ( function ( root , factory ) {
3+ 'use strict' ;
4+ if ( typeof define === 'function' && define . amd ) {
5+ define ( [ 'seriously' ] , factory ) ;
6+ } else if ( typeof exports === 'object' ) {
7+ factory ( require ( 'seriously' ) ) ;
8+ } else {
9+ if ( ! root . Seriously ) {
10+ root . Seriously = { plugin : function ( name , opt ) { this [ name ] = opt ; } } ;
11+ }
12+ factory ( root . Seriously ) ;
13+ }
14+ } ( window , function ( Seriously ) {
15+ 'use strict' ;
16+
17+ Seriously . plugin ( 'glitch' , {
18+ commonShader : true ,
19+ shader : function ( inputs , shaderSource ) {
20+ shaderSource . vertex = [
21+ 'precision mediump float;' ,
22+ 'attribute vec3 position;' ,
23+ 'attribute vec2 texCoord;' ,
24+ 'uniform mat4 transform;' ,
25+ 'varying vec2 vTexCoord;' ,
26+ 'void main(void) {' ,
27+ ' vTexCoord = texCoord;' ,
28+ ' gl_Position = transform * vec4(position, 1.0);' ,
29+ '}'
30+ ] . join ( '\n' ) ;
31+
32+ shaderSource . fragment = [
33+ 'precision mediump float;' ,
34+ 'varying vec2 vTexCoord;' ,
35+ 'uniform sampler2D source;' ,
36+ 'uniform float amount;' ,
37+ 'uniform float frequency;' ,
38+ 'uniform float speed;' ,
39+ 'uniform float time;' ,
40+
41+ 'float rand(vec2 co) {' ,
42+ ' return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);' ,
43+ '}' ,
44+
45+ 'void main(void) {' ,
46+ ' vec2 uv = vTexCoord;' ,
47+ ' float t = time * speed * 0.01;' ,
48+ ' float freq = frequency * 0.01;' ,
49+ ' float amt = amount * 0.005;' ,
50+
51+ ' float glitch = step(1.0 - freq, rand(vec2(t, uv.y)));' ,
52+
53+ ' uv.x += glitch * (rand(vec2(uv.y, t)) - 0.5) * amt;' ,
54+ ' uv.y += glitch * (rand(vec2(uv.x, t)) - 0.5) * amt * 0.5;' ,
55+
56+ ' vec4 color = texture2D(source, uv);' ,
57+
58+ ' float r = texture2D(source, uv + vec2(amt * 0.5, 0.0)).r;' ,
59+ ' float g = color.g;' ,
60+ ' float b = texture2D(source, uv - vec2(amt * 0.5, 0.0)).b;' ,
61+
62+ ' gl_FragColor = vec4(r, g, b, color.a);' ,
63+ '}'
64+ ] . join ( '\n' ) ;
65+ } ,
66+
67+ inputs : {
68+ source : {
69+ type : 'image' ,
70+ uniform : 'source'
71+ } ,
72+ amount : {
73+ type : 'number' ,
74+ uniform : 'amount' ,
75+ defaultValue : 0 ,
76+ min : 0 ,
77+ max : 200
78+ } ,
79+ frequency : {
80+ type : 'number' ,
81+ uniform : 'frequency' ,
82+ defaultValue : 0 ,
83+ min : 0 ,
84+ max : 200
85+ } ,
86+ speed : {
87+ type : 'number' ,
88+ uniform : 'speed' ,
89+ defaultValue : 0 ,
90+ min : 0 ,
91+ max : 200
92+ } ,
93+ time : {
94+ type : 'number' ,
95+ uniform : 'time' ,
96+ defaultValue : 0
97+ }
98+ } ,
99+
100+ title : 'Glitch'
101+ } ) ;
102+
103+ } ) ) ;
0 commit comments