comparison data/shaders/eye_post.fs @ 0:785057719d9b

Import.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 05 Aug 2013 12:25:43 +0300
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:785057719d9b
1 /* Fragment shader */
2
3 uniform float width;
4 uniform float height;
5
6 uniform float time;
7 uniform sampler2D texture0;
8 uniform sampler2D texture1;
9
10 float kernel[9];
11 vec2 offset[9];
12
13
14 float hash(float x)
15 {
16 return fract(sin(x) * 43758.5453);
17 }
18
19 float noise(vec3 x)
20 {
21 vec3 p = floor(x);
22 vec3 f = fract(x);
23 f = f*f*(3.0-2.0*f);
24 float n = p.x + p.y * 57.0 + p.z*113.0;
25
26 float a = hash(n);
27 return a;
28 }
29
30 float manhattan(vec3 v)
31 {
32 v = abs(v);
33 return v.x + v.y + v.z;
34 }
35
36 float cheby(vec3 v)
37 {
38 v = abs(v);
39 return v.x > v.y
40 ? (v.x > v.z ? v.x : v.z)
41 : (v.y > v.z ? v.y : v.z);
42 }
43
44 float vor(vec3 v)
45 {
46 vec3 start = floor(v);
47
48 float dist = 999999.0;
49 vec3 cand;
50
51 int z = 0;
52
53 for(int y = 0; y <= 4; y += 1)
54 {
55 for(int x = 0; x <= 4; x += 1)
56 {
57 vec3 t = start + vec3(-2+x, -2+y, -2+(x*y));
58 vec3 p = t + noise(t);
59
60 float d = manhattan(p - v);
61
62 if(d < dist)
63 {
64 dist = d;
65 cand = p;
66 }
67 }
68 }
69
70 vec3 delta = cand - v;
71
72 return manhattan(delta);
73 //return noise(cand); //length(delta);
74 }
75
76
77 void main()
78 {
79 float step_w = (1.0+abs(cos(time*0.00001)*9.0))/width;
80 float step_h = (1.0+abs(sin(time*0.00001)*9.0))/height;
81
82 offset[0] = vec2(-step_w, -step_h);
83 offset[1] = vec2(0.0, -step_h);
84 offset[2] = vec2(step_w, -step_h);
85 offset[3] = vec2(-step_w, 0.0);
86 offset[4] = vec2(0.0, 0.0);
87 offset[5] = vec2(step_w, 0.0);
88 offset[6] = vec2(-step_w, step_h);
89 offset[7] = vec2(0.0, step_h);
90 offset[8] = vec2(step_w, step_h);
91
92 /* SHARPEN KERNEL
93 0 -1 0
94 -1 5 -1
95 0 -1 0
96 */
97
98
99 float val1 = 1.;
100 float val2 = 5.;
101 float val3 = 1.;
102
103 kernel[0] = val1;
104 kernel[1] = val2;
105 kernel[2] = val3;
106 kernel[3] = val1;
107 kernel[4] = 1.0;
108 kernel[5] = val3;
109 kernel[6] = val1;
110 kernel[7] = val2;
111 kernel[8] = val3;
112
113 vec4 sum = vec4(0.0);
114 int i;
115
116 for (i = 0; i < 9; i++) {
117 vec4 color = texture2D(texture0, vec2(gl_FragCoord.x/width, gl_FragCoord.y/height) + offset[i]);
118 vec4 color2 = texture2D(texture1, vec2(gl_FragCoord.x/width, gl_FragCoord.y/height));
119 sum += color * kernel[i]-(color2*(tan(time*0.1)*0.01));
120 }
121
122 gl_FragColor = sum;
123 }
124