uniform sampler2D tex0;
//uniform float amount, inner, outer;
uniform int time;

uint wang_hash(uint seed)
{
    seed = (seed ^ 61) ^ (seed >> 16);
    seed *= 9;
    seed = seed ^ (seed >> 4);
    seed *= 0x27d4eb2d;
    seed = seed ^ (seed >> 15);
    return seed;
}

float rand(uint value)
{
	return float(wang_hash(value)) * (1.0 / 4294967296.0);
}

void main(void)
{
	float amount, inner, outer, exponent;

	amount = 0.7 - 0.7;
	inner = 0.7;
	outer = 2.0;
	exponent = 2.0;

	vec4 color = texture2D(tex0, gl_TexCoord[0].st);

	float distance = length(gl_TexCoord[0].st - vec2(0.5, 0.5)) * 2.0;
	float vig = smoothstep(outer, inner, distance);

	//vec3 vigColor = vec3(0.02, 0.03, 0.12);
	vec3 vigColor = vec3(0.0, 0.01, 0.07);
//	vigColor = vec3(0);



  vec4 sample;
  vec4 accum = 0.0;
  float sum = 0.0;
  
  vec2 offset = vec2(0,0);
  
  for (uint i = 0; i < 100; i++)
  {
    offset = (-1.0 + 2.0 * vec2(rand(81*i+0), rand(81*i+13))) * 0.04 * (1.0 - vig) * 0.0;
    sample = texture2D(tex0, gl_TexCoord[0].st + offset);
    accum += sample;
    sum++;  
  }
  accum /= sum;


	gl_FragData[0] = vec4(mix(accum, vigColor, pow(1.0 - vig, exponent) * amount), color.a);
  //gl_FragData[0] = texture2D(tex0, gl_TexCoord[0].st);
}
