-
Notifications
You must be signed in to change notification settings - Fork 6
/
34_Kaleidolines.fs
executable file
·152 lines (139 loc) · 3 KB
/
34_Kaleidolines.fs
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
{
"CATEGORIES" : [
"Generator"
],
"DESCRIPTION" : "",
"INPUTS" : [
{
"NAME" : "invert",
"TYPE" : "bool",
"DEFAULT" : true
},
{
"NAME" : "zoom",
"TYPE" : "float",
"MAX" : 20,
"DEFAULT" : 3.3019793033599854,
"MIN" : 0.25
},
{
"NAME" : "rotateCanvas",
"TYPE" : "float",
"MAX" : 1,
"DEFAULT" : 0.45078930258750916,
"MIN" : 0
},
{
"NAME" : "rotateLines",
"TYPE" : "float",
"MAX" : 1,
"DEFAULT" : 0.2777867317199707,
"MIN" : 0
},
{
"NAME" : "lineThickness",
"TYPE" : "float",
"MAX" : 20,
"DEFAULT" : 5.9209065437316895,
"MIN" : 0.10000000000000001
},
{
"NAME" : "lineLength",
"TYPE" : "float",
"MAX" : 10,
"DEFAULT" : 2.6872844696044922,
"MIN" : 0.050000000000000003
},
{
"NAME" : "lines1",
"TYPE" : "float",
"MAX" : 10,
"DEFAULT" : 6.8404679298400879,
"MIN" : 1
},
{
"NAME" : "lines2",
"TYPE" : "float",
"MAX" : 10,
"DEFAULT" : 9.7506446838378906,
"MIN" : 1
},
{
"NAME" : "offset",
"TYPE" : "float",
"MAX" : 2,
"DEFAULT" : 0.54888850450515747,
"MIN" : -2
},
{
"NAME" : "motion",
"TYPE" : "float",
"MAX" : 1,
"DEFAULT" : 0.82939350605010986,
"MIN" : 0
},
{
"NAME" : "pos",
"TYPE" : "point2D",
"MAX" : [
1,
1
],
"DEFAULT" : [
0.5,
0.5
],
"MIN" : [
0,
0
]
}
],
"ISFVSN" : "2",
"CREDIT" : ""
}
*/
#define TAU 6.28318530718
mat2 rotate2d(float _angle){
return mat2(cos(_angle),-sin(_angle),
sin(_angle),cos(_angle));
}
vec2 tile(vec2 _st, float _zoom){
_st *= _zoom;
return fract(_st);
}
float segment(vec2 p, vec2 a, vec2 b) {
vec2 ab = b - a;
vec2 ap = p - a;
float k = clamp(dot(ap, ab)/dot(ab, ab), 0.0, lineLength);
return smoothstep(0.0, 0.003 + lineThickness/RENDERSIZE.y, length(ap - k*ab) - (0.001 * lineThickness * 5. ));
}
float shape(vec2 p, float angle) {
float d = 100.0;
vec2 a = vec2(1.0, 0.0), b;
vec2 rot = vec2(cos(angle), sin(angle));
for (int i = 0; i < 10; ++i) {
a = a + offset;
if (i >= int(lines1)) break;
b = a;
for (int j = 0; j < 10; ++j) {
if (j >= int(lines2)) break;
b = vec2(b.x*rot.x - b.y*rot.y, b.x*rot.y + b.y*rot.x);
p = rotate2d(rotateLines* -TAU) * p;
d = min(d, segment(p, a, b));
}
a = vec2(a.x*rot.x - a.y*rot.y, a.x*rot.y + a.y*rot.x);
}
return d;
}
void main() {
vec2 uv = gl_FragCoord.xy / RENDERSIZE.xy;
uv -= vec2(pos);
uv.x *= RENDERSIZE.x/RENDERSIZE.y;
uv = rotate2d(rotateCanvas *-TAU) * uv;
uv *= zoom;
float col = shape(abs(uv), cos((motion * TAU)));
if (invert) col = col *-1.0 + 1.0;
gl_FragColor = vec4(vec3(col), 1.0);
}