//uniform int poly_size;
//uniform float poly_x[128];
//uniform float poly_y[128];

uniform sampler2D u_texture;
uniform sampler2D mask_texture;

varying vec2 v_texCoord;
varying vec4 v_fragmentColor;

/*
bool pointInPolygon(vec2 point) {

  int i = 0;
  int j = 0;
  int nvert = poly_size;
  bool c = false;

  for(i = 0, j = nvert - 1; i < nvert; j = i++) {
    if( ( (poly_y[i]) >= point.y != (poly_y[j] >= point.y) ) &&
        (point.x <= (poly_x[j] - poly_x[i]) * (point.y - poly_y[i]) / (poly_y[j] - poly_y[i]) + poly_x[i])
      )
      c = !c;
  }

  return c;
}*/

void main()
{
  vec4 color = texture2D(mask_texture, v_texCoord);
  
  if(color.g > 0 || color.r > 0 || color.b > 0)
  {
    //if(pointInPolygon(v_texCoord) == false) color = vec4(0,0,0,0);
      gl_FragColor = texture2D(u_texture, v_texCoord);
  }
  else
  {
      gl_FragColor = vec4(0);
  }
	
}
