12_voronoi.lolfx 2.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //-----------------------------------------------------------------------------
  2. //GLSL
  3. //-----------------------------------------------------------------------------
  4. [vert.glsl]
  5. #version 120
  6. attribute vec2 in_position;
  7. uniform vec2 in_screen_res;
  8. uniform float in_step;
  9. varying vec2 pass_pos;
  10. varying vec2 pass_p[8];
  11. void main()
  12. {
  13. //JFA ALGO
  14. pass_pos = ((vec2(1.0) + in_position) * 0.5);
  15. float k = in_step;
  16. vec2 p2 = pass_pos;
  17. pass_p[0] = p2 + vec2(-k, -k);
  18. pass_p[1] = p2 + vec2( 0, -k);
  19. pass_p[2] = p2 + vec2( k, -k);
  20. pass_p[3] = p2 + vec2(-k, 0);
  21. pass_p[4] = p2 + vec2( k, 0);
  22. pass_p[5] = p2 + vec2(-k, k);
  23. pass_p[6] = p2 + vec2( 0, k);
  24. pass_p[7] = p2 + vec2( k, k);
  25. gl_Position = vec4(in_position, 0.0, 1.0);
  26. }
  27. [frag.glsl]
  28. #version 120
  29. #if defined GL_ES
  30. precision highp float;
  31. #endif
  32. uniform sampler2D in_texture;
  33. varying vec2 pass_pos;
  34. varying vec2 pass_p[8];
  35. void main(void)
  36. {
  37. vec4 src_color = texture2D(in_texture, pass_pos);
  38. vec4 neigh_color;
  39. for (int i = 0; i < 8; ++i)
  40. {
  41. neigh_color = texture2D(in_texture, pass_p[i]);
  42. if (neigh_color.z > 0.0 && src_color.z == 0.0)
  43. src_color = neigh_color;
  44. else if (neigh_color.z > 0.0 && src_color.z > 0.0 &&
  45. length(neigh_color.xy - pass_pos) < length(src_color.xy - pass_pos))
  46. src_color = neigh_color;
  47. }
  48. gl_FragColor = src_color;
  49. }
  50. //-----------------------------------------------------------------------------
  51. //HLSL
  52. //-----------------------------------------------------------------------------
  53. [vert.hlsl]
  54. void main(float2 in_Position : POSITION,
  55. out float2 pass_Position : TEXCOORD0,
  56. out float4 out_Position : POSITION)
  57. {
  58. pass_Position = in_Position;
  59. out_Position = float4(in_Position, 0.0, 1.0);
  60. }
  61. [frag.hlsl]
  62. void main(in float2 pass_Position : TEXCOORD0,
  63. uniform sampler2D in_Texture,
  64. uniform float in_Flag,
  65. uniform float3 in_Point,
  66. uniform float3 in_Color,
  67. out float4 out_FragColor : COLOR)
  68. {
  69. out_FragColor = float4(0.0);
  70. }