您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

116 行
3.0 KiB

  1. [vert.glsl]
  2. #version 130
  3. in vec3 in_position;
  4. in vec4 in_color;
  5. in vec4 in_texcoord;
  6. uniform mat4 u_model_view;
  7. uniform mat3 u_normal_mat;
  8. uniform mat4 u_proj;
  9. uniform float u_sprite_orientation;
  10. out vec4 pass_texcoord;
  11. out vec4 pass_color;
  12. void main(void)
  13. {
  14. vec4 vertex = u_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(u_sprite_orientation);
  17. float cosX = cos(u_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 = u_proj * vertex;
  27. }
  28. [frag.glsl]
  29. #version 130
  30. #if defined GL_ES
  31. precision highp float;
  32. #endif
  33. in vec4 pass_texcoord;
  34. in vec4 pass_color;
  35. uniform sampler2D u_texture;
  36. uniform float u_sprite_flip;
  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 * u_sprite_flip, 0.0);
  58. vec4 color = texture2D(u_texture, texcoord) * pass_color;
  59. //need 130 : ivec2 tex_size = textureSize(u_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(u_texture, new_tc);
  71. //need 130 : vec4 new_col = texelFetch(u_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. }