float pSize=128.0;
float pSizeMax=1024.0;


float pointSize(vec4 loc)
{
float len = length(loc);

//distance attenuation as seen in point sprites...
//derivedSize = clamp (size * sqrt (1 / (a + b * d + c * d^2)))
//return (clamp(pSize * sqrt(1.0/(1.0+0.0*len+0.015*pow(len,2.0))),0.0,pSizeMax));

//linear attenuation
float myPSize=pSize/len;
if (myPSize<10)
  myPSize=15;
return (myPSize);
}


void main()
{
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_FrontColor=gl_Color;
float particleScale=1.0;

particleScale=gl_Vertex.w*3;

//reset gl_Vertex coordinate or we create weird distortions!
gl_Vertex.w=1.0;

gl_Position = ftransform();
gl_PointSize=pointSize(gl_Position)*particleScale;
}




