blur.frag 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2020, Inria
  3. * GRAPHDECO research group, https://team.inria.fr/graphdeco
  4. * All rights reserved.
  5. *
  6. * This software is free for non-commercial, research and evaluation use
  7. * under the terms of the LICENSE.md file.
  8. *
  9. * For inquiries contact sibr@inria.fr and/or George.Drettakis@inria.fr
  10. */
  11. #version 420
  12. layout(location = 0) out vec4 out_color;
  13. uniform sampler2D image;
  14. uniform vec2 in_image_size;
  15. in vec2 tex_coord;
  16. void main(void) {
  17. vec4 color = texture(image, tex_coord);
  18. const float blurPixelStep = 1.25;
  19. const float blurSizeX = (1.0 / in_image_size.x)*blurPixelStep;
  20. const float blurSizeY = (1.0 / in_image_size.y)*blurPixelStep;
  21. const int nbVisit = 4;
  22. ivec2 visit[nbVisit] = ivec2 [](
  23. // cross
  24. // ivec2( 0, -1),
  25. // ivec2( 0, 1),
  26. // ivec2( 1, 0),
  27. // ivec2(-1, 0)
  28. // corner (better, detect more edge)
  29. ivec2(-1, -1),
  30. ivec2(-1, 1),
  31. ivec2( 1, -1),
  32. ivec2( 1, 1)
  33. );
  34. vec4 avcolor;
  35. vec4 bgColor = vec4(color.xyz, 0.0);
  36. for (int i = 0; i < nbVisit; ++i)
  37. {
  38. vec4 col = texture( image,
  39. vec2(tex_coord.x + visit[i].x* blurSizeX, tex_coord.y + visit[i].y * blurSizeY) );
  40. bgColor = (col.a > bgColor.a)? col : bgColor;
  41. avcolor += col;
  42. }
  43. avcolor /= float(nbVisit);
  44. float dColor = abs(avcolor.a - color.a);//length(avcolor - color);
  45. const float maxDColor = 0.015f;
  46. float mixFactor = 1.0 - min(1.0, dColor/maxDColor);
  47. vec4 correction = bgColor;//mix(bgColor, avcolor, mixFactor);
  48. // [USEFUL FOR DEBUGGING]: show detected edge
  49. //out_color = (dColor > maxDColor)? vec4(1.0, 0.0, 1.0, 1.0) : color;
  50. out_color = (dColor > maxDColor)? mix(correction, color, 0.5) : color;
  51. // [USEFUL FOR DEBUGGING]: change nothing
  52. //out_color = color;
  53. }