#version 300 es
precision highp float;
uniform vec2 r;uniform float t;uniform int n;uniform vec2 p;out vec4 o;
float H(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453123);}
float S(vec2 u){vec2 g=floor(u*11.),f=fract(u*11.);float z=0.;for(int y=-1;y<2;y++)for(int x=-1;x<2;x++){vec2 q=vec2(x,y),id=g+q;vec2 a=vec2(H(id),H(id+19.));float d=length(q+a-f);z+=smoothstep(.055,.0,d)*mix(.2,1.,H(id+7.));}return z;}
vec3 P(float x){return .45+.45*cos(vec3(.3,1.2,2.1)+x+vec3(0.,2.,4.));}
void main(){
 vec2 u=(2.*gl_FragCoord.xy-r)/r.y;u*=.68;u.y+=.04;float d=length(u),a=atan(u.y,u.x),time=t*.34;
 vec3 col=vec3(.003,.006,.018);col+=S(u+vec2(time*.03,0.))*vec3(.18,.35,.8);
 float haze=exp(-2.2*abs(u.y+.18*sin(u.x*1.7)))*(.25+.25*sin(u.x*4.-time));col+=haze*vec3(.015,.025,.09);
 vec2 e=vec2(u.x,u.y*.63);float ed=length(e),ea=atan(e.y,e.x);
 for(int i=0;i<5;i++){float k=float(i);float rr=.30+k*.115+.012*sin(time*(1.+k*.11));float wave=.5+.5*sin(ea*(5.+k)+log(ed+.03)*18.-time*(3.+k));float ring=exp(-100.*abs(ed-rr));col+=ring*wave*P(k*.8-time)*(.42+.18*k);}
 float spiral=exp(-13.*abs(ed-.38))*smoothstep(.12,.72,ed)*( .35+.65*sin(28.*log(ed+.02)+7.*ea-time*8.));col+=spiral*vec3(.95,.08,.32);
 float glow=exp(-7.*ed)*(.45+.55*sin(ea*3.-time*4.));col+=glow*vec3(.12,.02,.35);
 float core=smoothstep(.265,.245,d);col*=core;col+= (1.-core)*vec3(.001,.002,.008);
 float rim=exp(-150.*abs(d-.255));col+=rim*vec3(.8,.18,1.2)*( .45+.55*sin(a*2.-time));
 col+=.015*P(d*8.+time)*smoothstep(1.4,.2,d);col=pow(col,vec3(.4545));o=vec4(col,1.);
}
