flipparticle.vert 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #if __VERSION__ >= 330
  2. layout(location=0) in vec3 Position;
  3. layout(location = 1) in float lifetime;
  4. layout(location = 2) in float size;
  5. layout(location = 3) in vec2 Texcoord;
  6. layout(location = 4) in vec2 quadcorner;
  7. layout(location = 5) in vec3 rotationvec;
  8. layout(location = 6) in float anglespeed;
  9. #else
  10. in vec3 Position;
  11. in float lifetime;
  12. in float size;
  13. in vec2 Texcoord;
  14. in vec2 quadcorner;
  15. in vec3 rotationvec;
  16. float anglespeed;
  17. #endif
  18. out float lf;
  19. out vec2 tc;
  20. out vec3 pc;
  21. void main(void)
  22. {
  23. tc = Texcoord;
  24. lf = lifetime;
  25. vec3 newposition = Position;
  26. // from http://jeux.developpez.com/faq/math
  27. float angle = lf * anglespeed;
  28. float sin_a = sin(angle / 2.);
  29. float cos_a = cos(angle / 2.);
  30. vec4 quaternion = normalize(vec4(rotationvec * sin_a, cos_a));
  31. float xx = quaternion.x * quaternion.x;
  32. float xy = quaternion.x * quaternion.y;
  33. float xz = quaternion.x * quaternion.z;
  34. float xw = quaternion.x * quaternion.w;
  35. float yy = quaternion.y * quaternion.y;
  36. float yz = quaternion.y * quaternion.z;
  37. float yw = quaternion.y * quaternion.w;
  38. float zz = quaternion.z * quaternion.z;
  39. float zw = quaternion.z * quaternion.w;
  40. vec4 col1 = vec4(
  41. 1. - 2. * ( yy + zz ),
  42. 2. * ( xy + zw ),
  43. 2. * ( xz - yw ),
  44. 0.);
  45. vec4 col2 = vec4(
  46. 2. * ( xy - zw ),
  47. 1. - 2. * ( xx + zz ),
  48. 2. * ( yz + xw ),
  49. 0.);
  50. vec4 col3 = vec4(
  51. 2. * ( xz + yw ),
  52. 2. * ( yz - xw ),
  53. 1. - 2. * ( xx + yy ),
  54. 0.);
  55. vec4 col4 = vec4(0., 0., 0., 1.);
  56. mat4 rotationMatrix = mat4(col1, col2, col3, col4);
  57. vec3 newquadcorner = size * vec3(quadcorner, 0.);
  58. newquadcorner = (rotationMatrix * vec4(newquadcorner, 0.)).xyz;
  59. vec4 viewpos = ViewMatrix * vec4(newposition + newquadcorner, 1.0);
  60. gl_Position = ProjectionMatrix * viewpos;
  61. pc = vec3(1.);
  62. }