varying vec4 EyeSpacePosition;
varying vec2 uv;
varying vec4 pos;

void main(void)
   {
   vec2 p = uv;
   p = (p)*2-vec2(1, 1);

   float d_squared = dot(p,p);
   
   vec4 LocalEyeSpacePosition = vec4
         (
         EyeSpacePosition.x-uv.x/2.0,
         EyeSpacePosition.y-uv.y/2.0,
         EyeSpacePosition.z,
         EyeSpacePosition.w
         );
   
   if (d_squared<=1.0)
      {
      float h = sqrt(1.0-d_squared);
      vec4 value = vec4(0,0,h*0.45,0);
      vec4 newpoint = (LocalEyeSpacePosition-value) * gl_ProjectionMatrix;
      gl_FragDepth = (pos.z-0.5*h)/pos.w;
      vec4 p = LocalEyeSpacePosition-value;
      gl_FragColor = vec4(normalize(EyeSpacePosition-p).xyz, LocalEyeSpacePosition.z);
      }
   else
      {
      discard;
      }
   }