uniform sampler2D EdgeMask;
uniform sampler2D Unexplored;

void main()
{
	//overriding the c++ 
	float EdgeRepeatRate = 1.0;
	float UnexploredRepeatRate = 2.0;


	//SFML on MacOS can't give us a 150 compatible GL context, so I'm hard coding the texture sizes for now - Cheese
	//vec4 EdgeMaskHeight = texture2D(EdgeMask, gl_FragCoord.xy/textureSize(EdgeMask,0)*EdgeRepeatRate);    //(gl_FragCoord.xy/1080)*EdgeRepeatRate);
	//vec4 UnexploredColor = texture2D(Unexplored, gl_FragCoord.xy/textureSize(Unexplored,0)*UnexploredRepeatRate);

	vec4 EdgeMaskHeight = texture2D(EdgeMask, gl_FragCoord.xy/vec2(64,64)*EdgeRepeatRate);
	vec4 UnexploredColor = texture2D(Unexplored, gl_FragCoord.xy/vec2(1,1)*UnexploredRepeatRate);

	float EdgeMasking = clamp(((gl_Color.x*2.0)+(EdgeMaskHeight.x-1.0)),0.0,1.0);

	vec4 pixel = vec4(0.0,0.0,0.0,0.0);
	pixel = vec4(UnexploredColor.xyz,EdgeMasking);
	gl_FragColor = pixel;



	//TODO: This should be an entirely separate shader with everything
	// calculated based on the image generated by the above code,
	// simplifying what's below down to:
	//    alpha = max(alpha, texture2D(fow, gl_FragCoord + tempX).a);
	//    alpha = max(alpha, texture2D(fow, gl_FragCoord - tempX).a);
	//    alpha = max(alpha, texture2D(fow, gl_FragCoord + tempY).a);
	//    alpha = max(alpha, texture2D(fow, gl_FragCoord - tempY).a);

	vec2 tempX;
	tempX.x = 1.0;
	vec2 tempY;
	tempX.y = 1.0;

	//Only operate on transparent regions
	if (gl_FragColor.a < 1.0)
	{
		float alpha = gl_FragColor.a;

		//Check for pixels that have partial transparency
		EdgeMaskHeight = texture2D(EdgeMask, (gl_FragCoord.xy + tempX)/vec2(64,64)*EdgeRepeatRate);
		EdgeMasking = clamp(((gl_Color.x*2.0)+(EdgeMaskHeight.x-1.0)),0.0,1.0);
		alpha = max(alpha, EdgeMasking);

		EdgeMaskHeight = texture2D(EdgeMask, (gl_FragCoord.xy - tempX)/vec2(64,64)*EdgeRepeatRate);
		EdgeMasking = clamp(((gl_Color.x*2.0)+(EdgeMaskHeight.x-1.0)),0.0,1.0);
		alpha = max(alpha, EdgeMasking);

		EdgeMaskHeight = texture2D(EdgeMask, (gl_FragCoord.xy + tempY)/vec2(64,64)*EdgeRepeatRate);
		EdgeMasking = clamp(((gl_Color.x*2.0)+(EdgeMaskHeight.x-1.0)),0.0,1.0);
		alpha = max(alpha, EdgeMasking);

		EdgeMaskHeight = texture2D(EdgeMask, (gl_FragCoord.xy - tempY)/vec2(64,64)*EdgeRepeatRate);
		EdgeMasking = clamp(((gl_Color.x*2.0)+(EdgeMaskHeight.x-1.0)),0.0,1.0);
		alpha = max(alpha, EdgeMasking);

		//Make the pixel dark blue (transparent pixels don't matter)
		gl_FragColor = vec4(0.25, 0.25 , 0.4, gl_FragColor.a);
	}
}
