#define PERIOD 2.
#define REPETITIONS 2
const float PI = 3.1415926535;
float box(in vec2 _st, in vec2 _size){
_size = vec2(0.5) - _size*0.5;
vec2 uv = smoothstep(_size,
_size+vec2(0.001),
_st);
uv *= smoothstep(_size,
_size+vec2(0.001),
vec2(1.0)-_st);
return uv.x*uv.y;
}
float cross2(in vec2 _st, float _size){
return box(_st, vec2(_size,_size/4.)) +
box(_st, vec2(_size/4.,_size));
}
vec3 shadeBlob(vec2 p, float index, float value, float scale)
{
float screenRatio = iResolution.x / iResolution.y;
vec2 pc = vec2(0.1 + (screenRatio - 0.2) * value, index);
float d = length(pc - p) / 0.015*scale/(1.37+abs(sin(iTime)));
return vec3(3. * vec3(0.5, 0.5, 0.7) / (max(d * d, 1.)));
}
float step_interp(float x) {
return step(0.5, x);
}
float linear_interp(float x) {
float c = clamp(x, 0., 1.);
return c;
}
float cosine_interp(float x) {
float c = clamp(x, 0., 1.);
return 0.5 * (1. - cos(PI * c));
}
float smoothstep_interp(float x) {
// return smoothstep(0., 1., x);
float c = clamp(x, 0., 1.);
return c * c * (3. - 2. * c);
}
float quintic_interp(float x) {
float c = clamp(x, 0., 1.);
return c * c * c * ((6. * c - 15.) * c + 10.);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 p = fragCoord.xy / iResolution.yy;
vec2 q = fragCoord.xy / iResolution.xy;
int tx = int(p.x*128.0);
int ty = int(p.y*128.0);
// per lo Spectrum Audio
float wave = texelFetch( iChannel0, ivec2(ty,1), 0 ).x;
vec3 spec = vec3(wave/0.5);
// per lo Spectrum Audio
//vec4 spec = vec4(0.1,0.1,0.1,0.1);
vec2 translate = vec2(cos(iTime),sin(iTime));
vec2 translate2 = vec2(sin(iTime),cos(iTime));
//p += translate*0.35*sin(iTime);
q += translate2*1.35*sin(iTime);
float t = abs(2. * fract(iTime / PERIOD) - 1.);
// Background pattern
vec3 col = vec3(0.0);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1, spec.x/0.4);
col += shadeBlob(p, 0.4, linear_interp(t)*0.1, spec.x/0.4);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1, spec.x/0.4 );
col += shadeBlob(p, 0.6, smoothstep_interp(t)*0.1, spec.x/0.4);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1, spec.x/0.4);
//col += shadeBlob(p, 0.3, smoothstep_interp(t)*spec.x+0.2, 0.1/0.1);
col += shadeBlob(p, 0.4, linear_interp(t)*0.1+0.05, spec.x/0.4);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.05, spec.x/0.4);
//col += shadeBlob(p, 0.6, smoothstep_interp(t)*spec.z+0.2, 0.1/0.1);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.05, spec.x/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.1, spec.x/0.4);
//col += shadeBlob(p, 0.4, linear_interp(t)*spec.y+0.1, 0.1/0.1);
//col += shadeBlob(p, 0.5, cosine_interp(t)*spec.z+0.1, 0.1/0.1);
col += shadeBlob(p, 0.6, smoothstep_interp(t)*0.1+0.1, spec.x/0.4);
//col += shadeBlob(p, 0.7, quintic_interp(t)*spec.z+0.1, 0.1/0.1);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.2, spec.y/0.4);
col += shadeBlob(p, 0.4, linear_interp(t)*0.1+0.2, spec.y/0.4);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.2, spec.y/0.4);
col += shadeBlob(p, 0.6, smoothstep_interp(t)*0.1+0.2, spec.y/0.4);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.2, spec.y/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.25, spec.x/0.4);
//col += shadeBlob(p, 0.4, linear_interp(t)*spec.y+0.25, 0.1/0.1);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.25, spec.x/0.4);
//col += shadeBlob(p, 0.6, smoothstep_interp(t)*spec.z+0.25, 0.1/0.1);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.25, spec.x/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.3, spec.x/0.4);
//col += shadeBlob(p, 0.4, linear_interp(t)*spec.y+0.25, 0.1/0.1);
//col += shadeBlob(p, 0.5, cosine_interp(t)*spec.z+0.25, 0.1/0.1);
//col += shadeBlob(p, 0.6, smoothstep_interp(t)*spec.z+0.25, 0.1/0.1);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.3, spec.x/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.4, spec.x/0.4);
col += shadeBlob(p, 0.4, linear_interp(t)*0.1+0.4, spec.x/0.4);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.4, spec.x/0.4);
col += shadeBlob(p, 0.6, smoothstep_interp(t)*0.1+0.4, spec.x/0.4);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.4, spec.x/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.45, spec.x/0.4);
//col += shadeBlob(p, 0.4, linear_interp(t)*spec.y+0.45, 0.1/0.1);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.45, spec.x/0.4);
//col += shadeBlob(p, 0.6, smoothstep_interp(t)*spec.z+0.45, 0.1/0.1);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.45, spec.x/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.5, spec.x/0.4);
col += shadeBlob(p, 0.4, linear_interp(t)*0.1+0.5, spec.x/0.4);
//col += shadeBlob(p, 0.5, cosine_interp(t)*spec.z+0.5, 0.1/0.1);
col += shadeBlob(p, 0.6, smoothstep_interp(t)*0.1+0.5, spec.x/0.4);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.5, spec.x/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.6, spec.x/0.4);
col += shadeBlob(p, 0.4, linear_interp(t)*0.1+0.6, spec.x/0.4);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.6, spec.x/0.4);
col += shadeBlob(p, 0.6, smoothstep_interp(t)*0.1+0.6, spec.x/0.4);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.6, spec.x/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.65, spec.x/0.4);
//col += shadeBlob(p, 0.4, linear_interp(t)*spec.y+0.65, 0.1/0.1);
//col += shadeBlob(p, 0.5, cosine_interp(t)*spec.z+0.65, 0.1/0.1);
//col += shadeBlob(p, 0.6, smoothstep_interp(t)*spec.z+0.65, 0.1/0.1);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.65, spec.x/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.7, spec.x/0.4);
col += shadeBlob(p, 0.4, linear_interp(t)*0.1+0.7, spec.x/0.4);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.7, spec.x/0.4);
col += shadeBlob(p, 0.6, smoothstep_interp(t)*0.1+0.7, spec.x/0.4);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.7, spec.x/0.4);
col += shadeBlob(p, 0.3, smoothstep_interp(t)*0.1+0.8, spec.x/0.4);
col += shadeBlob(p, 0.4, linear_interp(t)*0.1+0.8, spec.x/0.4);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.8, spec.x/0.4);
col += shadeBlob(p, 0.6, smoothstep_interp(t)*0.1+0.8, spec.x/0.4);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.8, spec.x/0.4);
//col += shadeBlob(p, 0.3, smoothstep_interp(t)*spec.x+0.8, 0.1/0.1);
//col += shadeBlob(p, 0.4, linear_interp(t)*spec.y+0.8, 0.1/0.1);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.85, spec.x/0.4);
//col += shadeBlob(p, 0.6, smoothstep_interp(t)*spec.z+0.8, 0.1/0.1);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.85, spec.x/0.4);
//col += shadeBlob(p, 0.3, smoothstep_interp(t)*spec.x+0.8, 0.1/0.1);
//col += shadeBlob(p, 0.4, linear_interp(t)*spec.y+0.8, 0.1/0.1);
col += shadeBlob(p, 0.5, cosine_interp(t)*0.1+0.9, spec.x/0.4);
col += shadeBlob(p, 0.6, smoothstep_interp(t)*0.1+0.9, spec.x/0.4);
col += shadeBlob(p, 0.7, quintic_interp(t)*0.1+0.9, spec.x/0.4);
col += 1.0 - smoothstep( 0.0, 0.15, abs(wave - q.x) );
//col = pow(col, vec3(1.3));
//col2 = pow(col2, vec3(0.45));
fragColor = vec4(col, 1.0);
}