antialias.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "/**\n\
  3. * Procedural anti-aliasing by blurring two colors that meet at a sharp edge.\n\
  4. *\n\
  5. * @name czm_antialias\n\
  6. * @glslFunction\n\
  7. *\n\
  8. * @param {vec4} color1 The color on one side of the edge.\n\
  9. * @param {vec4} color2 The color on the other side of the edge.\n\
  10. * @param {vec4} currentcolor The current color, either <code>color1</code> or <code>color2</code>.\n\
  11. * @param {float} dist The distance to the edge in texture coordinates.\n\
  12. * @param {float} [fuzzFactor=0.1] Controls the blurriness between the two colors.\n\
  13. * @returns {vec4} The anti-aliased color.\n\
  14. *\n\
  15. * @example\n\
  16. * // GLSL declarations\n\
  17. * vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor);\n\
  18. * vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist);\n\
  19. *\n\
  20. * // get the color for a material that has a sharp edge at the line y = 0.5 in texture space\n\
  21. * float dist = abs(textureCoordinates.t - 0.5);\n\
  22. * vec4 currentColor = mix(bottomColor, topColor, step(0.5, textureCoordinates.t));\n\
  23. * vec4 color = czm_antialias(bottomColor, topColor, currentColor, dist, 0.1);\n\
  24. */\n\
  25. vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist, float fuzzFactor)\n\
  26. {\n\
  27. float val1 = clamp(dist / fuzzFactor, 0.0, 1.0);\n\
  28. float val2 = clamp((dist - 0.5) / fuzzFactor, 0.0, 1.0);\n\
  29. val1 = val1 * (1.0 - val2);\n\
  30. val1 = val1 * val1 * (3.0 - (2.0 * val1));\n\
  31. val1 = pow(val1, 0.5); //makes the transition nicer\n\
  32. \n\
  33. vec4 midColor = (color1 + color2) * 0.5;\n\
  34. return mix(midColor, currentColor, val1);\n\
  35. }\n\
  36. \n\
  37. vec4 czm_antialias(vec4 color1, vec4 color2, vec4 currentColor, float dist)\n\
  38. {\n\
  39. return czm_antialias(color1, color2, currentColor, dist, 0.1);\n\
  40. }\n\
  41. ";