rain.vert 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #version 330 core
  2. layout(location = 0) in vec3 a_position;
  3. layout(location = 1) in vec3 a_offset;
  4. layout(location = 2) in float a_alpha;
  5. uniform mat4 u_view_proj;
  6. uniform float u_time;
  7. uniform float u_intensity;
  8. uniform vec3 u_camera_pos;
  9. uniform vec3 u_wind;
  10. uniform int u_weather_type;
  11. uniform float u_wind_strength;
  12. out float v_alpha;
  13. out float v_rotation;
  14. const float AREA_HEIGHT = 30.0;
  15. const float AREA_RADIUS = 50.0;
  16. const float RAIN_WIND_FACTOR = 0.1;
  17. const float SNOW_WIND_FACTOR = 0.25;
  18. const float SNOW_DRIFT_FREQ_X = 0.5;
  19. const float SNOW_DRIFT_FREQ_Z = 0.3;
  20. const float SNOW_DRIFT_SCALE_X = 0.3;
  21. const float SNOW_DRIFT_AMPLITUDE_X = 0.15;
  22. const float SNOW_DRIFT_AMPLITUDE_Z = 0.1;
  23. const float SNOW_POINT_SIZE = 22.0;
  24. void main() {
  25. float speed = a_offset.z;
  26. if (u_weather_type == 1) {
  27. speed *= 0.15;
  28. }
  29. float y_offset = a_offset.y;
  30. float fall_distance = mod(speed * u_time, AREA_HEIGHT);
  31. vec3 pos = a_position;
  32. pos.x += u_camera_pos.x;
  33. pos.z += u_camera_pos.z;
  34. pos.y = pos.y - fall_distance + y_offset;
  35. if (pos.y < 0.0) {
  36. pos.y += AREA_HEIGHT;
  37. }
  38. float wind_factor =
  39. (u_weather_type == 1) ? SNOW_WIND_FACTOR : RAIN_WIND_FACTOR;
  40. float height_factor = (AREA_HEIGHT - pos.y) / AREA_HEIGHT;
  41. pos.x += u_wind.x * height_factor * wind_factor * (1.0 + u_wind_strength);
  42. pos.z += u_wind.z * height_factor * wind_factor * (1.0 + u_wind_strength);
  43. if (u_weather_type == 1) {
  44. float drift =
  45. sin(u_time * SNOW_DRIFT_FREQ_X + a_position.x * SNOW_DRIFT_SCALE_X) *
  46. SNOW_DRIFT_AMPLITUDE_X;
  47. pos.x += drift;
  48. pos.z +=
  49. cos(u_time * SNOW_DRIFT_FREQ_Z + a_position.z * SNOW_DRIFT_SCALE_X) *
  50. SNOW_DRIFT_AMPLITUDE_Z;
  51. gl_PointSize = SNOW_POINT_SIZE;
  52. v_rotation = a_position.x * 2.0 + a_position.z * 3.0 + u_time * 0.2;
  53. }
  54. gl_Position = u_view_proj * vec4(pos, 1.0);
  55. v_alpha = a_alpha * u_intensity;
  56. }