uniform float pointSize;
varying vec3 col; 
varying vec3 worldspaceSphereCenter;
//varying vec4 baseZpos;
//varying vec4 zCorrectionVector;
uniform float time;
varying float rPointSize;

void main(void) 
{
  col= vec3(0.7,0.2,0.2); 
  //  gl_Position = ftransform() + vec4(gl_MultiTexCoord0[0],gl_MultiTexCoord0[1],0.0,0.0); 

  /* this is a bit of a hassle, but in order to find the actual
     screen-space size of the sphere, we first take the screen up vector,
     transform it into world space, place it inside the center of the
     sphere, the project both the center of the sphere and the newly found
     'top' of the sphere back to view space, and then calculate the length
     of the found vector in screen space.
   */

  vec4 attributes = gl_Color;
  rPointSize = (cos(attributes.x*300.0+time*2.0) * .3 + .4) * pointSize;

  vec3 worldspaceUpVector = normalize( (gl_ModelViewProjectionMatrixInverse * vec4(0,1,0,0)).xyz );
  vec3 worldspaceRightVector = normalize( (gl_ModelViewProjectionMatrixInverse * vec4(1,0,0,0)).xyz  );
  float scale = rPointSize * gl_Color.x;



  vec4 m_vertex = gl_Vertex;
  m_vertex +=
  gl_Position =  gl_ModelViewProjectionMatrix * m_vertex;

  m_vertex.xyz +=  scale*(gl_MultiTexCoord0[0] * worldspaceUpVector + gl_MultiTexCoord0[1] * worldspaceRightVector);
  gl_Position =  gl_ModelViewProjectionMatrix * m_vertex;



  /* vec4 worldspaceUpVector = normalize( vec4(0,1,0,1) * gl_ModelViewProjectionMatrixInverse ); */
  /* vec4 screenSphereCenter = (gl_ModelViewProjectionMatrix * (gl_Vertex + worldspaceUpVector)); */
  /* vec4 screenSphereTop = (gl_ModelViewProjectionMatrix * (gl_Vertex)); */

  /* vec2 projectedSphereCenter = screenSphereCenter.xy / screenSphereCenter.z  * screenSphereCenter.w; */
  /* vec2 projectedSphereTop = screenSphereTop.xy / screenSphereTop.z  * screenSphereTop.w; */

  //  vec4 spherePixelSize = 0.5 * length(projectedSphereTop - projectedSphereCenter) / pixelSize;

  //  gl_PointSize = spherePixelSize; 
  worldspaceSphereCenter = gl_Vertex.xyz;

  /* vec4 up = gl_ModelViewProjectionMatrixInverse * */
  /*   vec4(0.0, 0.0, -1.0, 0.0); */
  /* vec4 zPos = gl_ModelViewProjectionMatrix * */
  /*   vec4(pos.xyz + normalize(up.xyz) * z * pointSize, 1); */

  /* vec4 up = gl_ModelViewProjectionMatrixInverse *  vec4(0.0, 0.0, -1.0, 0.0); */
  /* baseZpos = gl_ModelViewProjectionMatrix *  vec4(gl_Vertex.xyz , 1); */

  /* zCorrectionVector = gl_ModelViewProjectionMatrix * vec4( normalize(up.xyz) * pointSize, 1.0 ); */

  gl_TexCoord[0]=gl_MultiTexCoord0; 
}
