#extension GL_OES_standard_derivatives:enable precision highp float; uniform float time; uniform vec2 mouse,resolution; const float z=acos(-1.); mat2 s(float v){float f=sin(v), x=cos(v); return mat2(x,f ,-f,x);} vec4 f(vec3 v){vec4 f = fract(vec4(v.xyzx)* vec4(0.1031,0.103,0.0973,0.1099)); f+=dot(f, f.wzxy+ 33.33); return fract((f.xxyz + f.yzzw)*f.zywx);}vec3 f(vec3 v,float z){vec4 f=vec4(0); mat2 m=s(.5); for( int r=0;r<6;r++) v+=v,v.xy*=m, v.yz*=m,v+=sin(v.yzx) ,f=z*f+ vec4(cross(sin(v.zxy), cos(v)), 1.0); return f.xyz/f.w;}vec3 t(vec3 v){v/=length(v); float x=time ;if(x<5.)return 0.001*vec3(1.-smoothstep(0.,5.,x));x -=5.;if(x<39.){float y=sin(x*z/3.0);if(x>24.)v.x=abs (v.x);if(x>27.)v.y=abs(v.y);v.xz*=s(-.9*max(x-4.0,.0 ));v.xy*=s(0.5*max(x-5.,0.));float m=.4*step(x,12.); return vec3(step(.02+m,.5*y*y-2.0*abs(fract(time-.5* v.y-.5)-.5)));}x-=39.0;if(x<16.0){v.xy*=s(.3*x);v.xz *=s(2.0*x);vec3 y=.5+.5*cos(x-vec3(0,90,67));if(v.x< 0.)y=1.0-y;return y*step(0.6+exp(-3.0*x)+exp(3.0*(x- 15.5)),abs(v.x))*4.;}x-=16.;v.xy*=s(-.1*exp(1.3*(5.0 -x+.02*f(v).x))); v.z+=0.82; v=sign(v); return vec3( smoothstep(0.,1.,x))*step(v.x*v.y*v.z,0.0);}float v( vec3 v){vec3 x=abs(v);x.z=v.z;x.xz-=1.3;float m=2.0- max(max(x.x,x.y),x.z);return .65*(m+.4*f(v,3.2).x);} void main(){vec4 x = f(vec3(gl_FragCoord.xy, time)); vec3 y=normalize(vec3(2.0*gl_FragCoord.xy-resolution +x.xy-0.5,2.0*resolution.y)), r=vec3(0,0,-6);vec4 m= .16*(1.0-smoothstep(45.,70.,time))*cos(.02*vec2(5,7) .xxyy*(time+vec2(0, 1).xyxy))+vec2(0,0.03).xxyy;r.xz *=s(m.x);y.xz*=s(m.y);r.yz*=s(m.z);y.yz*=s(m.w);vec3 e; float a,i,c=3.0; for(int n=0;n<70;n++) e=r+y*c,i= length(e)-1.,c+=a=min(i,v(e));vec3 n=vec3(0);if(a==i ){vec3 G=c*fwidth(y); for(int u=0;u<32;u++) x=fract( sin(1e4*x)+x.wxyz),n+=t(e+G*x.xyz);n/=32.;}else{vec3 G=normalize(e);vec2 u=vec2(0,.01);vec3 d=normalize(a -vec3(v(e-u.yxx),v(e-u.xyx),v(e-u.xxy)));for(int g=0 ;g<64;g++){x=fract(sin(1e4*x)+x.wxyz);float w=2.0*z* x.x,o=2.*x.y-1.,l=sqrt(1.-o*o);vec3 p=vec3(l*cos(w), o, l*sin(w)); float h = dot(G,p); if(h<0.) p=-p; n+= smoothstep(.2,1.,abs(h))*t(p);}n*=dot(d,-G)/(dot(e,e )*64.); n*=mix(vec3(1,.6,.5), vec3(1), f(-e,1.3));}n =max(2.*n-smoothstep(64.0,69.0,time),0.0); n/=n+1.0; gl_FragColor=vec4(sqrt(1.5*n),1);}