uniform sampler2D Color0;
uniform float ScreenWidth;
uniform float ScreenHeight;

float offsetx = 1.0 / ScreenWidth;
float offsety = 1.0 / ScreenHeight;

void main()
{
  vec3 c00 = texture2D( Color0, gl_TexCoord[1].st ).rgb;
  vec3 c01 = texture2D( Color0, gl_TexCoord[2].st ).rgb;
  vec3 c02 = texture2D( Color0, gl_TexCoord[3].st ).rgb;
  vec3 c10 = texture2D( Color0, gl_TexCoord[4].st ).rgb;
  vec3 c12 = texture2D( Color0, gl_TexCoord[5].st ).rgb;
  vec3 c20 = texture2D( Color0, gl_TexCoord[6].st ).rgb;
  vec3 c21 = texture2D( Color0, gl_TexCoord[7].st ).rgb;
  vec3 c22 = texture2D( Color0, gl_TexCoord[0].st + vec2( offsetx, offsety ) ).rgb;

  // do scaling here to cut down on ops
  c12 = 2.0 * ( c12 - c10 );
  c21 = 2.0 * ( c21 - c01 );
  vec3 sx = c02 + c12 + c22 - c00 - c20;
  vec3 sy = c20 + c21 + c22 - c00 - c02;

  // convert to grey scale
  vec3 se = abs(sx) + abs(sy);
  float sef = dot(se, vec3(0.299, 0.587, 0.114));//, 0.vec3(0.212671, 0.715160, 0.072169) ); 
  vec3 color = texture2D( Color0, gl_TexCoord[0].st ).rgb;
  // scale
  float scale = 0.25;
  color += sef * scale;

  gl_FragColor = vec4( color, sef );
}
