46 lines
1.7 KiB
GLSL
46 lines
1.7 KiB
GLSL
/**
|
|
* Translates a position (or any <code>vec3</code>) that was encoded with {@link EncodedCartesian3},
|
|
* and then provided to the shader as separate <code>high</code> and <code>low</code> bits to
|
|
* be relative to the eye. As shown in the example, the position can then be transformed in eye
|
|
* or clip coordinates using {@link czm_modelViewRelativeToEye} or {@link czm_modelViewProjectionRelativeToEye},
|
|
* respectively.
|
|
* <p>
|
|
* This technique, called GPU RTE, eliminates jittering artifacts when using large coordinates as
|
|
* described in {@link http://help.agi.com/AGIComponents/html/BlogPrecisionsPrecisions.htm|Precisions, Precisions}.
|
|
* </p>
|
|
*
|
|
* @name czm_translateRelativeToEye
|
|
* @glslFunction
|
|
*
|
|
* @param {vec3} high The position's high bits.
|
|
* @param {vec3} low The position's low bits.
|
|
* @returns {vec3} The position translated to be relative to the camera's position.
|
|
*
|
|
* @example
|
|
* in vec3 positionHigh;
|
|
* in vec3 positionLow;
|
|
*
|
|
* void main()
|
|
* {
|
|
* vec4 p = czm_translateRelativeToEye(positionHigh, positionLow);
|
|
* gl_Position = czm_modelViewProjectionRelativeToEye * p;
|
|
* }
|
|
*
|
|
* @see czm_modelViewRelativeToEye
|
|
* @see czm_modelViewProjectionRelativeToEye
|
|
* @see czm_computePosition
|
|
* @see EncodedCartesian3
|
|
*/
|
|
vec4 czm_translateRelativeToEye(vec3 high, vec3 low)
|
|
{
|
|
vec3 highDifference = high - czm_encodedCameraPositionMCHigh;
|
|
// This check handles the case when NaN values have gotten into `highDifference`.
|
|
// Such a thing could happen on devices running iOS.
|
|
if (length(highDifference) == 0.0) {
|
|
highDifference = vec3(0);
|
|
}
|
|
vec3 lowDifference = low - czm_encodedCameraPositionMCLow;
|
|
|
|
return vec4(highDifference + lowDifference, 1.0);
|
|
}
|