
#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)
{
	vec2 v_texCoord = gl_TexCoord[0].st;

    mediump vec3 dst;
    mediump vec3 txt;
    
    mediump float offset;
    mediump vec2  coord;
    
    dst.rgb = texture2D(SamplerBGRA, v_texCoord).rgb;
    //if which == 0 else ...
    offset = (1.0 - kk)*0.5;
    coord = vec2(offset*(1.0-which)+v_texCoord.x*(which+(1.0-which)*kk), offset*which + v_texCoord.y*(1.0-which+which*kk));
    txt = texture2D(SamplerBackTex1, coord).rgb;
    
    txt.r = max(dst.r, txt.r);
    txt.g = max(dst.g, txt.g);
    txt.b = max(dst.b, txt.b);
    dst = dst * 0.55 + txt * 0.45;
    outText = vec4(dst,1.0);
}