 
 void main(void)
 {
+    vec3 directionWC = normalize(position.xyz - czm_viewerPositionWC);
+    vec3 directionEC = (czm_view * vec4(directionWC, 0.0)).xyz;
+    czm_ray viewRay = czm_ray(vec3(0.0), directionEC);
+    czm_raySegment raySegment = czm_rayEllipsoidIntersectionInterval(viewRay, czm_view[3].xyz, czm_ellipsoidInverseRadii);
+    bool underEllipsoid = raySegment.start >= 0.0;
+
+    float t = raySegment.stop;
+    vec3 positionWC = underEllipsoid ? czm_viewerPositionWC + t * directionWC : czm_viewerPositionWC;
+
     // Unpack attributes
     float cameraHeight = u_cameraAndRadiiAndDynamicAtmosphereColor.x;
     float outerRadius = u_cameraAndRadiiAndDynamicAtmosphereColor.y;

    // Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
    v_mieColor = frontColor * KmESun;
    v_rayleighColor = frontColor * (InvWavelength * KrESun);
    v_toCamera = czm_viewerPositionWC - positionV3;
    gl_Position = czm_modelViewProjection * position;
}


    float lightEnum = u_cameraAndRadiiAndDynamicAtmosphereColor.w;
    vec3 lightDirection =
        positionWC * float(lightEnum == 0.0) +
        czm_lightDirectionWC * float(lightEnum == 1.0) +
        czm_sunDirectionWC * float(lightEnum == 2.0);
    lightDirection = normalize(lightDirection);
