metersPerPixel.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "/**\n\
  3. * Computes the size of a pixel in meters at a distance from the eye.\n\
  4. * <p>\n\
  5. * Use this version when passing in a custom pixel ratio. For example, passing in 1.0 will return meters per native device pixel.\n\
  6. * </p>\n\
  7. * @name czm_metersPerPixel\n\
  8. * @glslFunction\n\
  9. *\n\
  10. * @param {vec3} positionEC The position to get the meters per pixel in eye coordinates.\n\
  11. * @param {float} pixelRatio The scaling factor from pixel space to coordinate space\n\
  12. *\n\
  13. * @returns {float} The meters per pixel at positionEC.\n\
  14. */\n\
  15. float czm_metersPerPixel(vec4 positionEC, float pixelRatio)\n\
  16. {\n\
  17. float width = czm_viewport.z;\n\
  18. float height = czm_viewport.w;\n\
  19. float pixelWidth;\n\
  20. float pixelHeight;\n\
  21. \n\
  22. float top = czm_frustumPlanes.x;\n\
  23. float bottom = czm_frustumPlanes.y;\n\
  24. float left = czm_frustumPlanes.z;\n\
  25. float right = czm_frustumPlanes.w;\n\
  26. \n\
  27. if (czm_sceneMode == czm_sceneMode2D || czm_orthographicIn3D == 1.0)\n\
  28. {\n\
  29. float frustumWidth = right - left;\n\
  30. float frustumHeight = top - bottom;\n\
  31. pixelWidth = frustumWidth / width;\n\
  32. pixelHeight = frustumHeight / height;\n\
  33. }\n\
  34. else\n\
  35. {\n\
  36. float distanceToPixel = -positionEC.z;\n\
  37. float inverseNear = 1.0 / czm_currentFrustum.x;\n\
  38. float tanTheta = top * inverseNear;\n\
  39. pixelHeight = 2.0 * distanceToPixel * tanTheta / height;\n\
  40. tanTheta = right * inverseNear;\n\
  41. pixelWidth = 2.0 * distanceToPixel * tanTheta / width;\n\
  42. }\n\
  43. \n\
  44. return max(pixelWidth, pixelHeight) * pixelRatio;\n\
  45. }\n\
  46. \n\
  47. /**\n\
  48. * Computes the size of a pixel in meters at a distance from the eye.\n\
  49. * <p>\n\
  50. * Use this version when scaling by pixel ratio.\n\
  51. * </p>\n\
  52. * @name czm_metersPerPixel\n\
  53. * @glslFunction\n\
  54. *\n\
  55. * @param {vec3} positionEC The position to get the meters per pixel in eye coordinates.\n\
  56. *\n\
  57. * @returns {float} The meters per pixel at positionEC.\n\
  58. */\n\
  59. float czm_metersPerPixel(vec4 positionEC)\n\
  60. {\n\
  61. return czm_metersPerPixel(positionEC, czm_pixelRatio);\n\
  62. }\n\
  63. ";