varying vec4 worldPosition;
uniform vec2 lightPosition;

uniform float lightRadius;
varying float lightRadiusSquared;

void main() {

	float distSquared = (lightPosition.x-worldPosition.x)*(lightPosition.x-worldPosition.x)+(lightPosition.y-worldPosition.y)*(lightPosition.y-worldPosition.y);
	
	float solidFactor = 0.325;
	float brightness = 0.0;
	
	if (distSquared < lightRadiusSquared) {
	
		float dist = sqrt(distSquared);
		
		float fadeBegin = lightRadius*solidFactor;
		
		if (dist <= fadeBegin)
			brightness = 1.0;
		else {
			brightness = 1.0-(dist-fadeBegin)/(lightRadius-fadeBegin);
			brightness *= brightness;
		}
	}
	
	gl_FragColor = vec4(brightness, brightness, brightness, 1.0);
	
}