-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiming1c.frag
132 lines (106 loc) · 3.02 KB
/
Timing1c.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
//--------------------------------------------—-
#define PI 3.14159265358979323846
#define TWO_PI 6.28318530718
#define IVORY vec3(1.0, 0.9, 0.8)
#define SUNSET vec3(0.9, 0.3, 0.3)
#define NAVY vec3(0.0, 0.1, 0.2)
vec2 rotate2D(vec2 _st, float _angle) {
_st -= 0.5;
_st = mat2(cos(_angle), -sin(_angle),
sin(_angle), cos(_angle)) * _st;
_st += 0.5;
return _st;
}
vec2 tile(vec2 _st, float _zoom) {
_st *= _zoom;
return fract(_st);
}
float easeInQuad(float t) {
return t * t;
}
float easeOutQuad(float t) {
return -1.0 * t * (t - 2.0);
}
float easeInOutQuad(float t) {
if ((t *= 2.0) < 1.0) {
return 0.5 * t * t;
} else {
return -0.5 * ((t - 1.0) * (t - 3.0) - 1.0);
}
}
float easeInCubic(float t) {
return t * t * t;
}
float easeOutCubic(float t) {
return (t = t - 1.0) * t * t + 1.0;
}
float easeInOutCubic(float t) {
if ((t *= 2.0) < 1.0) {
return 0.5 * t * t * t;
} else {
return 0.5 * ((t -= 2.0) * t * t + 2.0);
}
}
float easeInExpo(float t) {
return (t == 0.0) ? 0.0 : pow(2.0, 10.0 * (t - 1.0));
}
float easeOutExpo(float t) {
return (t == 1.0) ? 1.0 : -pow(2.0, -10.0 * t) + 1.0;
}
float easeInOutExpo(float t) {
if (t == 0.0 || t == 1.0) {
return t;
}
if ((t *= 2.0) < 1.0) {
return 0.5 * pow(2.0, 10.0 * (t - 1.0));
} else {
return 0.5 * (-pow(2.0, -10.0 * (t - 1.0)) + 2.0);
}
}
void main() {
vec2 st = gl_FragCoord.xy / u_resolution;
vec3 color = vec3(.09);
// UV values goes from -1 to 1
// So we need to remap st (0.0 to 1.0)
st -= 0.5; // becomes -0.5 to 0.5
st *= 14.0; // becomes -1.0 to 1.0
st += .25;
st += rotate2D(st, easeInOutExpo(abs(sin(u_time))) * TWO_PI);
// Use polar coordinates instead of cartesian
vec2 toCenter = vec2(0.5) - st;
float angle = atan(toCenter.y, toCenter.x);
float radius = length(toCenter) * 2.0;
float t = abs(sin(u_time)), n0 = radius, v0;
// Bar animations
if (n0 < 1.0) {
v0 = smoothstep(.01, .35, t);
} else if (n0 < 2.0) {
v0 = smoothstep(.01, .35, easeInQuad(t));
} else if (n0 < 3.0) {
v0 = smoothstep(.01, .35, easeOutQuad(t));
} else if (n0 < 4.0) {
v0 = smoothstep(.01, .35, easeInOutQuad(t));
} else if (n0 < 5.0) {
v0 = smoothstep(.01, .35, easeInCubic(t));
} else if (n0 < 6.0) {
v0 = smoothstep(.01, .35, easeOutCubic(t));
} else if (n0 < 7.0) {
v0 = smoothstep(.01, .35, easeInOutCubic(t));
} else if (n0 < 8.0) {
v0 = smoothstep(.01, .35, easeInExpo(t));
} else if (n0 < 9.0) {
v0 = smoothstep(.01, .35, easeOutExpo(t));
} else if (n0 < 10.0) {
v0 = smoothstep(.01, .35, easeOutExpo(t));
} else {
v0 = smoothstep(.0, radius, easeInOutExpo(t));
}
color += mix(color, vec3(st, abs(cos(t))), v0);
gl_FragColor = vec4(color, 1.0);
}