combat_dust.vert 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #version 330 core
  2. layout(location = 0) in vec3 a_position;
  3. layout(location = 1) in vec3 a_normal;
  4. layout(location = 2) in vec2 a_texcoord;
  5. uniform mat4 u_mvp;
  6. uniform mat4 u_model;
  7. uniform float u_time;
  8. uniform vec3 u_center;
  9. uniform float u_radius;
  10. uniform float u_intensity;
  11. uniform int u_effect_type;
  12. out vec3 v_world_pos;
  13. out vec3 v_normal;
  14. out vec2 v_texcoord;
  15. out float v_intensity;
  16. out float v_alpha;
  17. void main() {
  18. vec3 pos = a_position;
  19. vec3 world_pos = (u_model * vec4(pos, 1.0)).xyz;
  20. vec3 to_center = world_pos - u_center;
  21. float dist = length(to_center.xz);
  22. float normalized_dist = dist / max(u_radius, 0.001);
  23. if (u_effect_type == 0) {
  24. float swirl_angle = u_time * 1.5 + normalized_dist * 3.14159;
  25. float swirl_strength = 0.15 * (1.0 - normalized_dist);
  26. pos.x += sin(swirl_angle) * swirl_strength;
  27. pos.z += cos(swirl_angle) * swirl_strength;
  28. float bob = sin(u_time * 2.0 + pos.x * 3.0) * 0.05;
  29. pos.y += bob + 0.1 * sin(u_time * 1.5 + pos.z * 2.0);
  30. float rise = max(0.0, sin(u_time * 0.5 + normalized_dist * 2.0)) * 0.3;
  31. pos.y += rise;
  32. float edge_fade = smoothstep(1.0, 0.7, normalized_dist);
  33. float time_pulse = 0.7 + 0.3 * sin(u_time * 1.5);
  34. v_alpha = edge_fade * time_pulse * u_intensity;
  35. } else if (u_effect_type == 1) {
  36. float height = a_texcoord.y;
  37. float angle_t = a_texcoord.x;
  38. float angle = angle_t * 6.28318;
  39. float tongue_count = 8.0;
  40. float tongue_id = floor(angle_t * tongue_count);
  41. float tongue_local = fract(angle_t * tongue_count);
  42. float tongue_phase = tongue_id * 1.618;
  43. float tongue_time = u_time + tongue_phase * 0.5;
  44. float sway_x = sin(tongue_time * 3.5 + height * 4.0) * 0.2 * height;
  45. float sway_z = cos(tongue_time * 3.0 + height * 3.5) * 0.2 * height;
  46. float cos_a = cos(angle);
  47. float sin_a = sin(angle);
  48. pos.x += sway_x * (-sin_a) + sway_z * cos_a;
  49. pos.z += sway_x * cos_a + sway_z * sin_a;
  50. float tongue_bulge = sin(tongue_local * 3.14159) * 0.3;
  51. float radial_expansion = 1.0 + tongue_bulge * (0.5 + 0.5 * height);
  52. pos.x *= radial_expansion;
  53. pos.z *= radial_expansion;
  54. float rise_speed = sin(tongue_time * 5.0 + height * 2.0) * 0.15;
  55. float vertical_scale = 1.8 + rise_speed + height * 0.5;
  56. pos.y *= vertical_scale;
  57. float turb = sin(tongue_time * 8.0 + height * 10.0) * 0.1 * height * height;
  58. pos.y += turb;
  59. float flicker = 0.85 + 0.15 * sin(tongue_time * 12.0 + height * 8.0);
  60. float height_fade = 1.0 - smoothstep(0.5, 1.0, height);
  61. float tongue_edge_fade =
  62. smoothstep(0.0, 0.2, tongue_local) * smoothstep(1.0, 0.8, tongue_local);
  63. v_alpha = height_fade * tongue_edge_fade * flicker * u_intensity * 1.5;
  64. } else {
  65. float height = a_texcoord.y;
  66. float angle_t = a_texcoord.x;
  67. float angle = angle_t * 6.28318;
  68. float t = u_time;
  69. float phase = smoothstep(0.0, 0.15, t);
  70. float decay = 1.0 - smoothstep(2.5, 5.0, t);
  71. float life = phase * decay;
  72. float chunk_id = floor(angle_t * 24.0);
  73. float chunk_hash = fract(sin(chunk_id * 127.1 + 311.7) * 43758.5453);
  74. float chunk_speed = 0.7 + chunk_hash * 0.6;
  75. float chunk_angle_offset = (chunk_hash - 0.5) * 0.4;
  76. float ejection_angle = angle + chunk_angle_offset;
  77. vec2 dir = vec2(cos(ejection_angle), sin(ejection_angle));
  78. float base_spread = mix(0.3, 2.2, height);
  79. float time_spread = t * chunk_speed * 1.8;
  80. float spread = base_spread + time_spread * (0.6 + 0.4 * chunk_hash);
  81. float turbulence = sin(t * 3.5 + chunk_id * 2.1) * 0.15 * (1.0 - height);
  82. vec2 perp = vec2(-dir.y, dir.x);
  83. pos.xz += dir * spread + perp * turbulence;
  84. float initial_velocity = 4.5 + 2.0 * chunk_hash;
  85. float gravity_accel = 9.8;
  86. float upward = height * initial_velocity * t - 0.5 * gravity_accel * t * t;
  87. upward = max(upward, -0.3);
  88. float dust_rise = (1.0 - height) * 0.8 * t * decay;
  89. pos.y += upward + dust_rise;
  90. float rotation = t * (2.0 + chunk_hash * 3.0);
  91. float wobble = sin(rotation) * 0.1 * height;
  92. pos.x += wobble * dir.y;
  93. pos.z -= wobble * dir.x;
  94. float radial = length(pos.xz);
  95. float radial_fade = 1.0 - smoothstep(1.5, 3.0, radial);
  96. float height_fade =
  97. smoothstep(0.0, 0.1, height) * (1.0 - smoothstep(0.7, 1.0, height));
  98. float dust_density = (1.0 - height) * 0.6 + 0.4;
  99. float flicker = 0.85 + 0.15 * sin(t * 8.0 + chunk_id * 4.0);
  100. v_alpha = clamp(life * radial_fade * height_fade * dust_density * flicker *
  101. u_intensity * 1.2,
  102. 0.0, 1.0);
  103. }
  104. v_world_pos = (u_model * vec4(pos, 1.0)).xyz;
  105. v_normal = normalize(mat3(u_model) * a_normal);
  106. v_texcoord = a_texcoord;
  107. v_intensity = u_intensity;
  108. gl_Position = u_mvp * vec4(pos, 1.0);
  109. }