PolylineCommon.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "void clipLineSegmentToNearPlane(\n\
  3. vec3 p0,\n\
  4. vec3 p1,\n\
  5. out vec4 positionWC,\n\
  6. out bool clipped,\n\
  7. out bool culledByNearPlane)\n\
  8. {\n\
  9. culledByNearPlane = false;\n\
  10. clipped = false;\n\
  11. vec3 p1ToP0 = p1 - p0;\n\
  12. float magnitude = length(p1ToP0);\n\
  13. vec3 direction = normalize(p1ToP0);\n\
  14. float endPoint0Distance = -(czm_currentFrustum.x + p0.z);\n\
  15. float denominator = -direction.z;\n\
  16. if (endPoint0Distance < 0.0 && abs(denominator) < czm_epsilon7)\n\
  17. {\n\
  18. culledByNearPlane = true;\n\
  19. }\n\
  20. else if (endPoint0Distance < 0.0 && abs(denominator) > czm_epsilon7)\n\
  21. {\n\
  22. float t = (czm_currentFrustum.x + p0.z) / denominator;\n\
  23. if (t < 0.0 || t > magnitude)\n\
  24. {\n\
  25. culledByNearPlane = true;\n\
  26. }\n\
  27. else\n\
  28. {\n\
  29. p0 = p0 + t * direction;\n\
  30. clipped = true;\n\
  31. }\n\
  32. }\n\
  33. positionWC = czm_eyeToWindowCoordinates(vec4(p0, 1.0));\n\
  34. }\n\
  35. vec4 getPolylineWindowCoordinatesEC(vec4 positionEC, vec4 prevEC, vec4 nextEC, float expandDirection, float width, bool usePrevious, out float angle)\n\
  36. {\n\
  37. vec4 endPointWC, p0, p1;\n\
  38. bool culledByNearPlane, clipped;\n\
  39. #ifdef POLYLINE_DASH\n\
  40. vec4 positionWindow = czm_eyeToWindowCoordinates(positionEC);\n\
  41. vec4 previousWindow = czm_eyeToWindowCoordinates(prevEC);\n\
  42. vec4 nextWindow = czm_eyeToWindowCoordinates(nextEC);\n\
  43. vec2 lineDir;\n\
  44. if (usePrevious) {\n\
  45. lineDir = normalize(positionWindow.xy - previousWindow.xy);\n\
  46. }\n\
  47. else {\n\
  48. lineDir = normalize(nextWindow.xy - positionWindow.xy);\n\
  49. }\n\
  50. angle = atan(lineDir.x, lineDir.y) - 1.570796327;\n\
  51. angle = floor(angle / czm_piOverFour + 0.5) * czm_piOverFour;\n\
  52. #endif\n\
  53. clipLineSegmentToNearPlane(prevEC.xyz, positionEC.xyz, p0, clipped, culledByNearPlane);\n\
  54. clipLineSegmentToNearPlane(nextEC.xyz, positionEC.xyz, p1, clipped, culledByNearPlane);\n\
  55. clipLineSegmentToNearPlane(positionEC.xyz, usePrevious ? prevEC.xyz : nextEC.xyz, endPointWC, clipped, culledByNearPlane);\n\
  56. if (culledByNearPlane)\n\
  57. {\n\
  58. return vec4(0.0, 0.0, 0.0, 1.0);\n\
  59. }\n\
  60. vec2 prevWC = normalize(p0.xy - endPointWC.xy);\n\
  61. vec2 nextWC = normalize(p1.xy - endPointWC.xy);\n\
  62. float expandWidth = width * 0.5;\n\
  63. vec2 direction;\n\
  64. #ifdef CLIP_POLYLINE\n\
  65. if (clipped)\n\
  66. {\n\
  67. if (prevEC.z - positionEC.z < 0.0)\n\
  68. {\n\
  69. direction = vec2(prevWC.y, -prevWC.x);\n\
  70. }\n\
  71. else\n\
  72. {\n\
  73. direction = vec2(-prevWC.y, prevWC.x);\n\
  74. }\n\
  75. }\n\
  76. else\n\
  77. #endif\n\
  78. if (czm_equalsEpsilon(prevEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1) || czm_equalsEpsilon(prevWC, -nextWC, czm_epsilon1))\n\
  79. {\n\
  80. direction = vec2(-nextWC.y, nextWC.x);\n\
  81. }\n\
  82. else if (czm_equalsEpsilon(nextEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1))\n\
  83. {\n\
  84. direction = vec2(prevWC.y, -prevWC.x);\n\
  85. }\n\
  86. else\n\
  87. {\n\
  88. vec2 normal = vec2(-nextWC.y, nextWC.x);\n\
  89. direction = normalize((nextWC + prevWC) * 0.5);\n\
  90. if (dot(direction, normal) < 0.0)\n\
  91. {\n\
  92. direction = -direction;\n\
  93. }\n\
  94. float sinAngle = abs(direction.x * nextWC.y - direction.y * nextWC.x);\n\
  95. expandWidth = clamp(expandWidth / sinAngle, 0.0, width * 2.0);\n\
  96. }\n\
  97. vec2 offset = direction * expandDirection * expandWidth * czm_pixelRatio;\n\
  98. return vec4(endPointWC.xy + offset, -endPointWC.z, 1.0);\n\
  99. }\n\
  100. vec4 getPolylineWindowCoordinates(vec4 position, vec4 previous, vec4 next, float expandDirection, float width, bool usePrevious, out float angle)\n\
  101. {\n\
  102. vec4 positionEC = czm_modelViewRelativeToEye * position;\n\
  103. vec4 prevEC = czm_modelViewRelativeToEye * previous;\n\
  104. vec4 nextEC = czm_modelViewRelativeToEye * next;\n\
  105. return getPolylineWindowCoordinatesEC(positionEC, prevEC, nextEC, expandDirection, width, usePrevious, angle);\n\
  106. }\n\
  107. ";