PolylineArrowMaterial.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifdef GL_OES_standard_derivatives\n\
  21. float base = 1.0 - abs(fwidth(st.s)) * 10.0 * czm_pixelRatio;\n\
  22. #else\n\
  23. float base = 0.975; // 2.5% of the line will be the arrow head\n\
  24. #endif\n\
  25. \n\
  26. vec2 center = vec2(1.0, 0.5);\n\
  27. float ptOnUpperLine = getPointOnLine(vec2(base, 1.0), center, st.s);\n\
  28. float ptOnLowerLine = getPointOnLine(vec2(base, 0.0), center, st.s);\n\
  29. \n\
  30. float halfWidth = 0.15;\n\
  31. float s = step(0.5 - halfWidth, st.t);\n\
  32. s *= 1.0 - step(0.5 + halfWidth, st.t);\n\
  33. s *= 1.0 - step(base, st.s);\n\
  34. \n\
  35. float t = step(base, materialInput.st.s);\n\
  36. t *= 1.0 - step(ptOnUpperLine, st.t);\n\
  37. t *= step(ptOnLowerLine, st.t);\n\
  38. \n\
  39. // Find the distance from the closest separator (region between two colors)\n\
  40. float dist;\n\
  41. if (st.s < base)\n\
  42. {\n\
  43. float d1 = abs(st.t - (0.5 - halfWidth));\n\
  44. float d2 = abs(st.t - (0.5 + halfWidth));\n\
  45. dist = min(d1, d2);\n\
  46. }\n\
  47. else\n\
  48. {\n\
  49. float d1 = czm_infinity;\n\
  50. if (st.t < 0.5 - halfWidth && st.t > 0.5 + halfWidth)\n\
  51. {\n\
  52. d1 = abs(st.s - base);\n\
  53. }\n\
  54. float d2 = abs(st.t - ptOnUpperLine);\n\
  55. float d3 = abs(st.t - ptOnLowerLine);\n\
  56. dist = min(min(d1, d2), d3);\n\
  57. }\n\
  58. \n\
  59. vec4 outsideColor = vec4(0.0);\n\
  60. vec4 currentColor = mix(outsideColor, color, clamp(s + t, 0.0, 1.0));\n\
  61. vec4 outColor = czm_antialias(outsideColor, color, currentColor, dist);\n\
  62. \n\
  63. outColor = czm_gammaCorrect(outColor);\n\
  64. material.diffuse = outColor.rgb;\n\
  65. material.alpha = outColor.a;\n\
  66. return material;\n\
  67. }\n\
  68. ";