attribute vec4 vertex;
attribute vec3 color;
attribute vec2 texCoordinate;
uniform mat4 modelView;
uniform mat4 projection;
varying vec2 v_texCoord;
varying vec3 fColor;
varying vec4 eyePosition;
varying float radius;

void main()
{
  radius = abs(texCoordinate.x);
  fColor = color;
  v_texCoord = texCoordinate / radius;
  gl_Position = modelView * vertex;
  eyePosition = gl_Position;
  gl_Position.xy += texCoordinate;
  gl_Position = projection * gl_Position;
}

attribute vec4 vertex;
attribute vec3 color;
attribute vec2 texCoordinate;
uniform mat4 modelView;
uniform mat4 projection;
varying vec2 v_texCoord;
varying vec3 fColor;
varying vec4 eyePosition;
varying float radius;

void main()
{
  radius = abs(texCoordinate.x);
  fColor = color;
  v_texCoord = texCoordinate / radius;
  gl_Position = modelView * vertex;
  eyePosition = gl_Position;

  // Test if the closest point on the sphere would be clipped.
  vec4 clipTestNear = eyePosition;
  clipTestNear.z += radius;
  clipTestNear = projection * clipTestNear;
  if (clipTestNear.z > -clipTestNear.w) {
    // If not, calculate clip coordinate
    gl_Position.xy += texCoordinate;
    gl_Position = projection * gl_Position;
  }
  else {
    // If so, invalidate the clip coordinate to ensure that it will be clipped.
    gl_Position.w = 0.0;
  }
}

Fix rendering artifact for partially-clipped spheres.
Fix rendering artifact for partially-clipped spheres.

If a sphere was clipped by the near-plane, the unclipped back of
the sphere would be rendered using the lighting equations for the
front of the sphere.

This patch ensures that spheres that would be clipped by the near-plane
will not be rendered at all.

Change-Id: Ic5c8151acfccfcf8eb728c8652e153186356e2be
