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
|
#define PI 3.14159265358979323
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
float ssubtract(float a, float b, float k) {
return -smin(-a, b, k);
}
float rotational_repetition(vec2 p, int n, inout vec2 p1, inout vec2 p2) {
float del = 2. * PI / float(n);
float theta = atan(p.y, p.x);
float id = floor(theta / del);
float id2 = id + 1.;
p1 = mat2(cos(del * id), -sin(del * id), sin(del * id), cos(del * id)) * p;
p2 = mat2(cos(del * id2), -sin(del * id2), sin(del * id2), cos(del * id2)) * p;
return id;
}
// Easing
float ease_in_out_quart(in float x) {
return x < 0.5 ? 8 * x * x * x * x : 1 - pow(-2 * x + 2, 4) / 2;
}
vec2 ease_in_out_quart(in vec2 v) {
return vec2(ease_in_out_quart(v.x), ease_in_out_quart(v.y));
}
// Color utils
vec3 srgb(float r, float g, float b) {
return vec3(pow(r, 2.2), pow(g, 2.2), pow(b, 2.2));
}
vec3 srgb(vec3 c) {
return srgb(c.r, c.g, c.b);
}
vec3 srgb(float c) {
return srgb(c, c, c);
}
vec3 saturation(vec3 color, float s) {
float y = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
return vec3(
y + s * (color.r - y),
y + s * (color.g - y),
y + s * (color.b - y)
);
}
|