
#version 130
precision mediump float;

uniform sampler2D SamplerBGRA;
//uniform sampler2D SamplerTableTex1;
//uniform sampler2D SamplerTableTex2;
//uniform sampler2D SamplerBackTex1;
//uniform sampler2D SamplerBackTex2;

out     vec4 		outText;	// output sampler

void main(void)
{
	vec2 v_texCoord = gl_TexCoord[0].st;

    mediump vec3 dst;
    
    mediump vec2 coord;
    mediump float max_r;
    mediump vec2 dis;
    mediump float lens_fac;
    mediump float lens_facinv;
    mediump float lens_amount;
    mediump float bd;
    mediump float alpha;
    
    lowp float saturate = 0.85;
    lowp float bound_h = 0.15;
    mediump float lum;
    
    dst.rgb = texture2D(SamplerBGRA, v_texCoord).rgb;        

    //calculate alpha
    coord = vec2(v_texCoord.x * 2.0, v_texCoord.y * 3.0);
    max_r = 1.5;
    dis.x = (1.0 - coord.x);
    dis.y = (1.5 - coord.y);
    
    lens_fac = 2.25;
    lens_facinv = 0.444444;
    lens_amount = 0.796875;
    
    bd = dis.x* dis.x + dis.y* dis.y;
    bd = ((lens_fac + bd) * lens_facinv);
    bd = bd*bd;
    bd = 1.0/bd;
    alpha = 1.0 + lens_amount*(bd - 1.0);
    //calculate alpha end
    
    lum = dst.r*0.299 + dst.g*0.587 + dst.b*0.114;
    
    lum /= saturate;
    lum *= alpha;
    
    outText = vec4(vec3(lum),1.0);
}