
#ifdef GL_ES
precision mediump float;
#extension GL_OES_standard_derivatives : enable
#endif

uniform vec4 color;
varying vec2 t; // texture coordinate

void main(void)
{
  float a,l,r,Ex;
  float ay, ly, ry, Ey;
  
  // E = fwidth(d);
  float d = t.x;
  
  Ex = length(vec2(dFdx(t.x), dFdy(t.x)));
  Ey = length(vec2(dFdx(t.y), dFdy(t.y)));
  
  l = -1.0; r = -1.0+2.0*Ex;
  a = smoothstep(l, r, d) * smoothstep(l, r, -d);
  
  // smoothstep can't handle ly == ry (divide by zero)
  if(Ey > 0.0) {
    ly = -1.0; ry = -1.0 + 2.0*Ey;
    ay = smoothstep(ly, ry, t.y) * smoothstep(ly, ry, -t.y);
  } else
    ay = 1.0;
  
  gl_FragColor = vec4(color.rgb, a * ay * color.a);

}