#version 410 core uniform float fGlobalTime; // in seconds uniform vec2 v2Resolution; // viewport resolution (in pixels) uniform float fFrameTime; // duration of the last frame, in seconds uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients uniform sampler1D texFFTIntegrated; // this is continually increasing uniform sampler2D texPreviousFrame; // screenshot of the previous frame uniform sampler2D texChecker; uniform sampler2D texNoise; uniform sampler2D texTex1; uniform sampler2D texTex2; uniform sampler2D texTex3; uniform sampler2D texTex4; layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything const float E = 0.001; const float FAR = 100.0; const int STEPS = 128; float time = pow(texture(texFFTIntegrated,0.05).r*.01,1)+fGlobalTime*.003; float fft = texture(texFFTIntegrated, 0.01).r*.01; float fft2 = texture(texFFTSmoothed,0.15).r; vec3 glow = vec3(0); float sphere(vec3 p, float r){ return length(p)-r; } float box(vec3 p, vec3 b){ vec3 d = abs(p)-b; return length(max(d, 0.0))+min(max(d.x, max(d.y, d.z)), 0.0); } float torus(vec3 p, vec2 t){ vec2 q= vec2(length(p.xz)-t.x,p.y); return length(q)-t.y; } void rot(inout vec2 p, float a){ p = cos(a)*p + sin(a)*vec2(-p.y, p.x); } float scene(vec3 p, vec3 ro, vec3 rd){ vec3 pp = p; float fpp= texture(texFFTSmoothed,(pow(dot(p,ro)*.001,2.5))).r*100; float keski = sphere(pp,2*(.5+fpp*1)); float pallo = box((pp-ro)*rd,vec3(1)); rot(pp.xy, time*0.1); for(int i = 0; i < (floor(abs(p.x*.2)+1.5)); ++i){ pp = abs(pp)-vec3(1.8); pp = abs(pp)-vec3(10,10,0)*.2; rot(pp.yz, time*1); pp = abs(pp)-vec3(0.1*i, 0.3, 0.1*i); } float d = distance(p,pp); //distance(p, pp); float sp = box(pp, vec3(d*0.05, d*0.04, d*0.02)*(vec3(1+fft2*0))); vec3 g = vec3(.2)*0.01 / (abs(sp)+0.05); glow += g; glow *= d*.05; sp = abs(sp*0.5); return max(sp,-pallo);//max(min(sp,keski),-pallo); } float scene2(vec3 p, vec3 ro, vec3 rd){ vec3 pp = p; for(int i = 0; i < 20; ++i) { pp = abs(pp)-vec3(2); } float d = distance(p,pp); //distance(p, pp); float sp = box(pp,vec3(0.5)); vec3 g = vec3(.2)*0.01 / (abs(sp)+0.05); glow += g; glow *= d*.03; return sp; } float scene3(vec3 p, vec3 ro, vec3 rd){ vec3 pp = p; //float d = distance(p,pp); for(int i = 0; i < 20; ++i) { //pp = abs(pp)-vec3(0,0,8); } pp+=vec3(0,-10,0); rot(pp.xy,sin(fft2*10)); pp+=vec3(0,10,0); float sp = torus(pp,vec2(5,2)); return sp; } float march(vec3 ro, vec3 rd){ float t = E; vec3 p = ro; for(int i = 0; i < STEPS; ++i){ float d = scene2(p,ro,rd); t += d; p = ro + rd * t; if(d <= E || t >= FAR){ break; } } return t; } vec3 hsl2rgb( in vec3 c ) { vec3 rgb = clamp( abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, 1.0 ); return c.z + c.y * (rgb-0.5)*(1.0-abs(2.0*c.z-1.0)); } vec3 HueShift (in vec3 Color, in float Shift) { vec3 P = vec3(0.55735)*dot(vec3(0.55735),Color); vec3 U = Color-P; vec3 V = cross(vec3(0.55735),U); Color = U*cos(Shift*6.2832) + V*sin(Shift*6.2832) + P; return vec3(Color); } vec3 rgb2hsl( in vec3 c ){ float h = 0.0; float s = 0.0; float l = 0.0; float r = c.r; float g = c.g; float b = c.b; float cMin = min( r, min( g, b ) ); float cMax = max( r, max( g, b ) ); l = ( cMax + cMin ) / 2.0; if ( cMax > cMin ) { float cDelta = cMax - cMin; //s = l < .05 ? cDelta / ( cMax + cMin ) : cDelta / ( 2.0 - ( cMax + cMin ) ); Original s = l < .0 ? cDelta / ( cMax + cMin ) : cDelta / ( 2.0 - ( cMax + cMin ) ); if ( r == cMax ) { h = ( g - b ) / cDelta; } else if ( g == cMax ) { h = 2.0 + ( b - r ) / cDelta; } else { h = 4.0 + ( r - g ) / cDelta; } if ( h < 0.0) { h += 6.0; } h = h / 6.0; } return vec3( h, s, l ); } float sdPen( in vec2 p, in float r) { const vec3 k = vec3(0.809016994,0.587785252,0.726542528); p.x = abs(p.x); p -= 2*min(dot(vec2(-k.x,k.y),p),0)*vec2(-k.x,k.y); p -= 2*min(dot(vec2( k.x,k.y),p),0)*vec2( k.x,k.y); p -= vec2(clamp(p.x,-r*k.z,r*k.z),r); return length(p)*sign(p.y); } void main(void) { vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y); vec2 zom = uv; vec2 kzom = uv; vec2 uv_=uv; uv_-=0.5; uv_*=vec2(1,.6)*vec2(2); float fw = (1/(texture(texFFTSmoothed, (cos(abs(uv.x-.5)+.025)+cos(abs(uv.y-.5)+.025))).r*3000))*.01; uv -= 0.5; uv /= vec2(v2Resolution.y / v2Resolution.x, 1); uv += 0.5; //uv-=vec2(0.5); //uv=abs(uv)+vec2(sin(time*10)); uv=round(uv/(fw*.2))*(fw*.2); glow=vec3(0); vec2 q = uv -0.5; //q /= vec2(v2Resolution.y / v2Resolution.x, 1); vec3 ro = vec3(10,0,10);// vec3(4+sin(time*.7*cos(time*.1))*15, 0, cos(time*.7*sin(time*.01))*20); rot(ro.xz,sin(time*.2)*10); rot(ro.yz,cos(time*.2)*10); vec3 rt = vec3(0, 0, 0); vec3 z = normalize(rt-ro); vec3 x = normalize(cross(z, vec3(0, 1, 0))); vec3 y = normalize(cross(x, z)); vec3 rd = normalize(mat3(x,y,z) * vec3(q, 1/radians(90.0))); float t = march(ro, rd); vec3 p = ro+rd*t; float dis = distance(ro,p); vec2 ffuv = uv.xy*1-vec2(.5); ffuv *= vec2(.5); ffuv.y=log(1+pow(abs(ffuv.y+.002),2)); float fy = texture(texFFT, ffuv.y).r*2; float fx = texture(texFFT, pow(abs(p.x*.4),3)*.2).r*20; float fz = texture(texFFTSmoothed, 0.02).r*-10; float fuv = texture(texFFT, pow(uv.y,1.5)).r*(10+pow(uv.y,1.5)); zom-=vec2(.5); zom*=vec2(0.998)-pow(fz,2)*0.008; rot(zom.xy,fz*.0001-fy*.0001); zom+=vec2(.5); kzom-=vec2(.75); kzom*=vec2(1-fz*8); kzom+=vec2(.75); vec3 prev = texture(texPreviousFrame, zom).rgb*.99; vec3 col = vec3(0.,0.,0.0); if(t < FAR){ col = vec3(0.2);//vec3(length(p))*.1; } glow*=vec3(.2,.5,.9);//vec3(abs(ro.x*2+.5*sign(ro.y*.4+5)),0.8, (ro.y*4+2)+0.6); col += dis*0.02; col += glow*.8*(.4+(fy*fx)*4); //col*=vec3(.2,.2,.5); vec3 hs = vec3(0); /* vec3 hs = rgb2hsl(col); hs.x+=0.1;//time*.03*(p.x*.001)+dis*.8; //hs.z-=.001; //hs.z=clamp(hs.z,0,1); col = hsl2rgb(hs); */ col-=glow*100; hs = rgb2hsl(prev); hs.x+=time*.002; hs.y+=0.08; hs.z-=0.01; prev = hsl2rgb(hs); float pen = sdPen(uv_*vec2(-1),.4-fx*.2+fx*10); //col = abs(vec3(p.x*0.002)); col = smoothstep(-0.1, 1.2, col); col=vec3(prev)*.8+vec3(col)*.9; col+=vec3(FAR-dis*5); if(col.x<.02 && col.y<.02 && col.z<.02){ col=prev*vec3(1.8,.2,.8);//*vec3(2,1.8,1.2); } if(col.x>.9 && col.y>.9 && col.z>.9){ col*=vec3(.01,.5,8); } col=clamp(col,0.0,1.0); col=HueShift(col,.5+floor(time*50)*.8); col*=1.5-smoothstep(0.0,pen,1.0); col+=smoothstep(0.0,1/pen,1.0)*pen; //col=vec3(uv,0); vec3 inter = vec3(pow(texture(texFFTSmoothed,length(p)*.2).x*4,1.8)); if(length(p)>=FAR) { inter = vec3(1); } out_color =vec4(col,1); // out_color =vec4(length(p)/FAR); out_color =vec4(inter,1); }