#ifdef GL_ES
precision mediump float;
#endif

varying vec4 v_fragmentColor;
varying vec2 v_texCoord;

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

uniform mediump float kk;
uniform mediump float which;

void main(void)
{
    mediump vec3 dst;
    mediump vec3 txt;
    
    mediump float lum;
    
    dst.rgb = texture2D(SamplerBGRA, v_texCoord).bgr;
    txt = texture2D(SamplerBackTex1, v_texCoord).rgb;
    
    lum = dst.r*0.299 + dst.g*0.587 + dst.b*0.114;
    
    if(lum < 0.5)
    {
        dst = 2.0*(lum * txt);
    }
    else
    {
        dst = 2.0*(lum + txt) - lum * txt * 2.0 - 1.0;
    }
    
    gl_FragColor = vec4(dst,1.0);
}