#define iChannel0 inputImageTexture
#define texture(a,b) texture2D(a,fract(b))
#define fragColor gl_FragColor
varying highp vec2 textureCoordinate;
varying highp vec2 textureCoordinate2;

uniform sampler2D inputImageTexture;
uniform sampler2D inputImageTexture2;
uniform lowp float mixturePercent;

void main()
{
    lowp vec4 c2 = texture2D(inputImageTexture2, textureCoordinate2);
    lowp vec4 c = texture2D(inputImageTexture, textureCoordinate);

    if (c2.r+c2.g+c2.b<=0.0) {
        c2.a = 0.0;
    }

    if (c.r + c.g + c.b + c.a > 3.5) {

        highp int i = 0;
        highp float temp = min(c.r,c.g);
        if (c.r < c.g) i = 0;else i = 1;
        if (c.b < temp) i = 2;

        if (i == 0)  c.r *= 0.4;
        if (i == 1)  c.g *= 0.4;
        if (i == 2)  c.b *= 0.4;

    }

    else {
        //if (c.r < 0.5 && c.g < 0.5 && c.b < 0.5) {
        c = vec4(0.0);
    }

    gl_FragColor = mix(c,c2,c2.a - mixturePercent);
}