|
| 1 | +#version 420 core |
| 2 | + |
| 3 | +uniform float fGlobalTime; // in seconds |
| 4 | +uniform vec2 v2Resolution; // viewport resolution (in pixels) |
| 5 | +uniform float fFrameTime; // duration of the last frame, in seconds |
| 6 | +uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq |
| 7 | +uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients |
| 8 | +uniform sampler1D texFFTIntegrated; // this is continually increasing |
| 9 | +uniform sampler2D texPreviousFrame; // screenshot of the previous frame |
| 10 | +uniform sampler2D texTex1; |
| 11 | +uniform sampler2D texTex2; |
| 12 | +uniform sampler2D texTex3; |
| 13 | +uniform sampler2D texTex4; |
| 14 | +layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything |
| 15 | +#define time fGlobalTime |
| 16 | + |
| 17 | +float sd_box(vec3 p, vec3 e) |
| 18 | +{ |
| 19 | + p = abs(p)-e; |
| 20 | + return length(max(p,0)) + min(0,max(p.x,max(p.y,p.z))); |
| 21 | +} |
| 22 | + |
| 23 | +const float bpm=142/60; |
| 24 | +vec4 s = time*bpm/vec4(1,4,8,16),t=fract(s); |
| 25 | +#define r2(a) mat2(cos(a),-sin(a),sin(a),cos(a)) |
| 26 | +const float pi = acos(-1); |
| 27 | +#define sin2(x) (.5+.5*sin(x)) |
| 28 | + |
| 29 | +uint hash(uint x){ |
| 30 | + const uint c = int((1.-sqrt(5)/2)*-1u)|1; |
| 31 | + x ^= x >> 16; |
| 32 | + x *= c; |
| 33 | + x ^= x >> 15; |
| 34 | + x *= c; |
| 35 | + x ^= x >> 16; |
| 36 | + return x; |
| 37 | +} |
| 38 | + |
| 39 | +uint rnd(ivec3 p) |
| 40 | +{ |
| 41 | + return hash(hash(hash(p.x)+p.y)+p.z); |
| 42 | +} |
| 43 | + |
| 44 | +float rnd(vec2 p) |
| 45 | +{ |
| 46 | + return hash(floatBitsToUint(p.y)+hash(floatBitsToUint(p.x)))/float(-1u); |
| 47 | +} |
| 48 | + |
| 49 | +vec3 rnd3(float v) |
| 50 | +{ |
| 51 | + uint x = hash(floatBitsToUint(v)); |
| 52 | + uint y = hash(x+floatBitsToUint(v)); |
| 53 | + uint z = hash(y+floatBitsToUint(v)); |
| 54 | + return vec3(x,y,z)/float(-1u); |
| 55 | +} |
| 56 | +uint seed = 1; |
| 57 | +float rnd(float x) |
| 58 | +{ |
| 59 | + return rnd(ivec3(seed+++floatBitsToUint(x), gl_FragCoord.xy))/float(-1u); |
| 60 | +} |
| 61 | +vec3 rndunit(float x) { |
| 62 | + return normalize(tan(rnd3(x)*2.-1.)); |
| 63 | +} |
| 64 | +vec3 erot(vec3 p, vec3 x, float a) |
| 65 | +{ |
| 66 | + return mix(dot(x,p)*x,p, cos(a))+cross(x,p)*sin(a); |
| 67 | +} |
| 68 | + |
| 69 | +vec2 sdf(vec3 p) { |
| 70 | + vec2 r=vec2(1e9,0); |
| 71 | + { |
| 72 | + float d; |
| 73 | + vec3 q = p; |
| 74 | + |
| 75 | + q = erot(q, normalize(vec3(1,1,0)), pi*(floor(s.x/2.0)+pow(fract(s.x/2.0),.5))); |
| 76 | + q.xz *= r2(pi*s.w); |
| 77 | + q.xz -= clamp(round(q.xz/4),-2,2)*4; |
| 78 | + |
| 79 | + q.y = abs(q.y)-2.; |
| 80 | + q.xz *= r2(q.y*pi*mix(0.1,0.25,t.z)); |
| 81 | + |
| 82 | + q.xy *= r2(0.125*pi); |
| 83 | + q.zy *= r2(-0.15*pi); |
| 84 | + |
| 85 | + float dy= 20*pow(t.y,.5); |
| 86 | + d = sd_box(q,vec3(.5,4.*t.x,.5)); |
| 87 | + if (d < r.x) { r.x = d; r.y = 1; } |
| 88 | + } |
| 89 | + if (false) |
| 90 | + { |
| 91 | + vec3 q = p.yxz; |
| 92 | + float d = 1e9; |
| 93 | + |
| 94 | + q = erot(q, normalize(vec3(1,1,0)), pi*(floor(s.x/2.0)+pow(fract(s.x/2.0),.5))); |
| 95 | + q.xz *= r2(pi*s.w); |
| 96 | + |
| 97 | + q.y = abs(q.y)-2.; |
| 98 | + q.xz *= r2(q.y*pi*mix(0.1,0.25,t.z)); |
| 99 | + |
| 100 | + q.xy *= r2(0.5*pi); |
| 101 | + d = sd_box(q,vec3(.2,10.,.2)); |
| 102 | + if (d < r.x) { r.x = d; r.y = 2; } |
| 103 | + } |
| 104 | + return r; |
| 105 | +} |
| 106 | + |
| 107 | +vec3 nrm(vec3 p) |
| 108 | +{ |
| 109 | + vec2 e = vec2(1,-1); |
| 110 | + float h = 5e-3; |
| 111 | + return normalize( |
| 112 | + e.xyy*sdf(p+e.xyy*h).x+ |
| 113 | + e.yxy*sdf(p+e.yxy*h).x+ |
| 114 | + e.yyx*sdf(p+e.yyx*h).x+ |
| 115 | + e.xxx*sdf(p+e.xxx*h).x |
| 116 | + ); |
| 117 | +} |
| 118 | + |
| 119 | +void main(void) |
| 120 | +{ |
| 121 | + vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y); |
| 122 | + vec2 tv = uv; |
| 123 | + uv -= 0.5; |
| 124 | + uv /= vec2(v2Resolution.y / v2Resolution.x, 1); |
| 125 | + vec3 col = vec3(0); |
| 126 | + float fv = .5; |
| 127 | + vec3 at = vec3(0,0,0); |
| 128 | + vec3 ro = vec3(0,0,4); |
| 129 | + |
| 130 | + fv = mix(0.1,0.5,pow(t.y,0.25)); |
| 131 | + fv += pow(t.x,.4)*0.2; |
| 132 | + vec3 cz = normalize(at-ro), |
| 133 | + cx=normalize(cross(cz,vec3(0,1,0))), |
| 134 | + cy=normalize(cross(cz,cx)),rd; |
| 135 | + float j,i,h, d, r; |
| 136 | + vec3 p; |
| 137 | + float si = 1; |
| 138 | + vec3 _ro = ro; |
| 139 | + |
| 140 | + for (j=0;j<2;j++) { |
| 141 | + rd=mat3(cx,cy,cz)*normalize(vec3(uv+.001*vec2(rnd(j+time),rnd(j-time)),fv)); |
| 142 | + ro=_ro; |
| 143 | + for (i=0,r=0,h=4; i<64; i++) { |
| 144 | + p = rd*r+ro; |
| 145 | + vec2 rr = sdf(p); |
| 146 | + rr.x *= (1.-rnd(time)*.2); |
| 147 | + r+=d=rr.x*.9; |
| 148 | + if (d<1e-3 && rr.y ==1 && h-->0){ |
| 149 | + vec3 n = nrm(p=rd*r+ro); |
| 150 | + rd = mix(reflect(rd, -n), rndunit(p.x+p.y+p.z),.03); |
| 151 | + ro = p + .1*n; |
| 152 | + r = 0; |
| 153 | + continue; |
| 154 | + } |
| 155 | + if (d<1e-3 ||r>1e3)break; |
| 156 | + } |
| 157 | + col.r += i/64; |
| 158 | + } |
| 159 | + col.r = pow(col.r/j + (rnd(time)+rnd(time))/64., 1.2); |
| 160 | + col.r = pow(col.r,mix(2.,1.5,t.x)); |
| 161 | + col.rgb = col.rrr; |
| 162 | + |
| 163 | + { |
| 164 | + vec3 pre = texture(texPreviousFrame, .5+(tv-.5)*.99).rgb; |
| 165 | + col = mix(pre, col, .99*pow(t.x,.5)); |
| 166 | + } |
| 167 | + |
| 168 | + { |
| 169 | + vec2 id = floor(tv*100.0); |
| 170 | + vec3 pre = texture(texPreviousFrame, .5+(id/100.0-.5)).rgb; |
| 171 | + col = mix(pre, col, step(0.2,rnd(id.x+rnd(id.y)))); |
| 172 | + } |
| 173 | + |
| 174 | + out_color = vec4(col, 1); |
| 175 | +} |
| 176 | + |
0 commit comments