PolylineArrowMaterial.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. uniform vec4 color;\n\
  6. varying float v_width;\n\
  7. float getPointOnLine(vec2 p0, vec2 p1, float x)\n\
  8. {\n\
  9. float slope = (p0.y - p1.y) / (p0.x - p1.x);\n\
  10. return slope * (x - p0.x) + p0.y;\n\
  11. }\n\
  12. czm_material czm_getMaterial(czm_materialInput materialInput)\n\
  13. {\n\
  14. czm_material material = czm_getDefaultMaterial(materialInput);\n\
  15. vec2 st = materialInput.st;\n\
  16. #ifdef GL_OES_standard_derivatives\n\
  17. float base = 1.0 - abs(fwidth(st.s)) * 10.0 * czm_pixelRatio;\n\
  18. #else\n\
  19. float base = 0.975;\n\
  20. #endif\n\
  21. vec2 center = vec2(1.0, 0.5);\n\
  22. float ptOnUpperLine = getPointOnLine(vec2(base, 1.0), center, st.s);\n\
  23. float ptOnLowerLine = getPointOnLine(vec2(base, 0.0), center, st.s);\n\
  24. float halfWidth = 0.15;\n\
  25. float s = step(0.5 - halfWidth, st.t);\n\
  26. s *= 1.0 - step(0.5 + halfWidth, st.t);\n\
  27. s *= 1.0 - step(base, st.s);\n\
  28. float t = step(base, materialInput.st.s);\n\
  29. t *= 1.0 - step(ptOnUpperLine, st.t);\n\
  30. t *= step(ptOnLowerLine, st.t);\n\
  31. float dist;\n\
  32. if (st.s < base)\n\
  33. {\n\
  34. float d1 = abs(st.t - (0.5 - halfWidth));\n\
  35. float d2 = abs(st.t - (0.5 + halfWidth));\n\
  36. dist = min(d1, d2);\n\
  37. }\n\
  38. else\n\
  39. {\n\
  40. float d1 = czm_infinity;\n\
  41. if (st.t < 0.5 - halfWidth && st.t > 0.5 + halfWidth)\n\
  42. {\n\
  43. d1 = abs(st.s - base);\n\
  44. }\n\
  45. float d2 = abs(st.t - ptOnUpperLine);\n\
  46. float d3 = abs(st.t - ptOnLowerLine);\n\
  47. dist = min(min(d1, d2), d3);\n\
  48. }\n\
  49. vec4 outsideColor = vec4(0.0);\n\
  50. vec4 currentColor = mix(outsideColor, color, clamp(s + t, 0.0, 1.0));\n\
  51. vec4 outColor = czm_antialias(outsideColor, color, currentColor, dist);\n\
  52. outColor = czm_gammaCorrect(outColor);\n\
  53. material.diffuse = outColor.rgb;\n\
  54. material.alpha = outColor.a;\n\
  55. return material;\n\
  56. }\n\
  57. ";