translateRelativeToEye.glsl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * Translates a position (or any <code>vec3</code>) that was encoded with {@link EncodedCartesian3},
  3. * and then provided to the shader as separate <code>high</code> and <code>low</code> bits to
  4. * be relative to the eye. As shown in the example, the position can then be transformed in eye
  5. * or clip coordinates using {@link czm_modelViewRelativeToEye} or {@link czm_modelViewProjectionRelativeToEye},
  6. * respectively.
  7. * <p>
  8. * This technique, called GPU RTE, eliminates jittering artifacts when using large coordinates as
  9. * described in {@link http://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.
  10. * </p>
  11. *
  12. * @name czm_translateRelativeToEye
  13. * @glslFunction
  14. *
  15. * @param {vec3} high The position's high bits.
  16. * @param {vec3} low The position's low bits.
  17. * @returns {vec3} The position translated to be relative to the camera's position.
  18. *
  19. * @example
  20. * in vec3 positionHigh;
  21. * in vec3 positionLow;
  22. *
  23. * void main()
  24. * {
  25. * vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
  26. * gl_Position = czm_modelViewProjectionRelativeToEye * p;
  27. * }
  28. *
  29. * @see czm_modelViewRelativeToEye
  30. * @see czm_modelViewProjectionRelativeToEye
  31. * @see czm_computePosition
  32. * @see EncodedCartesian3
  33. */
  34. vec4 czm_translateRelativeToEye(vec3 high, vec3 low)
  35. {
  36. vec3 highDifference = high - czm_encodedCameraPositionMCHigh;
  37. vec3 lowDifference = low - czm_encodedCameraPositionMCLow;
  38. return vec4(highDifference + lowDifference, 1.0);
  39. }