PolylineArrowMaterial.js 2.1 KB

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