/*
	sharpen algorithm - XPeng
*/

#version 130


uniform sampler2D 	inText;		// input sampler
out     vec4 		outText;	// output sampler

uniform float imageWidthFactor; // x step
uniform float imageHeightFactor;// y step
uniform float sharpness;		// Sharpness ranges from -4.0 to 4.0, with 0.0 as the normal level
 
void main()
{
     vec2 widthStep = vec2(imageWidthFactor, 0.0);
     vec2 heightStep = vec2(0.0, imageHeightFactor);

	vec2 leftTextureCoordinate = gl_TexCoord[0].xy - widthStep;
	vec2 rightTextureCoordinate = gl_TexCoord[0].xy + widthStep; 
	vec2 topTextureCoordinate = gl_TexCoord[0].xy + heightStep;
	vec2 bottomTextureCoordinate = gl_TexCoord[0].xy - heightStep;
 
	float centerMultiplier = 1.0 + 4.0 * sharpness;
	float edgeMultiplier = sharpness;

     vec3 textureColor = texture2D(inText, gl_TexCoord[0].xy).rgb;
     vec3 leftTextureColor = texture2D(inText, leftTextureCoordinate).rgb;
     vec3 rightTextureColor = texture2D(inText, rightTextureCoordinate).rgb;
     vec3 topTextureColor = texture2D(inText, topTextureCoordinate).rgb;
     vec3 bottomTextureColor = texture2D(inText, bottomTextureCoordinate).rgb;

    outText = vec4((textureColor * centerMultiplier - (leftTextureColor * edgeMultiplier + rightTextureColor * edgeMultiplier + topTextureColor * edgeMultiplier + bottomTextureColor * edgeMultiplier)), texture2D(inText, gl_TexCoord[0].xy).w);
}

