-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.glsl
109 lines (83 loc) · 2.03 KB
/
main.glsl
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
#define PI 3.1415926535897932384626433832795
precision mediump float;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 unit = vec2(1.0, 0.0);
vec2 i = vec2(0.0, 1.0);
vec4 color_light = vec4(0.9, 0.9, 0.9, 1.0);
vec4 color_dark = vec4(0.4, 0.4, 0.4, 1.0);
float time() {
return 1.0 + u_time / 10.0;
}
vec2 conj(vec2 a) {
return vec2(a.x, - a.y);
}
vec2 mul(vec2 a, vec2 b) {
return vec2(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
vec2 div(vec2 a, vec2 b) {
return mul(a, conj(b)) / dot(b, b);
}
vec2 Exp(vec2 a) {
return exp(a.x) * vec2(cos(a.y), sin(a.y));
}
vec2 Log(vec2 a) {
return vec2(log(length(a)), atan(a.y, a.x));
}
vec2 elliptic(vec2 a) {
return mul(a, Exp(time() * i));
}
vec2 parabolic(vec2 a) {
return a + time() * unit;
}
vec2 hyperbolic(vec2 a) {
return mul(a, Exp(time() * unit));
}
vec2 loxodromic(vec2 a) {
return mul(a, Exp(time() * (unit + i)));
}
// Mobius transformation with fixed points q1 and q2
vec2 M2(vec2 a, vec2 q1, vec2 q2) {
return div(a - q1, a - q2);
}
// M2 inverse
vec2 M2i(vec2 a, vec2 q1, vec2 q2) {
return div(mul(-q2, a) + q1, - a + unit);
}
// Mobius transformation with a fixed point q
vec2 M1(vec2 a, vec2 q) {
return div(unit, a - q);
}
// M1 inverse
vec2 M1i(vec2 a, vec2 q) {
return div(unit, a) + q;
}
vec2 toComplex(vec2 a) {
vec2 z = a.xy / u_resolution.xy;
z += vec2(-0.5, - 0.5);
z *= 5.0;
z.x *= u_resolution.x / u_resolution.y;
return z;
}
vec4 checkerboard(vec2 a) {
if (mod(floor(a.x) + floor(a.y), 2.0) > 0.0)
return color_light;
else
return color_dark;
}
vec4 dartboard(vec2 a) {
float r = 2.0 * log(length(a));
float t = 8.0 * atan(a.y, a.x) / PI;
if (mod(floor(r) + floor(t), 2.0) > 0.0)
return color_light;
else
return color_dark;
}
void main() {
vec2 z = toComplex(gl_FragCoord.xy);
vec2 m = toComplex(u_mouse);
vec2 w = M2(z, unit, - unit);
w = loxodromic(w);
gl_FragColor = dartboard(w);
}