
#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()
{
    mediump vec3 rgb;
    mediump vec3 dst;
    mediump vec3 tmp2_pic;
    mediump float max_r;
    mediump vec2 dis;
    mediump vec2 coord;
    mediump float lens_fac;
    mediump float lens_facinv;
    mediump float lens_amount;
    mediump float bd;
    mediump float alpha;
    mediump float lumm;
    mediump float lumm_rev;
    
    rgb.rgb = texture2D(SamplerBGRA, gl_TexCoord[0].st).rgb;
    
    //calculate alpha
    coord = vec2(gl_TexCoord[0].x * 2.0, gl_TexCoord[0].y * 3.0);
    max_r = 2.61165;
    dis.x = (1.0 - coord.x);
    dis.y = (1.5 - coord.y);
    
    lens_fac = 6.82;
    lens_facinv = 1.0/lens_fac;
    lens_amount = 0.3984;
    
    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
    
    dst = rgb*alpha;
    
    lumm = dst.r*0.299 + dst.g*0.587 + dst.b*0.114;
    lumm_rev = 1.0-lumm;
    
    if(lumm < 0.5)
    {
        tmp2_pic.r = lumm * dst.r * 2.0;
    }
    else
    {
        tmp2_pic.r = 2.0*(lumm + dst.r) - lumm * dst.r * 2.0 - 1.0;
    }
    if(lumm < 0.5)
    {
        tmp2_pic.g = lumm * dst.g * 2.0;
    }
    else
    {
        tmp2_pic.g = 2.0*(lumm + dst.g) - lumm * dst.g * 2.0 - 1.0;
    }
    if(lumm_rev < 0.5)
    {
        tmp2_pic.b = lumm_rev * dst.b * 2.0;
    }
    else
    {
        tmp2_pic.b = 2.0*(lumm_rev + dst.b) - lumm_rev * dst.b * 2.0 - 1.0;
    }
    dst = dst * 0.5+ tmp2_pic * 0.5;
    
    outText = vec4(dst,1.0);
}