pointemitter.vert 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. uniform int dt;
  2. uniform mat4 sourcematrix;
  3. uniform int level;
  4. uniform float size_increase_factor;
  5. #if __VERSION__ >= 330
  6. layout (location = 4) in vec3 particle_position_initial;
  7. layout (location = 5) in float lifetime_initial;
  8. layout (location = 6) in vec3 particle_velocity_initial;
  9. layout (location = 7) in float size_initial;
  10. layout (location = 0) in vec3 particle_position;
  11. layout (location = 1) in float lifetime;
  12. layout (location = 2) in vec3 particle_velocity;
  13. layout (location = 3) in float size;
  14. #else
  15. in vec3 particle_position_initial;
  16. in float lifetime_initial;
  17. in vec3 particle_velocity_initial;
  18. in float size_initial;
  19. in vec3 particle_position;
  20. in float lifetime;
  21. in vec3 particle_velocity;
  22. in float size;
  23. #endif
  24. out vec3 new_particle_position;
  25. out float new_lifetime;
  26. out vec3 new_particle_velocity;
  27. out float new_size;
  28. void main(void)
  29. {
  30. float updated_lifetime = lifetime + (float(dt)/lifetime_initial);
  31. if (updated_lifetime > 1.)
  32. {
  33. if (gl_VertexID < level)
  34. {
  35. float dt_from_last_frame = fract(updated_lifetime) * lifetime_initial;
  36. vec4 updated_initialposition = sourcematrix * vec4(particle_position_initial, 1.0);
  37. vec4 updated_initial_velocity = sourcematrix * vec4(particle_position_initial + particle_velocity_initial, 1.0) - updated_initialposition;
  38. new_particle_position = updated_initialposition.xyz + updated_initial_velocity.xyz * float(dt_from_last_frame);
  39. new_particle_velocity = updated_initial_velocity.xyz;
  40. new_lifetime = fract(updated_lifetime);
  41. new_size = mix(size_initial, size_initial * size_increase_factor, fract(updated_lifetime));
  42. }
  43. else
  44. {
  45. new_lifetime = fract(updated_lifetime);
  46. new_size = 0;
  47. }
  48. }
  49. else
  50. {
  51. new_particle_position = particle_position + particle_velocity.xyz * float(dt);
  52. new_particle_velocity = particle_velocity;
  53. new_lifetime = updated_lifetime;
  54. new_size = (size == 0) ? 0. : mix(size_initial, size_initial * size_increase_factor, updated_lifetime);
  55. }
  56. gl_Position = vec4(0.);
  57. }