x
158
 
1
/*
2
3
    daily: 010
4
    author: Will Stallwood
5
    insta: https://www.instagram.com/willstall/
6
    
7
*/
8
9
#ifdef GL_ES
10
    precision mediump float;
11
#endif
12
13
#define PI 3.14159265359
14
#define HALF_PI 1.57079632675
15
#define TWO_PI 6.283185307
16
17
uniform float u_float;
18
uniform vec2 u_vec2;
19
uniform vec3 u_vec3;
20
uniform vec4 u_vec4;
21
22
uniform vec2 u_resolution;
23
uniform vec2 u_mouse;
24
uniform float u_time;
25
26
/*
27
28
Inspiration:
29
https://www.instagram.com/p/BkaBfJplv6y/
30
31
*/
32
33
vec3 palette(float t,vec3 a,vec3 b,vec3 c,vec3 d )
34
{
35
    return a + b * cos( TWO_PI * (c*t+d));
36
}
37
38
vec3 colorize(float d,float t)
39
{
40
    return palette(d+t,vec3(0.5),
41
        vec3(0.5,0.5,0.2),
42
        vec3(1.0,1.0,1.0),
43
        vec3(0.3,.2,0.2));    
44
}
45
46
float random( in vec2 st )
47
{
48
    return fract( sin( dot(st.xy, vec2(-30.950,-10.810) )) * 43758.5453123  );      
49
}
50
51
float random( in float x )
52
{
53
    return fract(sin(x)*102670.0);
54
}
55
56
vec2 random2( vec2 p ) {
57
    return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453);
58
}
59
60
mat2 rotate(float angle)
61
{
62
    return mat2( cos(angle),-sin(angle),sin(angle),cos(angle) );
63
}
64
65
vec2 center(vec2 st)
66
{
67
    float aspect = u_resolution.x/u_resolution.y;
68
    st.x = st.x * aspect - aspect * 0.5 + 0.5;
69
    return st;
70
}
71
72
float manhattan_distance(vec2 x, vec2 y, float power)   // really wants a power of 1..2
73
{
74
    return pow(
75
            pow(abs(x.x-y.x),power) +
76
            pow(abs(x.y-y.y),power)
77
            ,1.0/power);
78
}
79
80
void main() {
81
    // config
82
    float scale = 3.0;
83
    float d = 1.0;
84
    float meta = 1.0;
85
86
    vec2 p = vec2(0.0);
87
    vec2 mp = vec2(0.0);
88
89
    // space
90
    vec2 st = gl_FragCoord.xy / u_resolution.xy;
91
    // st *= pow(length(st-0.5),0.5);
92
    st = center( st );   
93
    // st.x = mod(abs(pow(st.x-.5,.5+0.5*sin(u_time*.33))),1.0);
94
    // st = st * 2.0 - 1.0;
95
96
    // st *= scale*sin(u_time);
97
    
98
    vec2 sSt = st * scale * scale;
99
    sSt.y += u_time*.33;
100
    vec2 iSt = floor(sSt);
101
    vec2 fSt = fract(sSt);
102
    
103
    // get sdf based on neighbors
104
    for(int x = -1; x <= 1; x++)
105
    {
106
        for(int y = -1; y <= 1; y++)
107
        {
108
            vec2 offset = vec2(x,y);            
109
            vec2 point = random2(iSt+offset);
110
                point = 0.5 + 0.5 * sin(u_time * 0.5 + TWO_PI * point );
111
112
            // float diff = length(fSt - point - offset);
113
            float diff = manhattan_distance(fSt-point,offset,d+1.0+1.0*(0.5+0.5*sin(u_time)));
114
            float mDiff = diff * meta;
115
116
            if(meta > mDiff)
117
            {
118
                meta = mDiff;
119
                mp = point;
120
            }
121
            // diff *= d;
122
            // diff = smoothstep(0.0,c * scale,diff);
123
            if(d > diff)
124
            {
125
                d = diff;
126
                p = point;
127
            }
128
        }
129
    }
130
131
    meta = smoothstep(0.0001,0.001,abs(meta-.3)*mod(meta*30.0,4.0)-.3);
132
    meta += ceil(st*scale).x * sin(u_time*.33);
133
    
134
    // color    
135
    float color_id = random(floor(st*scale)+915392.0);
136
    float space_id = random(floor(st-p*scale)+189291.0);
137
138
    vec3 color = vec3(0.0);
139
140
    color = vec3(6.0,0.67,1.0) * colorize(meta*space_id,color_id+u_time*.13);
141
    color += (length(fract(st*scale))-.5)*.1;
142
    color += vec3(0.05,0.05,0.06);
143
144
    // fade config
145
    float fadeDuration = 15.0;    
146
    float fadeTime = 0.8;    
147
    vec3 fadeColor = vec3(246.0/255.0,49.0/255.,94.0/255.0);    
148
    // fade
149
    
150
    float fTime = mod( u_time, fadeDuration );
151
    float fT = 1.0;
152
    fT *= smoothstep(  0.0, fadeTime, fTime );
153
    fT *= 1.0 - smoothstep( fadeDuration-fadeTime, fadeDuration, fTime );
154
155
    color = mix(color,fadeColor,1.0-fT);
156
157
    gl_FragColor = vec4(color, 1.0);
158
}