precision mediump float;

varying mediump vec2 vTextureCoord;

uniform sampler2D uSampler;
uniform sampler2D uSampler2;  //process
uniform sampler2D uSampler3;  //blowout
uniform sampler2D uSampler4;  //contrast
uniform sampler2D uSampler5;  //luma
uniform sampler2D uSampler6;  //screen

mat3 saturateMatrix = mat3(
1.105150, -0.044850,-0.046000,
-0.088050,1.061950,-0.089200,
-0.017100,-0.017100,1.132900);

vec3 luma = vec3(.3, .59, .11);

uniform float strength;

void main()
{
    vec4 originColor = texture2D(uSampler, vTextureCoord);
    vec3 texel = texture2D(uSampler, vTextureCoord).rgb;

    vec2 lookup;
    lookup.y = 0.5;
    lookup.x = texel.r;
    texel.r = texture2D(uSampler2, lookup).r;
    lookup.x = texel.g;
    texel.g = texture2D(uSampler2, lookup).g;
    lookup.x = texel.b;
    texel.b = texture2D(uSampler2, lookup).b;

    texel = saturateMatrix * texel;


    vec2 tc = (2.0 * vTextureCoord) - 1.0;
    float d = dot(tc, tc);
    vec3 sampled;
    lookup.y = 0.5;
    lookup.x = texel.r;
    sampled.r = texture2D(uSampler3, lookup).r;
    lookup.x = texel.g;
    sampled.g = texture2D(uSampler3, lookup).g;
    lookup.x = texel.b;
    sampled.b = texture2D(uSampler3, lookup).b;
    float value = smoothstep(0.0, 1.0, d);
    texel = mix(sampled, texel, value);

    lookup.x = texel.r;
    texel.r = texture2D(uSampler4, lookup).r;
    lookup.x = texel.g;
    texel.g = texture2D(uSampler4, lookup).g;
    lookup.x = texel.b;
    texel.b = texture2D(uSampler4, lookup).b;


    lookup.x = dot(texel, luma);
    texel = mix(texture2D(uSampler5, lookup).rgb, texel, .5);

    lookup.x = texel.r;
    texel.r = texture2D(uSampler6, lookup).r;
    lookup.x = texel.g;
    texel.g = texture2D(uSampler6, lookup).g;
    lookup.x = texel.b;
    texel.b = texture2D(uSampler6, lookup).b;

    texel = mix(originColor.rgb, texel.rgb, 1.0);

    gl_FragColor = vec4(texel, 1.0);
}