#version 410

layout (location = 0) out vec4 FragColor;

in vec2 texturecoord;

uniform sampler2D color1;
uniform sampler2D color2;
uniform sampler2D depth;
uniform sampler2D logo;
uniform float time;

const float param[5] = float[5](0.16,0.15,0.12,0.09,0.05);

vec4 blur(sampler2D image, vec2 tc, int kernelSize){
   int i;
   vec4 sum = vec4(0.0);
   float texel = 1.0 / textureSize(image,0).y;
   for(i = kernelSize * -1; i < kernelSize; i++){
      vec2 coord = vec2(tc.x, tc.y - i * texel);
      sum += texture2D(image, coord) * param[abs(i)];
   }

   return(sum);
}

float vignette(sampler2D image, vec2 tc){
   float d = distance(tc, vec2(0.5,0.5));
   return(smoothstep(0.7,0.0,d*0.5));
}

vec4 pixelize(sampler2D image, vec2 tc, int squaresize){
   vec4 color = vec4(0.0);
   ivec2 square = ivec2(tc * squaresize);
   vec2 beosztas = vec2(1.0) / squaresize;

   return color;
}

void main(void){
   vec4 pic;
   float blend = 1.0;

   if(time > 20.0 && time < 30.0){
      pic = texture2D(logo, texturecoord);
      blend = max(cos((time - 20.0) / (3.183 / 2.0)),0.0);
   }
   else if(time > 72.051 && time < 113.186){
      pic = texture2D(logo, texturecoord);
      blend = 1.0 - pic.a;
   }
   else if(time > 174.0){
      pic = texture2D(logo, texturecoord);
      blend = 0.0;
   }
   else{
      pic = vec4(0.0, 0.0, 0.0, 1.0);
   }
//FragColor = pixelize(color1, texturecoord, 250);
   FragColor = mix(pic, blur(color1, texturecoord, 3), blend) * vignette(color1, texturecoord);
}
