Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

front_camera_sprite.lolfx 2.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. [vert.glsl]
  2. #version 120
  3. attribute vec3 in_vertex;
  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_vertex - 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. void main(void)
  55. {
  56. vec2 texcoord = pass_texcoord.xy - vec2(pass_texcoord.z * in_sprite_flip, 0.0);
  57. vec4 color = texture2D(in_texture, texcoord) * pass_color;
  58. //need 130 : ivec2 tex_size = textureSize(in_texture, 0);
  59. int sample_nb = 2;
  60. if (color.a < 0.9)
  61. {
  62. for (int x = -sample_nb; x <= sample_nb; x++)
  63. {
  64. for (int y = -sample_nb; y <= sample_nb; y++)
  65. {
  66. if (x != 0 && y != 0)
  67. {
  68. vec2 new_tc = clamp(texcoord + (vec2(x, y) / 1024.0), vec2(0.0), vec2(1.0));
  69. vec4 new_col = texture2D(in_texture, new_tc);
  70. //need 130 : vec4 new_col = texelFetch(in_texture, ivec2(tex_size * texcoord) + ivec2(x, y), 0);
  71. if (new_col.a > 0.9)
  72. {
  73. color = vec4(0.0, 0.0, 0.0, 1.0);
  74. x = sample_nb + 1;
  75. y = sample_nb + 1;
  76. }
  77. }
  78. }
  79. }
  80. }
  81. if (color.a < 0.01)
  82. discard;
  83. vec3 hsv = rgb2hsv(color.rgb);
  84. hsv.x = fract(hsv.x + rgb2hsv(pass_color.rgb).x);
  85. gl_FragColor = vec4(hsv2rgb(hsv), color.a);
  86. }