windowToEyeCoordinates.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "vec4 czm_windowToEyeCoordinates(vec4 fragmentCoordinate)\n\
  3. {\n\
  4. float x = 2.0 * (fragmentCoordinate.x - czm_viewport.x) / czm_viewport.z - 1.0;\n\
  5. float y = 2.0 * (fragmentCoordinate.y - czm_viewport.y) / czm_viewport.w - 1.0;\n\
  6. float z = (fragmentCoordinate.z - czm_viewportTransformation[3][2]) / czm_viewportTransformation[2][2];\n\
  7. vec4 q = vec4(x, y, z, 1.0);\n\
  8. q /= fragmentCoordinate.w;\n\
  9. if (!(czm_inverseProjection == mat4(0.0)))\n\
  10. {\n\
  11. q = czm_inverseProjection * q;\n\
  12. }\n\
  13. else\n\
  14. {\n\
  15. float top = czm_frustumPlanes.x;\n\
  16. float bottom = czm_frustumPlanes.y;\n\
  17. float left = czm_frustumPlanes.z;\n\
  18. float right = czm_frustumPlanes.w;\n\
  19. float near = czm_currentFrustum.x;\n\
  20. float far = czm_currentFrustum.y;\n\
  21. q.x = (q.x * (right - left) + left + right) * 0.5;\n\
  22. q.y = (q.y * (top - bottom) + bottom + top) * 0.5;\n\
  23. q.z = (q.z * (near - far) - near - far) * 0.5;\n\
  24. q.w = 1.0;\n\
  25. }\n\
  26. return q;\n\
  27. }\n\
  28. vec4 czm_windowToEyeCoordinates(vec2 fragmentCoordinateXY, float depthOrLogDepth)\n\
  29. {\n\
  30. #ifdef LOG_DEPTH\n\
  31. float near = czm_currentFrustum.x;\n\
  32. float far = czm_currentFrustum.y;\n\
  33. float unscaledDepth = pow(2.0, depthOrLogDepth * czm_log2FarPlusOne) - 1.0;\n\
  34. vec4 windowCoord = vec4(fragmentCoordinateXY, far * (1.0 - near / unscaledDepth) / (far - near), 1.0);\n\
  35. vec4 eyeCoordinate = czm_windowToEyeCoordinates(windowCoord);\n\
  36. eyeCoordinate.w = 1.0 / unscaledDepth;\n\
  37. #else\n\
  38. vec4 windowCoord = vec4(fragmentCoordinateXY, depthOrLogDepth, 1.0);\n\
  39. vec4 eyeCoordinate = czm_windowToEyeCoordinates(windowCoord);\n\
  40. #endif\n\
  41. return eyeCoordinate;\n\
  42. }\n\
  43. ";