particlesimheightmap.vert 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. uniform int dt;
  2. uniform mat4 sourcematrix;
  3. uniform int level;
  4. uniform float size_increase_factor;
  5. uniform float track_x;
  6. uniform float track_z;
  7. uniform float track_x_len;
  8. uniform float track_z_len;
  9. uniform samplerBuffer heightmap;
  10. #if __VERSION__ >= 330
  11. layout (location = 4) in vec3 particle_position_initial;
  12. layout (location = 5) in float lifetime_initial;
  13. layout (location = 6) in vec3 particle_velocity_initial;
  14. layout (location = 7) in float size_initial;
  15. layout (location = 0) in vec3 particle_position;
  16. layout (location = 1) in float lifetime;
  17. layout (location = 2) in vec3 particle_velocity;
  18. layout (location = 3) in float size;
  19. #else
  20. in vec3 particle_position_initial;
  21. in float lifetime_initial;
  22. in vec3 particle_velocity_initial;
  23. in float size_initial;
  24. in vec3 particle_position;
  25. in float lifetime;
  26. in vec3 particle_velocity;
  27. in float size;
  28. #endif
  29. out vec3 new_particle_position;
  30. out float new_lifetime;
  31. out vec3 new_particle_velocity;
  32. out float new_size;
  33. void main(void)
  34. {
  35. bool reset = false;
  36. float i_as_float = clamp(256. * (particle_position.x - track_x) / track_x_len, 0., 255.);
  37. float j_as_float = clamp(256. * (particle_position.z - track_z) / track_z_len, 0., 255.);
  38. int i = int(i_as_float);
  39. int j = int(j_as_float);
  40. float h = particle_position.y - texelFetch(heightmap, i * 256 + j).r;
  41. reset = h < 0.;
  42. vec4 initialposition = sourcematrix * vec4(particle_position_initial, 1.0);
  43. vec4 adjusted_initial_velocity = sourcematrix * vec4(particle_position_initial + particle_velocity_initial, 1.0) - initialposition;
  44. float adjusted_lifetime = lifetime + (float(dt)/lifetime_initial);
  45. reset = reset || (adjusted_lifetime > 1.) && (gl_VertexID <= level);
  46. reset = reset || (lifetime < 0.);
  47. new_particle_position = !reset ? particle_position + particle_velocity.xyz * float(dt) : initialposition.xyz;
  48. new_lifetime = !reset ? adjusted_lifetime : 0.;
  49. new_particle_velocity = !reset ? particle_velocity : adjusted_initial_velocity.xyz;
  50. new_size = !reset ? mix(size_initial, size_initial * size_increase_factor, adjusted_lifetime) : size_initial;
  51. gl_Position = vec4(0.);
  52. }