forked from lilybeevee/bab-be-u
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader_pucker.txt
81 lines (72 loc) · 2.17 KB
/
shader_pucker.txt
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
// ZA WARUDO
// helper function, please ignore
number _hue(number s, number t, number h)
{
h = mod(h, 1.);
number six_h = 6.0 * h;
if (six_h < 1.) return (t-s) * six_h + s;
if (six_h < 3.) return t;
if (six_h < 4.) return (t-s) * (4.-six_h) + s;
return s;
}
// input: vec4(h,s,l,a), with h,s,l,a = 0..1
// output: vec4(r,g,b,a), with r,g,b,a = 0..1
vec4 hsl_to_rgb(vec4 c)
{
if (c.y == 0)
return vec4(vec3(c.z), c.a);
number t = (c.z < .5) ? c.y*c.z + c.z : -c.y*c.z + (c.y+c.z);
number s = 2.0 * c.z - t;
return vec4(_hue(s,t,c.x + 1./3.), _hue(s,t,c.x), _hue(s,t,c.x - 1./3.), c.w);
}
// input: vec4(r,g,b,a), with r,g,b,a = 0..1
// output: vec4(h,s,l,a), with h,s,l,a = 0..1
vec4 rgb_to_hsl(vec4 c)
{
number low = min(c.r, min(c.g, c.b));
number high = max(c.r, max(c.g, c.b));
number delta = high - low;
number sum = high+low;
vec4 hsl = vec4(.0, .0, .5 * sum, c.a);
if (delta == .0)
return hsl;
hsl.y = (hsl.z < .5) ? delta / sum : delta / (2.0 - sum);
if (high == c.r)
hsl.x = (c.g - c.b) / delta;
else if (high == c.g)
hsl.x = (c.b - c.r) / delta + 2.0;
else
hsl.x = (c.r - c.g) / delta + 4.0;
hsl.x = mod(hsl.x / 6., 1.);
return hsl;
}
uniform number time;
number pi = atan(1.0)*4.0;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 scoord) {
//distort part
vec2 npos = texture_coords;
number cx = texture_coords.x-0.5;
number cy = texture_coords.y-0.5;
number dist = sqrt(cx*cx + cy*cy);
cx = cx/dist;
cy = cy/dist;
number circle = sin(min(time/130,pi))*1.2;
npos.x = npos.x + (cx/6 * sin((dist-0.7)*17)/2) * circle;
npos.y = npos.y + (cy/6 * sin((dist-0.7)*17)/2) * circle;
vec4 texturecolor = Texel(texture, npos);
texturecolor = texturecolor * color;
//color part
if(dist < circle) {
texturecolor.r = 1 - texturecolor.r;
texturecolor.g = 1 - texturecolor.g;
texturecolor.b = 1 - texturecolor.b;
vec4 chromcolo = rgb_to_hsl(texturecolor);
chromcolo.x = 0.666 + time/400;
if(mod(circle - dist, 0.4/3) < 0.06 && circle - dist < 0.4) {
chromcolo.z = 1;
chromcolo.a = 1;
}
texturecolor = hsl_to_rgb(chromcolo);
}
return vec4(texturecolor.r, texturecolor.g, texturecolor.b, texturecolor.a);
}