EllipsoidVS.glsl 1.3 KB

1234567891011121314151617181920212223242526
  1. attribute vec3 position;
  2. uniform vec3 u_radii;
  3. varying vec3 v_positionEC;
  4. void main()
  5. {
  6. // In the vertex data, the cube goes from (-1.0, -1.0, -1.0) to (1.0, 1.0, 1.0) in model coordinates.
  7. // Scale to consider the radii. We could also do this once on the CPU when using the BoxGeometry,
  8. // but doing it here allows us to change the radii without rewriting the vertex data, and
  9. // allows all ellipsoids to reuse the same vertex data.
  10. vec4 p = vec4(u_radii * position, 1.0);
  11. v_positionEC = (czm_modelView * p).xyz; // position in eye coordinates
  12. gl_Position = czm_modelViewProjection * p; // position in clip coordinates
  13. // With multi-frustum, when the ellipsoid primitive is positioned on the intersection of two frustums
  14. // and close to terrain, the terrain (writes depth) in the closest frustum can overwrite part of the
  15. // ellipsoid (does not write depth) that was rendered in the farther frustum.
  16. //
  17. // Here, we clamp the depth in the vertex shader to avoid being overwritten; however, this creates
  18. // artifacts since some fragments can be alpha blended twice. This is solved by only rendering
  19. // the ellipsoid in the closest frustum to the viewer.
  20. gl_Position.z = clamp(gl_Position.z, czm_depthRange.near, czm_depthRange.far);
  21. }