precision highp float;
varying highp vec2 textureCoordinate;
uniform sampler2D inputTexture;
uniform sampler2D toneCurveTexture;

void main() {
    vec4 textureColor = texture2D(inputTexture, textureCoordinate);
    lowp float redCompositeCurveValue = clamp(texture2D(toneCurveTexture, vec2(textureColor.r, 0.0)).r, 0.0, 1.0);
    lowp float greenCompositeCurveValue = clamp(texture2D(toneCurveTexture, vec2(textureColor.g, 0.0)).g, 0.0, 1.0);
    lowp float blueCompositeCurveValue = clamp(texture2D(toneCurveTexture, vec2(textureColor.b, 0.0)).b, 0.0, 1.0);
    lowp float redCurveValue = texture2D(toneCurveTexture, vec2(redCompositeCurveValue, 1.0)).r;
    lowp float greenCurveValue = texture2D(toneCurveTexture, vec2(greenCompositeCurveValue, 1.0)).g;
    lowp float blueCurveValue = texture2D(toneCurveTexture, vec2(blueCompositeCurveValue, 1.0)).b;
    gl_FragColor = vec4(redCurveValue * textureColor.a, greenCurveValue * textureColor.a, blueCurveValue * textureColor.a, textureColor.a);
}