-
Notifications
You must be signed in to change notification settings - Fork 1
/
v002.AnalogGlitch.frag
51 lines (39 loc) · 1.36 KB
/
v002.AnalogGlitch.frag
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
// define our rectangular texture samplers
uniform sampler2DRect tex0;
uniform sampler2DRect tex1; // bars and distortion texture
uniform vec2 texdim0;
uniform float barsamount; // changes bars amount
uniform float distortion; // amount of distortion
uniform int resolution; // for scanlines
uniform float vsync; // sync
uniform float hsync;
// define our varying texture coordinates
varying vec2 texcoord0;
void main (void)
{
vec2 point = texcoord0/texdim0;
vec2 original = point;
// sample center of the 1st pixel, down the height
// bars should be 1x height of incoming image
vec4 bars = texture2DRect(tex1, vec2(0.5, texdim0.y));
// scanlines
vec4 stripes; // our base 'stripe color'
stripes = vec4(floor(mod(texcoord0.y, float(resolution)+0.0001)));
stripes = clamp(stripes, 0.0, 1.0);
stripes = 2.0 - (stripes - vec4(0.)); // subtract
// get rough luma
vec4 key = texture2DRect(tex0, (vec2(point.y, point.y)) * texdim0);
key += texture2DRect(tex0, (1.0 - vec2(point.y, point.y)) * texdim0);
key -= bars.r;
//key *= 0.33;
float d = key.r + key.g + key.b;
d /= 3.0;
point.x -= d * distortion * 0.1;
//sync
vec2 texcoord = point + ( mod(vec2(hsync, vsync), 1.0));
// wrap
texcoord = mod(texcoord, 1.0);
// outout
vec4 result = texture2DRect(tex0, texcoord * texdim0);
gl_FragColor = mix(result, bars*result, barsamount);
}