combat_dust_pipeline.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. #include "combat_dust_pipeline.h"
  2. #include "../../../game/core/component.h"
  3. #include "../../../game/core/world.h"
  4. #include "../backend.h"
  5. #include "../camera.h"
  6. #include "../render_constants.h"
  7. #include "../shader_cache.h"
  8. #include <QDebug>
  9. #include <QMatrix4x4>
  10. #include <QOpenGLContext>
  11. #include <cmath>
  12. #include <numbers>
  13. namespace Render::GL::BackendPipelines {
  14. using namespace Render::GL::VertexAttrib;
  15. using namespace Render::GL::ComponentCount;
  16. namespace {
  17. constexpr float kMinDustIntensity = 0.01F;
  18. constexpr float kDefaultDustRadius = 2.0F;
  19. constexpr float kDefaultDustIntensity = 0.6F;
  20. constexpr float kDustColorR = 0.6F;
  21. constexpr float kDustColorG = 0.55F;
  22. constexpr float kDustColorB = 0.45F;
  23. constexpr float kDustYOffset = 0.05F;
  24. constexpr float kDefaultFlameRadius = 3.0F;
  25. constexpr float kDefaultFlameIntensity = 0.8F;
  26. constexpr float kFlameColorR = 1.0F;
  27. constexpr float kFlameColorG = 0.4F;
  28. constexpr float kFlameColorB = 0.1F;
  29. constexpr float kFlameYOffset = 0.5F;
  30. constexpr float kBuildingHealthThreshold = 0.5F;
  31. void clear_gl_errors() {
  32. while (glGetError() != GL_NO_ERROR) {
  33. }
  34. }
  35. auto check_gl_error(const char *operation) -> bool {
  36. GLenum err = glGetError();
  37. if (err != GL_NO_ERROR) {
  38. qWarning() << "CombatDustPipeline GL error in" << operation << ":" << err;
  39. return false;
  40. }
  41. return true;
  42. }
  43. } // namespace
  44. auto CombatDustPipeline::initialize() -> bool {
  45. if (m_shader_cache == nullptr) {
  46. qWarning() << "CombatDustPipeline::initialize: null ShaderCache";
  47. return false;
  48. }
  49. initializeOpenGLFunctions();
  50. clear_gl_errors();
  51. m_dust_shader = m_shader_cache->get("combat_dust");
  52. if (m_dust_shader == nullptr) {
  53. m_dust_shader = m_shader_cache->load(
  54. "combat_dust", QStringLiteral(":/assets/shaders/combat_dust.vert"),
  55. QStringLiteral(":/assets/shaders/combat_dust.frag"));
  56. }
  57. if (m_dust_shader == nullptr) {
  58. qWarning() << "CombatDustPipeline: Failed to get combat_dust shader";
  59. return false;
  60. }
  61. cache_uniforms();
  62. if (!create_dust_geometry()) {
  63. qWarning() << "CombatDustPipeline: Failed to create dust geometry";
  64. return false;
  65. }
  66. qInfo() << "CombatDustPipeline initialized successfully";
  67. return is_initialized();
  68. }
  69. void CombatDustPipeline::shutdown() {
  70. shutdown_geometry();
  71. m_dust_shader = nullptr;
  72. }
  73. void CombatDustPipeline::shutdown_geometry() {
  74. if (QOpenGLContext::currentContext() == nullptr) {
  75. m_vao = 0;
  76. m_vertex_buffer = 0;
  77. m_index_buffer = 0;
  78. m_index_count = 0;
  79. return;
  80. }
  81. initializeOpenGLFunctions();
  82. clear_gl_errors();
  83. if (m_vao != 0) {
  84. glDeleteVertexArrays(1, &m_vao);
  85. m_vao = 0;
  86. }
  87. if (m_vertex_buffer != 0) {
  88. glDeleteBuffers(1, &m_vertex_buffer);
  89. m_vertex_buffer = 0;
  90. }
  91. if (m_index_buffer != 0) {
  92. glDeleteBuffers(1, &m_index_buffer);
  93. m_index_buffer = 0;
  94. }
  95. m_index_count = 0;
  96. }
  97. void CombatDustPipeline::cache_uniforms() {
  98. if (m_dust_shader == nullptr) {
  99. return;
  100. }
  101. m_uniforms.mvp = m_dust_shader->uniform_handle("u_mvp");
  102. m_uniforms.model = m_dust_shader->uniform_handle("u_model");
  103. m_uniforms.time = m_dust_shader->uniform_handle("u_time");
  104. m_uniforms.center = m_dust_shader->uniform_handle("u_center");
  105. m_uniforms.radius = m_dust_shader->uniform_handle("u_radius");
  106. m_uniforms.intensity = m_dust_shader->uniform_handle("u_intensity");
  107. m_uniforms.dust_color = m_dust_shader->uniform_handle("u_dust_color");
  108. m_uniforms.effect_type = m_dust_shader->uniform_handle("u_effect_type");
  109. }
  110. auto CombatDustPipeline::is_initialized() const -> bool {
  111. return m_dust_shader != nullptr && m_vao != 0 && m_index_count > 0;
  112. }
  113. struct DustVertex {
  114. float position[3];
  115. float normal[3];
  116. float tex_coord[2];
  117. };
  118. auto CombatDustPipeline::create_dust_geometry() -> bool {
  119. initializeOpenGLFunctions();
  120. shutdown_geometry();
  121. clear_gl_errors();
  122. std::vector<DustVertex> vertices;
  123. std::vector<unsigned int> indices;
  124. constexpr int rings = 6;
  125. constexpr int segments = 16;
  126. constexpr float pi = std::numbers::pi_v<float>;
  127. constexpr int height_levels = 8;
  128. constexpr int angle_segments = 12;
  129. constexpr float max_height = 1.0F;
  130. vertices.reserve(
  131. static_cast<size_t>((height_levels + 1) * (angle_segments + 1)));
  132. for (int h = 0; h <= height_levels; ++h) {
  133. float height_t = static_cast<float>(h) / static_cast<float>(height_levels);
  134. float y = height_t * max_height;
  135. float radius_at_height = 1.0F - height_t * 0.3F;
  136. for (int a = 0; a <= angle_segments; ++a) {
  137. float angle_t =
  138. static_cast<float>(a) / static_cast<float>(angle_segments);
  139. float theta = angle_t * pi * 2.0F;
  140. float x = radius_at_height * std::cos(theta);
  141. float z = radius_at_height * std::sin(theta);
  142. DustVertex v;
  143. v.position[0] = x;
  144. v.position[1] = y;
  145. v.position[2] = z;
  146. v.normal[0] = std::cos(theta);
  147. v.normal[1] = 0.3F;
  148. v.normal[2] = std::sin(theta);
  149. v.tex_coord[0] = angle_t;
  150. v.tex_coord[1] = height_t;
  151. vertices.push_back(v);
  152. }
  153. }
  154. indices.reserve(static_cast<size_t>(height_levels * angle_segments * 6));
  155. for (int h = 0; h < height_levels; ++h) {
  156. for (int a = 0; a < angle_segments; ++a) {
  157. unsigned int curr =
  158. static_cast<unsigned int>(h * (angle_segments + 1) + a);
  159. unsigned int next = curr + static_cast<unsigned int>(angle_segments + 1);
  160. indices.push_back(curr);
  161. indices.push_back(next);
  162. indices.push_back(curr + 1);
  163. indices.push_back(curr + 1);
  164. indices.push_back(next);
  165. indices.push_back(next + 1);
  166. }
  167. }
  168. glGenVertexArrays(1, &m_vao);
  169. if (!check_gl_error("glGenVertexArrays") || m_vao == 0) {
  170. return false;
  171. }
  172. glBindVertexArray(m_vao);
  173. if (!check_gl_error("glBindVertexArray")) {
  174. glDeleteVertexArrays(1, &m_vao);
  175. m_vao = 0;
  176. return false;
  177. }
  178. glGenBuffers(1, &m_vertex_buffer);
  179. glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer);
  180. glBufferData(GL_ARRAY_BUFFER,
  181. static_cast<GLsizeiptr>(vertices.size() * sizeof(DustVertex)),
  182. vertices.data(), GL_STATIC_DRAW);
  183. if (!check_gl_error("vertex buffer")) {
  184. shutdown_geometry();
  185. return false;
  186. }
  187. glGenBuffers(1, &m_index_buffer);
  188. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer);
  189. glBufferData(GL_ELEMENT_ARRAY_BUFFER,
  190. static_cast<GLsizeiptr>(indices.size() * sizeof(unsigned int)),
  191. indices.data(), GL_STATIC_DRAW);
  192. if (!check_gl_error("index buffer")) {
  193. shutdown_geometry();
  194. return false;
  195. }
  196. m_index_count = static_cast<GLsizei>(indices.size());
  197. glEnableVertexAttribArray(VertexAttrib::Position);
  198. glVertexAttribPointer(
  199. VertexAttrib::Position, ComponentCount::Vec3, GL_FLOAT, GL_FALSE,
  200. sizeof(DustVertex),
  201. reinterpret_cast<void *>(offsetof(DustVertex, position)));
  202. glEnableVertexAttribArray(VertexAttrib::Normal);
  203. glVertexAttribPointer(VertexAttrib::Normal, ComponentCount::Vec3, GL_FLOAT,
  204. GL_FALSE, sizeof(DustVertex),
  205. reinterpret_cast<void *>(offsetof(DustVertex, normal)));
  206. glEnableVertexAttribArray(VertexAttrib::TexCoord);
  207. glVertexAttribPointer(
  208. VertexAttrib::TexCoord, ComponentCount::Vec2, GL_FLOAT, GL_FALSE,
  209. sizeof(DustVertex),
  210. reinterpret_cast<void *>(offsetof(DustVertex, tex_coord)));
  211. glBindVertexArray(0);
  212. if (!check_gl_error("vertex attributes")) {
  213. shutdown_geometry();
  214. return false;
  215. }
  216. return true;
  217. }
  218. void CombatDustPipeline::collect_combat_zones(Engine::Core::World *world,
  219. float animation_time) {
  220. if (world == nullptr) {
  221. return;
  222. }
  223. auto units = world->get_entities_with<Engine::Core::UnitComponent>();
  224. for (auto *unit : units) {
  225. if (unit->has_component<Engine::Core::PendingRemovalComponent>()) {
  226. continue;
  227. }
  228. auto *unit_comp = unit->get_component<Engine::Core::UnitComponent>();
  229. auto *transform = unit->get_component<Engine::Core::TransformComponent>();
  230. auto *attack = unit->get_component<Engine::Core::AttackComponent>();
  231. if (transform == nullptr || unit_comp == nullptr) {
  232. continue;
  233. }
  234. if (unit_comp->health <= 0) {
  235. continue;
  236. }
  237. if (attack == nullptr || !attack->in_melee_lock) {
  238. continue;
  239. }
  240. CombatDustData data;
  241. data.position =
  242. QVector3D(transform->position.x, kDustYOffset, transform->position.z);
  243. data.radius = kDefaultDustRadius;
  244. data.intensity = kDefaultDustIntensity;
  245. data.color = QVector3D(kDustColorR, kDustColorG, kDustColorB);
  246. data.time = animation_time;
  247. data.effect_type = EffectType::Dust;
  248. m_dust_data.push_back(data);
  249. }
  250. }
  251. void CombatDustPipeline::collect_building_flames(Engine::Core::World *world,
  252. float animation_time) {
  253. if (world == nullptr) {
  254. return;
  255. }
  256. auto buildings = world->get_entities_with<Engine::Core::BuildingComponent>();
  257. for (auto *building : buildings) {
  258. if (building->has_component<Engine::Core::PendingRemovalComponent>()) {
  259. continue;
  260. }
  261. auto *unit_comp = building->get_component<Engine::Core::UnitComponent>();
  262. auto *transform =
  263. building->get_component<Engine::Core::TransformComponent>();
  264. if (transform == nullptr || unit_comp == nullptr) {
  265. continue;
  266. }
  267. if (unit_comp->health <= 0) {
  268. continue;
  269. }
  270. float health_ratio = static_cast<float>(unit_comp->health) /
  271. static_cast<float>(unit_comp->max_health);
  272. if (health_ratio > kBuildingHealthThreshold) {
  273. continue;
  274. }
  275. float base_intensity = kDefaultFlameIntensity * (1.0F - health_ratio);
  276. float cx = transform->position.x;
  277. float cz = transform->position.z;
  278. constexpr float kBuildingHalfWidth = 1.5F;
  279. constexpr float kBuildingHalfDepth = 1.2F;
  280. constexpr float kFlameSpacing = 0.8F;
  281. struct FlamePoint {
  282. float dx, dz, height_offset, intensity_mult, radius_mult;
  283. };
  284. FlamePoint flame_points[] = {
  285. {-kBuildingHalfWidth * 0.7F, -kBuildingHalfDepth * 0.7F, 0.8F, 1.0F,
  286. 0.9F},
  287. {kBuildingHalfWidth * 0.7F, -kBuildingHalfDepth * 0.7F, 0.7F, 0.95F,
  288. 0.85F},
  289. {-kBuildingHalfWidth * 0.7F, kBuildingHalfDepth * 0.7F, 0.6F, 0.9F,
  290. 0.8F},
  291. {kBuildingHalfWidth * 0.7F, kBuildingHalfDepth * 0.7F, 0.75F, 1.0F,
  292. 0.9F},
  293. {0.0F, -kBuildingHalfDepth * 0.8F, 0.9F, 0.85F, 0.7F},
  294. {0.0F, kBuildingHalfDepth * 0.8F, 0.7F, 0.8F, 0.65F},
  295. {-kBuildingHalfWidth * 0.8F, 0.0F, 0.65F, 0.75F, 0.7F},
  296. {kBuildingHalfWidth * 0.8F, 0.0F, 0.8F, 0.85F, 0.75F},
  297. {0.0F, 0.0F, 1.0F, 1.1F, 1.0F},
  298. };
  299. for (const auto &fp : flame_points) {
  300. CombatDustData data;
  301. data.position =
  302. QVector3D(cx + fp.dx, kFlameYOffset + fp.height_offset, cz + fp.dz);
  303. data.radius = kDefaultFlameRadius * fp.radius_mult;
  304. data.intensity = base_intensity * fp.intensity_mult;
  305. data.color = QVector3D(kFlameColorR, kFlameColorG, kFlameColorB);
  306. data.time = animation_time;
  307. data.effect_type = EffectType::Flame;
  308. m_dust_data.push_back(data);
  309. }
  310. }
  311. }
  312. void CombatDustPipeline::collect_all_effects(Engine::Core::World *world,
  313. float animation_time) {
  314. m_dust_data.clear();
  315. collect_combat_zones(world, animation_time);
  316. collect_building_flames(world, animation_time);
  317. }
  318. void CombatDustPipeline::add_dust_zone(const QVector3D &position, float radius,
  319. float intensity, const QVector3D &color,
  320. float time) {
  321. CombatDustData data;
  322. data.position = position;
  323. data.radius = radius;
  324. data.intensity = intensity;
  325. data.color = color;
  326. data.time = time;
  327. data.effect_type = EffectType::Dust;
  328. m_dust_data.push_back(data);
  329. }
  330. void CombatDustPipeline::add_flame_zone(const QVector3D &position, float radius,
  331. float intensity, const QVector3D &color,
  332. float time) {
  333. CombatDustData data;
  334. data.position = position;
  335. data.radius = radius;
  336. data.intensity = intensity;
  337. data.color = color;
  338. data.time = time;
  339. data.effect_type = EffectType::Flame;
  340. m_dust_data.push_back(data);
  341. }
  342. void CombatDustPipeline::render(const Camera &cam, float animation_time) {
  343. if (!is_initialized() || m_dust_data.empty()) {
  344. return;
  345. }
  346. initializeOpenGLFunctions();
  347. clear_gl_errors();
  348. GLboolean cull_enabled = glIsEnabled(GL_CULL_FACE);
  349. GLboolean depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
  350. GLboolean blend_enabled = glIsEnabled(GL_BLEND);
  351. GLboolean depth_mask_enabled = GL_TRUE;
  352. glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_mask_enabled);
  353. glDisable(GL_CULL_FACE);
  354. glEnable(GL_DEPTH_TEST);
  355. glDepthMask(GL_FALSE);
  356. glEnable(GL_BLEND);
  357. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  358. m_dust_shader->use();
  359. glBindVertexArray(m_vao);
  360. for (const auto &data : m_dust_data) {
  361. CombatDustData render_data = data;
  362. render_data.time = animation_time;
  363. render_dust(render_data, cam);
  364. }
  365. glBindVertexArray(0);
  366. glDepthMask(depth_mask_enabled);
  367. if (!blend_enabled) {
  368. glDisable(GL_BLEND);
  369. }
  370. if (depth_test_enabled) {
  371. glEnable(GL_DEPTH_TEST);
  372. } else {
  373. glDisable(GL_DEPTH_TEST);
  374. }
  375. if (cull_enabled) {
  376. glEnable(GL_CULL_FACE);
  377. }
  378. }
  379. void CombatDustPipeline::render_dust(const CombatDustData &data,
  380. const Camera &cam) {
  381. QMatrix4x4 model;
  382. model.setToIdentity();
  383. model.translate(data.position);
  384. model.scale(data.radius);
  385. QMatrix4x4 vp = cam.get_projection_matrix() * cam.get_view_matrix();
  386. QMatrix4x4 mvp = vp * model;
  387. m_dust_shader->set_uniform(m_uniforms.mvp, mvp);
  388. m_dust_shader->set_uniform(m_uniforms.model, model);
  389. m_dust_shader->set_uniform(m_uniforms.time, data.time);
  390. m_dust_shader->set_uniform(m_uniforms.center, data.position);
  391. m_dust_shader->set_uniform(m_uniforms.radius, data.radius);
  392. m_dust_shader->set_uniform(m_uniforms.intensity, data.intensity);
  393. m_dust_shader->set_uniform(m_uniforms.dust_color, data.color);
  394. m_dust_shader->set_uniform(m_uniforms.effect_type,
  395. static_cast<int>(data.effect_type));
  396. glDrawElements(GL_TRIANGLES, m_index_count, GL_UNSIGNED_INT, nullptr);
  397. }
  398. void CombatDustPipeline::render_single_dust(const QVector3D &position,
  399. const QVector3D &color,
  400. float radius, float intensity,
  401. float time,
  402. const QMatrix4x4 &view_proj) {
  403. if (!is_initialized()) {
  404. return;
  405. }
  406. if (intensity < kMinDustIntensity) {
  407. return;
  408. }
  409. initializeOpenGLFunctions();
  410. GLboolean cull_enabled = glIsEnabled(GL_CULL_FACE);
  411. GLboolean depth_mask_enabled = GL_TRUE;
  412. glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_mask_enabled);
  413. glDisable(GL_CULL_FACE);
  414. glEnable(GL_DEPTH_TEST);
  415. glDepthMask(GL_FALSE);
  416. glEnable(GL_BLEND);
  417. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  418. m_dust_shader->use();
  419. glBindVertexArray(m_vao);
  420. QMatrix4x4 model;
  421. model.setToIdentity();
  422. model.translate(position);
  423. model.scale(radius);
  424. QMatrix4x4 mvp = view_proj * model;
  425. m_dust_shader->set_uniform(m_uniforms.mvp, mvp);
  426. m_dust_shader->set_uniform(m_uniforms.model, model);
  427. m_dust_shader->set_uniform(m_uniforms.time, time);
  428. m_dust_shader->set_uniform(m_uniforms.center, position);
  429. m_dust_shader->set_uniform(m_uniforms.radius, radius);
  430. m_dust_shader->set_uniform(m_uniforms.intensity, intensity);
  431. m_dust_shader->set_uniform(m_uniforms.dust_color, color);
  432. m_dust_shader->set_uniform(m_uniforms.effect_type,
  433. static_cast<int>(EffectType::Dust));
  434. glDrawElements(GL_TRIANGLES, m_index_count, GL_UNSIGNED_INT, nullptr);
  435. glBindVertexArray(0);
  436. glDepthMask(depth_mask_enabled);
  437. if (cull_enabled) {
  438. glEnable(GL_CULL_FACE);
  439. }
  440. }
  441. void CombatDustPipeline::render_single_flame(const QVector3D &position,
  442. const QVector3D &color,
  443. float radius, float intensity,
  444. float time,
  445. const QMatrix4x4 &view_proj) {
  446. if (!is_initialized()) {
  447. return;
  448. }
  449. if (intensity < kMinDustIntensity) {
  450. return;
  451. }
  452. initializeOpenGLFunctions();
  453. GLboolean cull_enabled = glIsEnabled(GL_CULL_FACE);
  454. GLboolean depth_mask_enabled = GL_TRUE;
  455. glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_mask_enabled);
  456. glDisable(GL_CULL_FACE);
  457. glEnable(GL_DEPTH_TEST);
  458. glDepthMask(GL_FALSE);
  459. glEnable(GL_BLEND);
  460. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  461. m_dust_shader->use();
  462. glBindVertexArray(m_vao);
  463. QMatrix4x4 model;
  464. model.setToIdentity();
  465. model.translate(position);
  466. model.scale(radius);
  467. QMatrix4x4 mvp = view_proj * model;
  468. m_dust_shader->set_uniform(m_uniforms.mvp, mvp);
  469. m_dust_shader->set_uniform(m_uniforms.model, model);
  470. m_dust_shader->set_uniform(m_uniforms.time, time);
  471. m_dust_shader->set_uniform(m_uniforms.center, position);
  472. m_dust_shader->set_uniform(m_uniforms.radius, radius);
  473. m_dust_shader->set_uniform(m_uniforms.intensity, intensity);
  474. m_dust_shader->set_uniform(m_uniforms.dust_color, color);
  475. m_dust_shader->set_uniform(m_uniforms.effect_type,
  476. static_cast<int>(EffectType::Flame));
  477. glDrawElements(GL_TRIANGLES, m_index_count, GL_UNSIGNED_INT, nullptr);
  478. glBindVertexArray(0);
  479. glDepthMask(depth_mask_enabled);
  480. if (cull_enabled) {
  481. glEnable(GL_CULL_FACE);
  482. }
  483. }
  484. void CombatDustPipeline::render_single_stone_impact(
  485. const QVector3D &position, const QVector3D &color, float radius,
  486. float intensity, float time, const QMatrix4x4 &view_proj) {
  487. if (!is_initialized()) {
  488. return;
  489. }
  490. if (intensity < kMinDustIntensity) {
  491. return;
  492. }
  493. initializeOpenGLFunctions();
  494. GLboolean cull_enabled = glIsEnabled(GL_CULL_FACE);
  495. GLboolean depth_mask_enabled = GL_TRUE;
  496. glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_mask_enabled);
  497. glDisable(GL_CULL_FACE);
  498. glEnable(GL_DEPTH_TEST);
  499. glDepthMask(GL_FALSE);
  500. glEnable(GL_BLEND);
  501. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  502. m_dust_shader->use();
  503. glBindVertexArray(m_vao);
  504. QMatrix4x4 model;
  505. model.setToIdentity();
  506. model.translate(position);
  507. model.scale(radius);
  508. QMatrix4x4 mvp = view_proj * model;
  509. m_dust_shader->set_uniform(m_uniforms.mvp, mvp);
  510. m_dust_shader->set_uniform(m_uniforms.model, model);
  511. m_dust_shader->set_uniform(m_uniforms.time, time);
  512. m_dust_shader->set_uniform(m_uniforms.center, position);
  513. m_dust_shader->set_uniform(m_uniforms.radius, radius);
  514. m_dust_shader->set_uniform(m_uniforms.intensity, intensity);
  515. m_dust_shader->set_uniform(m_uniforms.dust_color, color);
  516. m_dust_shader->set_uniform(m_uniforms.effect_type,
  517. static_cast<int>(EffectType::StoneImpact));
  518. glDrawElements(GL_TRIANGLES, m_index_count, GL_UNSIGNED_INT, nullptr);
  519. glBindVertexArray(0);
  520. glDepthMask(depth_mask_enabled);
  521. if (cull_enabled) {
  522. glEnable(GL_CULL_FACE);
  523. }
  524. }
  525. } // namespace Render::GL::BackendPipelines