#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect tex0;

uniform vec2 offset0;
uniform vec2 offset1;

uniform vec3 color0;
uniform vec3 color1;
uniform float time;


void main() {
  vec2 sp = gl_TexCoord[0].xy;
  vec2 sp0 = sp + offset0;
  sp0.x += cos(time+sp.y*0.132)*3.0;
  vec2 sp1 = sp + offset1;
  sp1.x += cos(time+sp.y*0.098)*3.0;
  //  sp1.x += cos(time*354.0+sp.y*3870412.12)*120.0*cos(time)*0.5+0.5;;
  

  vec3 c0 = texture2DRect( tex0, sp0 ).rgb;
  vec3 c1 = texture2DRect( tex0, sp1 ).rgb;
  vec3 c = texture2DRect( tex0, sp ).rgb;
  float a = texture2DRect( tex0, sp ).a;


  vec4 glow = vec4(0,0,0,0);
  for (int i = -4; i < 5; ++i) 
    for (int j = -4; j < 5; ++j)  {
      
      glow += texture2DRect( tex0, sp + vec2(i*3,j*3) );


    }
      
  glow/= 8*8;
  

  float a0 = texture2DRect( tex0, sp0 ).a;
  float a1 = texture2DRect( tex0, sp1 ).a;

  float l0 = length(c0);
  float l1 = length(c1);

  float d0 = (cos(0.42*sp.y+time)*0.3+0.7)*.5;
  float d1 = (cos(0.54*sp.y+time)*0.3+0.7)*.5;

  gl_FragColor.rgb = ((a*c) + (d0*l0 * color0) + (d1*l1 * color1));
  gl_FragColor.a = (a + a0 + a1)/3.0;

  gl_FragColor+=glow*1.0;
}



