precision highp float;

uniform sampler2D uSampler;
uniform sampler2D uSampler2;
varying highp vec2 vTextureCoord;

void main()
{ 
	lowp vec4 textureColor;
	lowp vec4 textureColorRes; 
	lowp vec4 textureColorOri; 
	vec4 grey1Color; 
	vec4 layerColor; 
	mediump float satVal = 115.0 / 100.0; 

    float xCoordinate = vTextureCoord.x;
	float yCoordinate = vTextureCoord.y;
	
	highp float redCurveValue; 
	highp float greenCurveValue; 
	highp float blueCurveValue; 

	textureColor = texture2D( uSampler, vec2(xCoordinate, yCoordinate));
    textureColorRes = textureColor;
	textureColorOri = textureColor;

	textureColor = 1.0 - ((1.0 - textureColorOri) * (1.0 - textureColorOri)); 
	textureColor = (textureColor - textureColorOri) + textureColorOri; 

	redCurveValue = texture2D(uSampler2, vec2(textureColor.r, 0.0)).r;
	greenCurveValue = texture2D(uSampler2, vec2(textureColor.g, 0.0)).g;
    blueCurveValue = texture2D(uSampler2, vec2(textureColor.b, 0.0)).b;

	highp float G = (redCurveValue + greenCurveValue + blueCurveValue); 
	G = G / 3.0; 

    redCurveValue = ((1.0 - satVal) * G + satVal * redCurveValue); 
	greenCurveValue = ((1.0 - satVal) * G + satVal * greenCurveValue); 
	blueCurveValue = ((1.0 - satVal) * G + satVal * blueCurveValue); 

	textureColor = vec4(redCurveValue, greenCurveValue, blueCurveValue, 1.0); 

    gl_FragColor = vec4(textureColor.r, textureColor.g, textureColor.b, 1.0); 
}
