// Overscan shader (helps to get rid of black bars by enlarging the image)

// edit theese values to get the overscan you want (set a negative value for shrinking)

#define OverscanX 0.05              // relative x-overscan setting
#define OverscanY 0.05              // relative y-overscan setting

uniform sampler2D OGL2Texture;
uniform vec4 OGL2Size;
uniform vec4 OGL2Param;
uniform vec4 OGL2InvSize;


vec2 Overscan(vec2 pos){
  pos=pos*2.0-1.0;    
  pos*=vec2(1.0-OverscanX,1.0-OverscanY);
  return pos*0.5+0.5;}


void main()
{
	vec2 texcoord = vec2(gl_TexCoord[1].x,1.0-gl_TexCoord[1].y);
	vec2 pos=Overscan(texcoord)*OGL2Size.zw;
	vec2 diff = pos - texcoord*OGL2Size.zw;
	
	float black = 1.0 - sign(dot(abs(pos-clamp(pos,vec2(OGL2InvSize.x, OGL2InvSize.y),vec2(OGL2Size.z-OGL2InvSize.x,OGL2Size.w-OGL2InvSize.y))),vec2(1.0)));  // garbage cleaning
	
	gl_FragColor.xyz = texture2D(OGL2Texture, gl_TexCoord[0].xy+diff).xyz*black;
}
