
#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

uniform mediump float kk;
uniform mediump float which;

void main(void)
{
    mediump vec3 dst;
    mediump vec3 tmp_t;
    mediump vec3 txt;
    
    mediump vec2  coord;
    mediump float lum;
    mediump float lum_t = 0.275286;
    lowp float saturate = 0.5;

    dst.rgb = texture2D(SamplerBGRA, gl_TexCoord[0].st).rgb;    
    //if which == 0 else ...
    coord = vec2(gl_TexCoord[0].x*(which+(1.0-which)*kk), gl_TexCoord[0].y*(1.0-which+which*kk));
    txt = texture2D(SamplerBackTex1, coord).rgb;

    lum = dst.r*0.299 + dst.g*0.587 + dst.b*0.114;
    dst = lum*(1.0-saturate) + saturate*dst;
    
    dst.r = min(1.0,dst.r+dst.r-dst.r*dst.r);
    dst.g = min(1.0,dst.g+dst.g-dst.g*dst.g);
    dst.b = min(1.0,dst.b+dst.b-dst.b*dst.b);
    
    dst = dst*0.49 + txt*0.51;    
    
    lum = lum-lum_t;
    tmp_t = vec3(0.42743, 0.23529, 0.082336);
    
    dst = dst*0.66 + (tmp_t+lum)*0.34;
    outText = vec4(dst,1.0);
}