GridMaterial.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //This file is automatically rebuilt by the Cesium build process.
  2. /*global define*/
  3. define(function() {
  4. "use strict";
  5. return "#ifdef GL_OES_standard_derivatives\n\
  6. #extension GL_OES_standard_derivatives : enable\n\
  7. #endif\n\
  8. \n\
  9. uniform vec4 color;\n\
  10. uniform float cellAlpha;\n\
  11. uniform vec2 lineCount;\n\
  12. uniform vec2 lineThickness;\n\
  13. uniform vec2 lineOffset;\n\
  14. \n\
  15. czm_material czm_getMaterial(czm_materialInput materialInput)\n\
  16. {\n\
  17. czm_material material = czm_getDefaultMaterial(materialInput);\n\
  18. \n\
  19. vec2 st = materialInput.st;\n\
  20. \n\
  21. float scaledWidth = fract(lineCount.s * st.s - lineOffset.s);\n\
  22. scaledWidth = abs(scaledWidth - floor(scaledWidth + 0.5));\n\
  23. float scaledHeight = fract(lineCount.t * st.t - lineOffset.t);\n\
  24. scaledHeight = abs(scaledHeight - floor(scaledHeight + 0.5));\n\
  25. \n\
  26. float value;\n\
  27. #ifdef GL_OES_standard_derivatives\n\
  28. // Fuzz Factor - Controls blurriness of lines\n\
  29. const float fuzz = 1.2;\n\
  30. vec2 thickness = (lineThickness * czm_resolutionScale) - 1.0;\n\
  31. \n\
  32. // From \"3D Engine Design for Virtual Globes\" by Cozzi and Ring, Listing 4.13.\n\
  33. vec2 dx = abs(dFdx(st));\n\
  34. vec2 dy = abs(dFdy(st));\n\
  35. vec2 dF = vec2(max(dx.s, dy.s), max(dx.t, dy.t)) * lineCount;\n\
  36. value = min(\n\
  37. smoothstep(dF.s * thickness.s, dF.s * (fuzz + thickness.s), scaledWidth),\n\
  38. smoothstep(dF.t * thickness.t, dF.t * (fuzz + thickness.t), scaledHeight));\n\
  39. #else\n\
  40. // Fuzz Factor - Controls blurriness of lines\n\
  41. const float fuzz = 0.05;\n\
  42. \n\
  43. vec2 range = 0.5 - (lineThickness * 0.05);\n\
  44. value = min(\n\
  45. 1.0 - smoothstep(range.s, range.s + fuzz, scaledWidth),\n\
  46. 1.0 - smoothstep(range.t, range.t + fuzz, scaledHeight));\n\
  47. #endif\n\
  48. \n\
  49. // Edges taken from RimLightingMaterial.glsl\n\
  50. // See http://www.fundza.com/rman_shaders/surface/fake_rim/fake_rim1.html\n\
  51. float dRim = 1.0 - abs(dot(materialInput.normalEC, normalize(materialInput.positionToEyeEC)));\n\
  52. float sRim = smoothstep(0.8, 1.0, dRim);\n\
  53. value *= (1.0 - sRim);\n\
  54. \n\
  55. vec3 halfColor = color.rgb * 0.5;\n\
  56. material.diffuse = halfColor;\n\
  57. material.emission = halfColor;\n\
  58. material.alpha = color.a * (1.0 - ((1.0 - cellAlpha) * value));\n\
  59. \n\
  60. return material;\n\
  61. }\n\
  62. ";
  63. });