PolylineDashMaterial.glsl 1.1 KB

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