metersPerPixel.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "float czm_metersPerPixel(vec4 positionEC, float pixelRatio)\n\
  3. {\n\
  4. float width = czm_viewport.z;\n\
  5. float height = czm_viewport.w;\n\
  6. float pixelWidth;\n\
  7. float pixelHeight;\n\
  8. float top = czm_frustumPlanes.x;\n\
  9. float bottom = czm_frustumPlanes.y;\n\
  10. float left = czm_frustumPlanes.z;\n\
  11. float right = czm_frustumPlanes.w;\n\
  12. if (czm_sceneMode == czm_sceneMode2D || czm_orthographicIn3D == 1.0)\n\
  13. {\n\
  14. float frustumWidth = right - left;\n\
  15. float frustumHeight = top - bottom;\n\
  16. pixelWidth = frustumWidth / width;\n\
  17. pixelHeight = frustumHeight / height;\n\
  18. }\n\
  19. else\n\
  20. {\n\
  21. float distanceToPixel = -positionEC.z;\n\
  22. float inverseNear = 1.0 / czm_currentFrustum.x;\n\
  23. float tanTheta = top * inverseNear;\n\
  24. pixelHeight = 2.0 * distanceToPixel * tanTheta / height;\n\
  25. tanTheta = right * inverseNear;\n\
  26. pixelWidth = 2.0 * distanceToPixel * tanTheta / width;\n\
  27. }\n\
  28. return max(pixelWidth, pixelHeight) * pixelRatio;\n\
  29. }\n\
  30. float czm_metersPerPixel(vec4 positionEC)\n\
  31. {\n\
  32. return czm_metersPerPixel(positionEC, czm_pixelRatio);\n\
  33. }\n\
  34. ";