nearFarScalar.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "/**\n\
  3. * Computes a value that scales with distance. The scaling is clamped at the near and\n\
  4. * far distances, and does not extrapolate. This function works with the\n\
  5. * {@link NearFarScalar} JavaScript class.\n\
  6. *\n\
  7. * @name czm_nearFarScalar\n\
  8. * @glslFunction\n\
  9. *\n\
  10. * @param {vec4} nearFarScalar A vector with 4 components: Near distance (x), Near value (y), Far distance (z), Far value (w).\n\
  11. * @param {float} cameraDistSq The square of the current distance from the camera.\n\
  12. *\n\
  13. * @returns {float} The value at this distance.\n\
  14. */\n\
  15. float czm_nearFarScalar(vec4 nearFarScalar, float cameraDistSq)\n\
  16. {\n\
  17. float valueAtMin = nearFarScalar.y;\n\
  18. float valueAtMax = nearFarScalar.w;\n\
  19. float nearDistanceSq = nearFarScalar.x * nearFarScalar.x;\n\
  20. float farDistanceSq = nearFarScalar.z * nearFarScalar.z;\n\
  21. \n\
  22. float t = (cameraDistSq - nearDistanceSq) / (farDistanceSq - nearDistanceSq);\n\
  23. \n\
  24. t = pow(clamp(t, 0.0, 1.0), 0.2);\n\
  25. \n\
  26. return mix(valueAtMin, valueAtMax, t);\n\
  27. }\n\
  28. ";