varying vec3 spriteCenterVS, viewPos;
varying float radius;

void main(void) {

	vec3 viewDir = normalize(viewPos);
	float dotLC = dot(viewDir,spriteCenterVS);
	float discr = dotLC*dotLC-dot(spriteCenterVS,spriteCenterVS)+radius*radius;
	
	if (discr<0.0) discard;	
	
	float t = dotLC - sqrt(discr);
	
	vec3 ballPosVS = viewDir * t;
	vec3 normalVS = (ballPosVS-spriteCenterVS)*(1.0/radius);
	
	vec3 normal = normalVS;
	
	vec3 r = reflect(viewDir, normal);
	
	float len = length(ballPosVS);
	
	vec4 projectedPoint = gl_ProjectionMatrix * vec4(ballPosVS, 1.0);
	
	float a = max(0.0, dot(normal, vec3(0.0,0.0,1.0)));
	
	gl_FragDepth = projectedPoint.z / projectedPoint.w;
	gl_FragColor = (gl_Color * a * (1.0/(1.0+len*len*0.01)) + vec4(1,1,1,0)*pow(max(r.y,0.0), 57.0)*1.0);
}