Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

85 рядки
2.0 KiB

  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. vec4 color = texture2D(in_texture, pass_texcoord.xy -
  57. vec2(pass_texcoord.z * in_sprite_flip, 0.0));
  58. if (color.a < 0.01)
  59. discard;
  60. vec3 hsv = rgb2hsv(color.rgb);
  61. hsv.x = fract(hsv.x + rgb2hsv(pass_color.rgb).x);
  62. gl_FragColor = vec4(hsv2rgb(hsv), color.a);
  63. }