//$c3 OZ  04/24/08 fixed alpha fading for speedpak bubble effect
//$c2 OZ  12/12/07 added fading effect on centerPoint.z
//$c1 OZ  08/30/07 removed distortion
//$c0 OZ 08/23/07 created

// this line is needed to get the associated xml files
#define SW_PARAMETER_FILES "global.xml, magnifyglass.xml"



varying vec2 v_Vertex;
varying vec2 v_TexCoord;
varying vec4 v_FloorPoint;

/////////////////////////////////////////////////////////////////////////////////

#ifdef _VERTEX_PROGRAM
void main()
{
	// vertex position in clip space
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	
	v_TexCoord.xy = gl_MultiTexCoord0.xy;

	// vertex position in eye space
	v_Vertex = (gl_ModelViewMatrix * gl_Vertex).xy;
	v_FloorPoint = gl_ModelViewMatrix * vec4(centerPoint.xy, 0.0, 1.0);
}
#endif //_VERTEX_PROGRAM







#ifdef _FRAGMENT_PROGRAM

void main()
{
	float radialDist = distance(v_Vertex, v_FloorPoint.xy)/centerPoint.w;
	if (radialDist >= 1.0)
		discard;

	// shadow and reflection part will write alpha value < 1.0 so make sure we overwrite finalColor.a, not modulate with it
	vec4 finalColor = texture2D(mainMap2D, v_TexCoord);
	if (radialDist > centerPoint.z)
		finalColor.a = 1.0 - (radialDist-centerPoint.z)/(1-centerPoint.z);
	else
		finalColor.a = 1.0;

	gl_FragColor = finalColor;
}
#endif //_FRAGMENT_PROGRAM


