// 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.00              // relative x-overscan setting
#define OverscanY 0.09              // relative y-overscan setting


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()
{
const vec2 OGLSize    = vec2( 1024.0, 512.0);
vec2 OGLInvSize = 1.0/OGLSize;
float dx = OGLInvSize.x;
float dy = OGLInvSize.y;

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;


vec2 texcoord = vec2(gl_MultiTexCoord1.x,1.0-gl_MultiTexCoord1.y);
vec2 pos=Overscan(texcoord)*OGL2Size.zw;
vec2 diff = pos - texcoord*OGL2Size.zw;

gl_TexCoord[0].xy = gl_TexCoord[0].xy + diff;

gl_TexCoord[1] = gl_TexCoord[0].xxxy + vec4( -dx, 0, dx,-2.0*dy); // A1 B1 C1
gl_TexCoord[2] = gl_TexCoord[0].xxxy + vec4( -dx, 0, dx,    -dy); //  A  B  C
gl_TexCoord[3] = gl_TexCoord[0].xxxy + vec4( -dx, 0, dx,      0); //  D  E  F
gl_TexCoord[4] = gl_TexCoord[0].xxxy + vec4( -dx, 0, dx,     dy); //  G  H  I
gl_TexCoord[5] = gl_TexCoord[0].xxxy + vec4( -dx, 0, dx, 2.0*dy); // G5 H5 I5
gl_TexCoord[6] = gl_TexCoord[0].xyyy + vec4(-2.0*dx,-dy, 0,  dy); // A0 D0 G0
gl_TexCoord[7] = gl_TexCoord[0].xyyy + vec4( 2.0*dx,-dy, 0,  dy); // C4 F4 I4
}
