You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

front_camera_sprite.lolfx 3.0 KiB

пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. [vert.glsl]
  2. #version 120
  3. attribute vec3 in_Position;
  4. attribute vec4 in_Color;
  5. attribute vec4 in_TexCoord;
  6. uniform mat4 in_model_view;
  7. uniform mat3 in_normal_mat;
  8. uniform mat4 in_proj;
  9. uniform float in_sprite_orientation;
  10. varying vec4 pass_texcoord;
  11. varying vec4 pass_color;
  12. void main(void)
  13. {
  14. vec4 vertex = in_model_view * vec4(in_Position - vec3(0.0,0.5,0.0), 1.0);
  15. vec3 v_offset = vec3(1.0 * in_TexCoord.z, -1.0 * in_TexCoord.w, 0.0);
  16. float sinX = sin(in_sprite_orientation);
  17. float cosX = cos(in_sprite_orientation);
  18. float sinY = sinX;
  19. mat2 rotationMatrix = mat2(cosX, -sinX, sinY, cosX);
  20. v_offset.xy = rotationMatrix * v_offset.xy;
  21. //Billboard calculations
  22. vertex.xyz += v_offset;
  23. //pass datas
  24. pass_texcoord = in_TexCoord;
  25. pass_color = in_Color;
  26. gl_Position = in_proj * vertex;
  27. }
  28. [frag.glsl]
  29. #version 120
  30. #if defined GL_ES
  31. precision highp float;
  32. #endif
  33. uniform sampler2D in_texture;
  34. uniform float in_sprite_flip;
  35. varying vec4 pass_texcoord;
  36. varying vec4 pass_color;
  37. const float cos_45 = 0.70710678118;
  38. const float PI = 3.14159265358979323846264;
  39. vec3 rgb2hsv(vec3 c)
  40. {
  41. vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
  42. vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
  43. vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
  44. float d = q.x - min(q.w, q.y);
  45. float e = 1.0e-10;
  46. return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
  47. }
  48. vec3 hsv2rgb(vec3 c)
  49. {
  50. vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
  51. vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
  52. return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
  53. }
  54. const int sample_nb = 2;
  55. void main(void)
  56. {
  57. vec2 texcoord = pass_texcoord.xy - vec2(pass_texcoord.z * in_sprite_flip, 0.0);
  58. vec4 color = texture2D(in_texture, texcoord) * pass_color;
  59. //need 130 : ivec2 tex_size = textureSize(in_texture, 0);
  60. if (color.a < 0.9)
  61. {
  62. bool break_loop = false;
  63. for (int x = -sample_nb; x <= sample_nb; x++)
  64. {
  65. for (int y = -sample_nb; y <= sample_nb; y++)
  66. {
  67. if (x != 0 && y != 0)
  68. {
  69. vec2 new_tc = clamp(texcoord + (vec2(x, y) / 1024.0), vec2(0.0), vec2(1.0));
  70. vec4 new_col = texture2D(in_texture, new_tc);
  71. //need 130 : vec4 new_col = texelFetch(in_texture, ivec2(tex_size * texcoord) + ivec2(x, y), 0);
  72. if (new_col.a > 0.9)
  73. {
  74. color = vec4(0.0, 0.0, 0.0, 1.0);
  75. break_loop = true;
  76. //x = sample_nb + 1;
  77. //y = sample_nb + 1;
  78. }
  79. if (break_loop)
  80. break;
  81. }
  82. }
  83. if (break_loop)
  84. break;
  85. }
  86. }
  87. if (color.a < 0.01)
  88. discard;
  89. vec3 hsv = rgb2hsv(color.rgb);
  90. hsv.x = fract(hsv.x + rgb2hsv(pass_color.rgb).x);
  91. gl_FragColor = vec4(hsv2rgb(hsv), color.a);
  92. }