/*
	gaussian selective blur algorithm - XPeng
*/

#version 130


uniform sampler2D 	inText;		// input sampler, normal
uniform sampler2D	bluredText;	// input sampler, blured 
out     vec4 		outText;	// output sampler

uniform  float excludeCircleRadius;
uniform  vec2 excludeCirclePoint;
uniform  float excludeBlurSize;
uniform  float aspectRatio;
uniform float rangeX, rangeY, rangeW, rangeH;
  
void main()
{
	 vec2 textureCoordinate = gl_TexCoord[0].xy;
     vec4 sharpImageColor = texture2D(inText, textureCoordinate);
     vec4 blurredImageColor = texture2D(bluredText, textureCoordinate);
     
	 vec2 v_texCoord = vec2(gl_TexCoord[0].s*rangeW+rangeX, gl_TexCoord[0].t*rangeH+rangeY);
     vec2 textureCoordinateToUse = vec2(v_texCoord.x, (v_texCoord.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
     vec2 centerPointToUse = vec2(excludeCirclePoint.x, (excludeCirclePoint.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
     float distanceFromCenter = distance(centerPointToUse, textureCoordinateToUse);
    
	//outText = mix(sharpImageColor, blurredImageColor, smoothstep(excludeCircleRadius - excludeBlurSize, excludeCircleRadius, distanceFromCenter));
	float edge0 = excludeCircleRadius - excludeBlurSize;
	float edge1 = excludeCircleRadius;
	float fFac = clamp((distanceFromCenter-edge0)/(edge1-edge0), 0, 1);
	outText = mix(sharpImageColor, blurredImageColor, sqrt(fFac));     //slow??
}

