25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.2 KiB

  1. [vert.glsl]
  2. #version 130
  3. in vec2 in_position;
  4. uniform vec2 u_screen_res;
  5. uniform float u_step;
  6. out vec2 pass_pos;
  7. out vec2 pass_p[8];
  8. void main()
  9. {
  10. //JFA ALGO
  11. pass_pos = ((vec2(1.0) + in_position) * 0.5);
  12. float k = u_step;
  13. vec2 p2 = pass_pos;
  14. pass_p[0] = p2 + vec2(-k, -k);
  15. pass_p[1] = p2 + vec2( 0, -k);
  16. pass_p[2] = p2 + vec2( k, -k);
  17. pass_p[3] = p2 + vec2(-k, 0);
  18. pass_p[4] = p2 + vec2( k, 0);
  19. pass_p[5] = p2 + vec2(-k, k);
  20. pass_p[6] = p2 + vec2( 0, k);
  21. pass_p[7] = p2 + vec2( k, k);
  22. gl_Position = vec4(in_position, 0.0, 1.0);
  23. }
  24. [frag.glsl]
  25. #version 130
  26. #if defined GL_ES
  27. precision highp float;
  28. #endif
  29. in vec2 pass_pos;
  30. in vec2 pass_p[8];
  31. uniform sampler2D u_texture;
  32. void main(void)
  33. {
  34. vec4 src_color = texture2D(u_texture, pass_pos);
  35. vec4 neigh_color;
  36. for (int i = 0; i < 8; ++i)
  37. {
  38. neigh_color = texture2D(u_texture, pass_p[i]);
  39. if (neigh_color.z > 0.0 && src_color.z == 0.0)
  40. src_color = neigh_color;
  41. else if (neigh_color.z > 0.0 && src_color.z > 0.0 &&
  42. length(neigh_color.xy - pass_pos) < length(src_color.xy - pass_pos))
  43. src_color = neigh_color;
  44. }
  45. gl_FragColor = src_color;
  46. }