#ifdef GL_ES
precision mediump float;
#else
#define highp
#define mediump
#define lowp
#endif

// ------- UNIFORMS (SHADER CONSTS) -------
uniform sampler2D	u_sTexture0;
uniform sampler2D	u_sTexture1; // mask
uniform vec2		hu_vDimsTexture0;
//uniform vec2		u_vStep;

// ------- INTERPOLATORS (SHADER INPUTS) -------
varying vec2		v_vTex0UV;

// ------- FUNCTIONS ------- 

void main(void)
{
	vec4 mask, result, sample, sample0, sample1, sample2, sample3;
	
	float stepx = 3.0/hu_vDimsTexture0.x;
	float stepy = 3.0/hu_vDimsTexture0.y;

	sample = texture2D(u_sTexture1, v_vTex0UV);
	if (sample.x > 0.0)
	{
		sample0 = texture2D(u_sTexture1, vec2(v_vTex0UV.x - stepx, v_vTex0UV.y - stepy));
		sample1 = texture2D(u_sTexture1, vec2(v_vTex0UV.x + stepx, v_vTex0UV.y + stepy));
		sample2 = texture2D(u_sTexture1, vec2(v_vTex0UV.x + stepx, v_vTex0UV.y - stepy));
		sample3 = texture2D(u_sTexture1, vec2(v_vTex0UV.x - stepx, v_vTex0UV.y + stepy));
		
		if (sample0.x == 0.0 || sample1.x == 0.0 || sample2.x == 0.0 || sample3.x == 0.0)
		{
			result = vec4(1.0, 1.0, 0.0, 1.0);
		}
		else
		{
			result = texture2D(u_sTexture0, v_vTex0UV);
		}
	}
	else
	{
		result = texture2D(u_sTexture0, v_vTex0UV);
	}
	
	gl_FragColor = result;
};