
#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)
{
    mediump vec3 dst;
    mediump vec3 dst_a;
    mediump vec3 dst_b;
    mediump vec3 txt;
    mediump vec3 tmp_s;
    mediump vec3 tmp_t;
    
    mediump float lum;
    lowp float saturate = 0.9;
    lowp float bound_h = 0.1;
    
    dst.rgb = texture2D(SamplerBGRA, gl_TexCoord[0].st).rgb;        
    txt = texture2D(SamplerBackTex1, gl_TexCoord[0].st).rgb;
    
    lum = dst.r*0.299 + dst.g*0.587 + dst.b*0.114;
    
    tmp_s = lum*bound_h + saturate*dst;
    tmp_s = tmp_s/saturate;
    
    tmp_t.r = min(1.0,txt.r+tmp_s.r-txt.r*tmp_s.r);
    tmp_t.g = min(1.0,txt.g+tmp_s.g-txt.g*tmp_s.g);
    tmp_t.b = min(1.0,txt.b+tmp_s.b-txt.b*tmp_s.b);
    
    dst = tmp_s*0.49 + tmp_t*0.51;
    outText = vec4(dst,1.0);
}