PolylineDashMaterial.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "uniform vec4 color;\n\
  3. uniform vec4 gapColor;\n\
  4. uniform float dashLength;\n\
  5. uniform float dashPattern;\n\
  6. varying float v_polylineAngle;\n\
  7. \n\
  8. const float maskLength = 16.0;\n\
  9. \n\
  10. mat2 rotate(float rad) {\n\
  11. float c = cos(rad);\n\
  12. float s = sin(rad);\n\
  13. return mat2(\n\
  14. c, s,\n\
  15. -s, c\n\
  16. );\n\
  17. }\n\
  18. \n\
  19. czm_material czm_getMaterial(czm_materialInput materialInput)\n\
  20. {\n\
  21. czm_material material = czm_getDefaultMaterial(materialInput);\n\
  22. \n\
  23. vec2 pos = rotate(v_polylineAngle) * gl_FragCoord.xy;\n\
  24. \n\
  25. // Get the relative position within the dash from 0 to 1\n\
  26. float dashPosition = fract(pos.x / (dashLength * czm_pixelRatio));\n\
  27. // Figure out the mask index.\n\
  28. float maskIndex = floor(dashPosition * maskLength);\n\
  29. // Test the bit mask.\n\
  30. float maskTest = floor(dashPattern / pow(2.0, maskIndex));\n\
  31. vec4 fragColor = (mod(maskTest, 2.0) < 1.0) ? gapColor : color;\n\
  32. if (fragColor.a < 0.005) { // matches 0/255 and 1/255\n\
  33. discard;\n\
  34. }\n\
  35. \n\
  36. fragColor = czm_gammaCorrect(fragColor);\n\
  37. material.emission = fragColor.rgb;\n\
  38. material.alpha = fragColor.a;\n\
  39. return material;\n\
  40. }\n\
  41. ";