#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 texHello;
uniform sampler2D texMono;
uniform sampler2D texNoise;
uniform sampler2D texNormal;
uniform sampler2D texPaper;

layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything

vec2 rotate(vec2 x, float an)
{
  float c = cos(an);
  float s = sin(an);
  return vec2(x.x * c - x.y * s, x.y * c + x.x * s);
}

void main(void)
{
  vec2 uv = gl_FragCoord.xy / v2Resolution.xy; // that bugged me :P

  vec2 q = rotate((gl_FragCoord.xy - v2Resolution / 2.0) / v2Resolution.y, sin(fGlobalTime * .01) * 20.0 + fGlobalTime * .2)
    + vec2(sin(fGlobalTime * .3), cos(fGlobalTime * .21)) * .7
    + sin(gl_FragCoord.xy * .01 + fGlobalTime * .12)
    + vec2(sin(uv.x + fGlobalTime * .1), sin(uv.y * fGlobalTime * .12)) * 1.1
    + vec2(texture(texFFTSmoothed, .2).x, texture(texFFT, .7).x)
    ;

  vec3 baseColor = texture(texNormal, q).xyz;

  float f = sin(baseColor.x * 2.0 * 3.141592 + fGlobalTime) * .3 + .7;
  out_color = vec4(pow(mix(vec3(texture(texFFTSmoothed, .2).x),
mix(vec3(.8, .9, 1.0), vec3(1.0, .8, .9) * 1.3, texture(texHello, rotate(vec2(uv.x, 1.0 - uv.y), fGlobalTime * .01)).x), f), vec3(5.0)), 1.0);

  out_color -= 1.0 - pow(texture(texGrunge, uv).x, 2.2) * 2.8;

  out_color = vec4(pow(out_color.xyz * 1.1, vec3(3.0)) * (sin(length(uv) * 18.0 + fGlobalTime * 18.0) * .5 + .5)
 * texture(texFFT, .9).x * 200.0, 1.0);

  out_color = clamp(out_color, 0.0, 1.0);
}