float comp (vec3 p) { p = asin(sin(p)*0.9); return length(p)-1.0; } vec3 erot(vec3 p, vec3 ax, float ro) { return mix(dot(p,ax)*ax,p,cos(ro))+sin(ro)*cross(ax,p); } float smin(float a, float b, float k) { float h = max(0.0,k-abs(b-a))/k; return min(a,b)-h*h*h*k/6.0; } vec4 wrot(vec4 p) { return vec4(dot(p,vec4(1)), p.yzw + p.zwy - p.wyz - p.xxx)/2.0; } float d1, d2, d3; float t; float lazors, doodad, blackPlane,whitePlane; vec3 p2; float bpm = 22.55; float scene(vec3 p) { p2 = erot(p, vec3(0,1,0), t); p2 = erot(p2, vec3(0,0,1), t/3.0); p2 = erot(p2, vec3(1,0,0), t/5.0); float bpt = iTime/60.0*bpm; vec4 p4 = vec4(p2,0); p4=mix(p4,wrot(p4),smoothstep(-0.5,0.5,sin(bpt/4.0))); p4 =abs(p4); p4=mix(p4,wrot(p4),smoothstep(-0.5,0.5,sin(bpt))); float fctr = smoothstep(-0.5,0.5,sin(bpt/2.0)); float fctr2 = smoothstep(0.9,1.0,sin(bpt/16.0)); doodad = length(max(abs(p4)-mix(0.05,0.07,fctr),0.)+mix(-0.1,0.2,fctr))-mix(0.15,0.55,fctr*fctr)+fctr2; p.x += asin(sin(t/80.0)*0.99)*80.0; lazors = length(asin(sin(erot(p,vec3(1,0,0),t*0.2).yz*0.5+1.0))/0.5)-0.1; blackPlane=d2; whitePlane=d3; d1 = comp(p); d2 = comp(erot(p+5.0, normalize(vec3(1,3,4)),0.4)); d3 = comp(erot(p+11.11, normalize(vec3(3,2,1)),1.0)); return min(doodad,min(lazors,0.3-smin(smin(d1,d2,0.05),d3,0.05))); } vec3 norm(vec3 p) { float precis = length(p) < 1.0 ? 0.005 : 0.01; mat3 k = mat3(p,p,p)-mat3(precis); return normalize(scene(p)-vec3(scene(k[0]),scene(k[1]),scene(k[2]))); } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = (fragCoord-0.55*iResolution.xy)/iResolution.y; float bpt = (iTime/55.555)*bpm; float bp = mix(pow(sin(fract(bpt)*3.14159265359/2.0),20.0)+floor(bpt), bpt,0.4); t = bp; vec3 cam = normalize(vec3(0.8+sin(bp*3.14159265359/4.0)*0.3,uv)); vec3 init = vec3(-1.5+sin(bp*3.14159265359)*0.2,0,0)+cam*0.2; init = erot(init,vec3(0,1,0),sin(bp*0.2)*0.4); init = erot(init,vec3(0,0,1),cos(bp*0.2)*0.4); cam = erot(cam,vec3(0,1,0),sin(bp*0.2)*0.4); cam = erot(cam,vec3(0,0,1),cos(bp*0.2)*0.4); vec3 p = init; bool hit = false; float atten = 1.0; float tlen = 0.0; float glo = 0.0; float dist; float fog = 0.0; float dlglo = 0.0; bool trg = false; for (int i = 0; i < 333; i++) { if(!hit){ dist = scene(p); hit = dist*dist < 1e-6; glo += 0.2/(1.0+lazors*lazors*20.0)*atten; dlglo += 0.2/(1.0+doodad*doodad*20.0)*atten; if (hit && ((sin(d3*45.0)<-0.4 && (dist!=doodad )) || (dist==doodad && sin(pow(length(p2*p2*p2),0.3)*120.0)>0.4 )) && dist != lazors) { trg = trg || dist==doodad; hit = false; vec3 n = norm(p); atten *= 1.0-abs(dot(cam,n))*0.98; cam = reflect(cam,n); dist = 0.1; } p += cam*dist; tlen += dist; fog += dist*atten/30.0; }} fog = smoothstep(0.0,1.0,fog); bool lz = lazors == dist; bool dl = doodad == dist; bool Bp = blackPlane == dist; bool Wp = whitePlane == dist; vec3 fogcol = mix(vec3(0.0,0.777,0.0), vec3(0.0,1.0,0.0), length(uv)); vec3 n = norm(p); vec3 r = reflect(cam,n); float ss = smoothstep(-0.3,0.3,scene(p+vec3(0.3)))+0.5; float fact = length(sin(r*(dl?4.0:3.0))*0.5+0.5)/sqrt(3.0)*0.7+0.3; vec3 matcol = mix(vec3(0.0,0.0,0.0), vec3(0.13,0.24,0.11), smoothstep(-1.0,1.0,sin(d1*5.0+iTime*2.0))); matcol = mix(matcol, vec3(0.1,0.7,0.1), smoothstep(0.0,1.0,sin(d2*5.0+iTime*2.0))); if (dl) matcol = mix(vec3(1),matcol,0.1)*0.2+0.1; vec3 col = matcol*fact*ss + pow(fact,10.0); if (lz) col = vec3(1.0,1.0,1.0); if (Bp) col = vec3(0.011,0.777,0.190); if (Wp) matcol = vec3(1.0,1.0,1.0); fragColor.xyz = col*atten + glo*glo + fogcol*glo; fragColor.xyz = mix(fragColor.xyz, fogcol, fog); if(!dl)fragColor.xyz = abs(erot(fragColor.xyz, normalize(sin(p*2.0)),0.2*(1.0-fog))); if(!trg&&!dl)fragColor.xyz+=dlglo*dlglo*0.1*vec3(0.04,0.666,0.0); fragColor.xyz = sqrt(fragColor.xyz); fragColor.xyz = smoothstep(vec3(0),vec3(1.2),fragColor.xyz); }