#version 430 core

uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)

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 sampler2D texBricks;
uniform sampler2D texGrunge;
uniform sampler2D texMono;
uniform sampler2D texNoise;
uniform sampler2D texNormal;
uniform sampler2D texPaper;
uniform sampler2D texPooBrain;

layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything

vec4 plas( vec2 v, float time )
{
  float c = 0.5 + sin( v.x * 10.0 ) + cos( sin( time + v.y ) * 20.0 );
  return vec4( sin(c * 0.2 + cos(time)), c * 0.15, cos( c * 0.1 + time / .4 ) * .25, 1.0 );
}

float l(vec4 x) {
  return x.y*x.y+x.x*x.x;
}

void main(void)
{
 // float d = m.y;
//  float f = texture( texFFT,  ).r * 100;
  float t = fGlobalTime;

  vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y);
  uv -= 0.5;
  uv /= vec2(v2Resolution.y / v2Resolution.x, 1);
  float g = texture( texFFT, 0.6 ).r * 100;
  float h = texture( texGrunge, uv);

  float s = texture( texFFTSmoothed, 0.00 ).r * 100;


  vec2 p1 = s*vec2(sin(t), cos(t));
  vec2 p2 = s*vec2(sin(t+cos(t)), cos(t));
  vec2 p3 = s*vec2(sin(t+sin(t)), cos(t+cos(t)));

  vec4 b1 = vec4(uv+p1,0,0);
  vec4 b2 = vec4(uv+p2,0,0);
  vec4 b3 = vec4(uv+p3,0,0);

  float v = 1-10/l(b1) * l(b2) * l(b3);
  vec4 r = vec4(v,v,v,0);


  float tp = texture( texPaper, p1 ).r * 100;

  vec2 m;
  m.x = atan(uv.x / uv.y) / 3.14;
  m.y = 1 / length(uv) * .2;
  float d = m.y;

  float f = texture( texFFT, d ).r * 100;
  m.x += sin( fGlobalTime ) * 0.1;
  m.y += fGlobalTime * 0.25;

  vec4 t2 = plas( m * 3.14, fGlobalTime ) / d;
  t2 = clamp( t2, 0.0, 1.0 );

  out_color = vec4(v)* h;
}