uniform sampler2D SampleTexColor;

void main(void)
{
  float
    rDist = length(gl_TexCoord[0].zw);

  float
    rDiffuse = 1.0,
    rSpecular = 0.0;

  vec2
    cUV = gl_TexCoord[0].xy;

  float
    rEdgeFac = max((rDist - gl_TexCoord[1].w) * (1.0 / (1.0 - gl_TexCoord[1].w)), 0.0);

  float
    t = pow(rEdgeFac, gl_TexCoord[1].z);
//  t = smoothstep(0.9, 1.0, rDist);

  // Interpolate towards "zoomed area"

  float
    f = 1.0 - 1.0 / gl_TexCoord[1].z;

  vec3 
    vNormal = normalize(vec3(dFdx(t) * f, dFdy(t) * f, 0.1));


  if (rDist < gl_TexCoord[1].w) discard;

  if (rDist < 1.0)
  {
  float
    rI = abs(0.5 - t) * 2.0;
    rI = dot(vNormal,vec3(0.5, 0.5, 1.0));
    if (rI < 1.0) rDiffuse = rI;
    else rSpecular = pow((rI - 1.0) * 4.0, 4.0);
    cUV = mix(gl_TexCoord[1].xy, cUV, t);
  }


  gl_FragColor = texture2D(SampleTexColor, cUV);
  gl_FragColor.rgb *=  vec3(rDiffuse);
  gl_FragColor.rgb +=  vec3(rSpecular);
  gl_FragColor.a = 1.0;
}

