uniform sampler2D tex0;
uniform float amount;
uniform float lineAmount;

uniform float 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 diAnim = mod(-time / 100000.0 * 15,1.0); 

  float diOffset = lineAmount;  
  float diRadius = 0.03;
  float diPosition = -diRadius + diAnim * (1.0 + diRadius * 2.0 + 0.4);
  
  float diStart = diPosition - diRadius;
  float diEnd = diPosition + diRadius;
  float diZo = (gl_TexCoord[0].t - diStart) / (diEnd - diStart);

 
  vec2 coord = gl_TexCoord[0].st;
  
  if (gl_TexCoord[0].t > diStart && gl_TexCoord[0].t < diEnd)
  {    
    coord = vec2(mod(gl_TexCoord[0].s + diOffset * 0.5 * (1 - cos(diZo * 2.0 * 3.141592654)),1.0), gl_TexCoord[0].t);
  }
  
  
	vec4 texel = texture2D(tex0, coord);
  
    
  float noise = (-1.0 + 2.0 * rand(gl_FragCoord.x * gl_FragCoord.y * 0.2 * uint(10000 * (1+time)))) * amount;
  texel += vec4(vec3(noise), 0.0);
  
  //texel = mix(texel, texel * 2.0 * rand(gl_FragCoord.x * gl_FragCoord.y + time), amount);
  
  float lines = 0.4 * amount;
  
  if (mod(gl_FragCoord.y, 8.0) < 4)
    texel += vec4(vec3(lines), 0.0);
  else
    texel -= vec4(vec3(lines), 0.0);

	gl_FragData[0] = texel;
}
