PolylineArrowMaterial.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "#ifdef GL_OES_standard_derivatives\n\
  3. #extension GL_OES_standard_derivatives : enable\n\
  4. #endif\n\
  5. \n\
  6. uniform vec4 color;\n\
  7. \n\
  8. float getPointOnLine(vec2 p0, vec2 p1, float x)\n\
  9. {\n\
  10. float slope = (p0.y - p1.y) / (p0.x - p1.x);\n\
  11. return slope * (x - p0.x) + p0.y;\n\
  12. }\n\
  13. \n\
  14. czm_material czm_getMaterial(czm_materialInput materialInput)\n\
  15. {\n\
  16. czm_material material = czm_getDefaultMaterial(materialInput);\n\
  17. \n\
  18. vec2 st = materialInput.st;\n\
  19. \n\
  20. #if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\n\
  21. float base = 1.0 - abs(fwidth(st.s)) * 10.0 * czm_pixelRatio;\n\
  22. #else\n\
  23. // If no derivatives available (IE 10?), 2.5% of the line will be the arrow head\n\
  24. float base = 0.975;\n\
  25. #endif\n\
  26. \n\
  27. vec2 center = vec2(1.0, 0.5);\n\
  28. float ptOnUpperLine = getPointOnLine(vec2(base, 1.0), center, st.s);\n\
  29. float ptOnLowerLine = getPointOnLine(vec2(base, 0.0), center, st.s);\n\
  30. \n\
  31. float halfWidth = 0.15;\n\
  32. float s = step(0.5 - halfWidth, st.t);\n\
  33. s *= 1.0 - step(0.5 + halfWidth, st.t);\n\
  34. s *= 1.0 - step(base, st.s);\n\
  35. \n\
  36. float t = step(base, materialInput.st.s);\n\
  37. t *= 1.0 - step(ptOnUpperLine, st.t);\n\
  38. t *= step(ptOnLowerLine, st.t);\n\
  39. \n\
  40. // Find the distance from the closest separator (region between two colors)\n\
  41. float dist;\n\
  42. if (st.s < base)\n\
  43. {\n\
  44. float d1 = abs(st.t - (0.5 - halfWidth));\n\
  45. float d2 = abs(st.t - (0.5 + halfWidth));\n\
  46. dist = min(d1, d2);\n\
  47. }\n\
  48. else\n\
  49. {\n\
  50. float d1 = czm_infinity;\n\
  51. if (st.t < 0.5 - halfWidth && st.t > 0.5 + halfWidth)\n\
  52. {\n\
  53. d1 = abs(st.s - base);\n\
  54. }\n\
  55. float d2 = abs(st.t - ptOnUpperLine);\n\
  56. float d3 = abs(st.t - ptOnLowerLine);\n\
  57. dist = min(min(d1, d2), d3);\n\
  58. }\n\
  59. \n\
  60. vec4 outsideColor = vec4(0.0);\n\
  61. vec4 currentColor = mix(outsideColor, color, clamp(s + t, 0.0, 1.0));\n\
  62. vec4 outColor = czm_antialias(outsideColor, color, currentColor, dist);\n\
  63. \n\
  64. outColor = czm_gammaCorrect(outColor);\n\
  65. material.diffuse = outColor.rgb;\n\
  66. material.alpha = outColor.a;\n\
  67. return material;\n\
  68. }\n\
  69. ";