GridMaterial.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. uniform float cellAlpha;\n\
  7. uniform vec2 lineCount;\n\
  8. uniform vec2 lineThickness;\n\
  9. uniform vec2 lineOffset;\n\
  10. czm_material czm_getMaterial(czm_materialInput materialInput)\n\
  11. {\n\
  12. czm_material material = czm_getDefaultMaterial(materialInput);\n\
  13. vec2 st = materialInput.st;\n\
  14. float scaledWidth = fract(lineCount.s * st.s - lineOffset.s);\n\
  15. scaledWidth = abs(scaledWidth - floor(scaledWidth + 0.5));\n\
  16. float scaledHeight = fract(lineCount.t * st.t - lineOffset.t);\n\
  17. scaledHeight = abs(scaledHeight - floor(scaledHeight + 0.5));\n\
  18. float value;\n\
  19. #ifdef GL_OES_standard_derivatives\n\
  20. const float fuzz = 1.2;\n\
  21. vec2 thickness = (lineThickness * czm_pixelRatio) - 1.0;\n\
  22. vec2 dx = abs(dFdx(st));\n\
  23. vec2 dy = abs(dFdy(st));\n\
  24. vec2 dF = vec2(max(dx.s, dy.s), max(dx.t, dy.t)) * lineCount;\n\
  25. value = min(\n\
  26. smoothstep(dF.s * thickness.s, dF.s * (fuzz + thickness.s), scaledWidth),\n\
  27. smoothstep(dF.t * thickness.t, dF.t * (fuzz + thickness.t), scaledHeight));\n\
  28. #else\n\
  29. const float fuzz = 0.05;\n\
  30. vec2 range = 0.5 - (lineThickness * 0.05);\n\
  31. value = min(\n\
  32. 1.0 - smoothstep(range.s, range.s + fuzz, scaledWidth),\n\
  33. 1.0 - smoothstep(range.t, range.t + fuzz, scaledHeight));\n\
  34. #endif\n\
  35. float dRim = 1.0 - abs(dot(materialInput.normalEC, normalize(materialInput.positionToEyeEC)));\n\
  36. float sRim = smoothstep(0.8, 1.0, dRim);\n\
  37. value *= (1.0 - sRim);\n\
  38. vec4 halfColor;\n\
  39. halfColor.rgb = color.rgb * 0.5;\n\
  40. halfColor.a = color.a * (1.0 - ((1.0 - cellAlpha) * value));\n\
  41. halfColor = czm_gammaCorrect(halfColor);\n\
  42. material.diffuse = halfColor.rgb;\n\
  43. material.emission = halfColor.rgb;\n\
  44. material.alpha = halfColor.a;\n\
  45. return material;\n\
  46. }\n\
  47. ";