-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiming1.frag
120 lines (97 loc) · 2.82 KB
/
Timing1.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
#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;
}
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);
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 * 14.0, v0;
// Bar animations
if (n0 < 1.0) {
v0 = smoothstep(1., angle/PI, t);
} else if (n0 < 1.5) {
v0 = smoothstep(1., angle/PI, easeInQuad(t));
} else if (n0 < 2.0) {
v0 = smoothstep(1., angle/PI, easeOutQuad(t));
} else if (n0 < 2.5) {
v0 = smoothstep(1., angle/PI, easeInOutQuad(t));
} else if (n0 < 3.0) {
v0 = smoothstep(1., angle/PI, easeInCubic(t));
} else if (n0 < 3.5) {
v0 = smoothstep(1., angle/PI, easeOutCubic(t));
} else if (n0 < 7.0) {
v0 = smoothstep(1., angle/PI, easeInOutCubic(t));
} else if (n0 < 8.0) {
v0 = smoothstep(1., angle/PI, easeInExpo(t));
} else if (n0 < 9.0) {
v0 = smoothstep(1., angle/PI, easeOutExpo(t));
} else if (n0 < 10.0) {
v0 = smoothstep(1.1, angle/PI, easeOutExpo(t));
} else {
v0 = smoothstep(.7, radius, easeInOutExpo(t));
}
color += mix(color, vec3(st, abs(cos(u_time))), v0);
gl_FragColor = vec4(color, 1.0);
}