EdgeDetection.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "uniform sampler2D depthTexture;\n\
  3. uniform float length;\n\
  4. uniform vec4 color;\n\
  5. varying vec2 v_textureCoordinates;\n\
  6. void main(void)\n\
  7. {\n\
  8. float directions[3];\n\
  9. directions[0] = -1.0;\n\
  10. directions[1] = 0.0;\n\
  11. directions[2] = 1.0;\n\
  12. float scalars[3];\n\
  13. scalars[0] = 3.0;\n\
  14. scalars[1] = 10.0;\n\
  15. scalars[2] = 3.0;\n\
  16. float padx = czm_pixelRatio / czm_viewport.z;\n\
  17. float pady = czm_pixelRatio / czm_viewport.w;\n\
  18. #ifdef CZM_SELECTED_FEATURE\n\
  19. bool selected = false;\n\
  20. for (int i = 0; i < 3; ++i)\n\
  21. {\n\
  22. float dir = directions[i];\n\
  23. selected = selected || czm_selected(vec2(-padx, dir * pady));\n\
  24. selected = selected || czm_selected(vec2(padx, dir * pady));\n\
  25. selected = selected || czm_selected(vec2(dir * padx, -pady));\n\
  26. selected = selected || czm_selected(vec2(dir * padx, pady));\n\
  27. if (selected)\n\
  28. {\n\
  29. break;\n\
  30. }\n\
  31. }\n\
  32. if (!selected)\n\
  33. {\n\
  34. gl_FragColor = vec4(color.rgb, 0.0);\n\
  35. return;\n\
  36. }\n\
  37. #endif\n\
  38. float horizEdge = 0.0;\n\
  39. float vertEdge = 0.0;\n\
  40. for (int i = 0; i < 3; ++i)\n\
  41. {\n\
  42. float dir = directions[i];\n\
  43. float scale = scalars[i];\n\
  44. horizEdge -= texture2D(depthTexture, v_textureCoordinates + vec2(-padx, dir * pady)).x * scale;\n\
  45. horizEdge += texture2D(depthTexture, v_textureCoordinates + vec2(padx, dir * pady)).x * scale;\n\
  46. vertEdge -= texture2D(depthTexture, v_textureCoordinates + vec2(dir * padx, -pady)).x * scale;\n\
  47. vertEdge += texture2D(depthTexture, v_textureCoordinates + vec2(dir * padx, pady)).x * scale;\n\
  48. }\n\
  49. float len = sqrt(horizEdge * horizEdge + vertEdge * vertEdge);\n\
  50. gl_FragColor = vec4(color.rgb, len > length ? color.a : 0.0);\n\
  51. }\n\
  52. ";