gpu_particles_3d.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. /**************************************************************************/
  2. /* gpu_particles_3d.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "gpu_particles_3d.h"
  31. #include "gpu_particles_3d.compat.inc"
  32. #include "scene/3d/cpu_particles_3d.h"
  33. #include "scene/resources/curve_texture.h"
  34. #include "scene/resources/gradient_texture.h"
  35. #include "scene/resources/particle_process_material.h"
  36. AABB GPUParticles3D::get_aabb() const {
  37. return AABB();
  38. }
  39. void GPUParticles3D::set_emitting(bool p_emitting) {
  40. // Do not return even if `p_emitting == emitting` because `emitting` is just an approximation.
  41. if (p_emitting && one_shot) {
  42. if (!active && !emitting) {
  43. // Last cycle ended.
  44. active = true;
  45. time = 0;
  46. signal_canceled = false;
  47. emission_time = lifetime;
  48. active_time = lifetime * (2 - explosiveness_ratio);
  49. } else {
  50. signal_canceled = true;
  51. }
  52. set_process_internal(true);
  53. } else if (!p_emitting) {
  54. if (one_shot) {
  55. set_process_internal(true);
  56. } else {
  57. set_process_internal(false);
  58. }
  59. } else {
  60. set_process_internal(true);
  61. }
  62. emitting = p_emitting;
  63. RS::get_singleton()->particles_set_emitting(particles, p_emitting);
  64. }
  65. void GPUParticles3D::set_amount(int p_amount) {
  66. ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles cannot be smaller than 1.");
  67. amount = p_amount;
  68. RS::get_singleton()->particles_set_amount(particles, amount);
  69. }
  70. void GPUParticles3D::set_lifetime(double p_lifetime) {
  71. ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0.");
  72. lifetime = p_lifetime;
  73. RS::get_singleton()->particles_set_lifetime(particles, lifetime);
  74. }
  75. void GPUParticles3D::set_interp_to_end(float p_interp) {
  76. interp_to_end_factor = CLAMP(p_interp, 0.0, 1.0);
  77. RS::get_singleton()->particles_set_interp_to_end(particles, interp_to_end_factor);
  78. }
  79. void GPUParticles3D::set_one_shot(bool p_one_shot) {
  80. one_shot = p_one_shot;
  81. RS::get_singleton()->particles_set_one_shot(particles, one_shot);
  82. if (is_emitting()) {
  83. if (!one_shot) {
  84. RenderingServer::get_singleton()->particles_restart(particles);
  85. }
  86. }
  87. }
  88. void GPUParticles3D::set_use_fixed_seed(bool p_use_fixed_seed) {
  89. if (p_use_fixed_seed == use_fixed_seed) {
  90. return;
  91. }
  92. use_fixed_seed = p_use_fixed_seed;
  93. notify_property_list_changed();
  94. }
  95. bool GPUParticles3D::get_use_fixed_seed() const {
  96. return use_fixed_seed;
  97. }
  98. void GPUParticles3D::set_seed(uint32_t p_seed) {
  99. seed = p_seed;
  100. RS::get_singleton()->particles_set_seed(particles, p_seed);
  101. }
  102. uint32_t GPUParticles3D::get_seed() const {
  103. return seed;
  104. }
  105. void GPUParticles3D::set_pre_process_time(double p_time) {
  106. pre_process_time = p_time;
  107. RS::get_singleton()->particles_set_pre_process_time(particles, pre_process_time);
  108. }
  109. void GPUParticles3D::set_explosiveness_ratio(real_t p_ratio) {
  110. explosiveness_ratio = p_ratio;
  111. RS::get_singleton()->particles_set_explosiveness_ratio(particles, explosiveness_ratio);
  112. }
  113. void GPUParticles3D::set_randomness_ratio(real_t p_ratio) {
  114. randomness_ratio = p_ratio;
  115. RS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio);
  116. }
  117. void GPUParticles3D::set_visibility_aabb(const AABB &p_aabb) {
  118. visibility_aabb = p_aabb;
  119. RS::get_singleton()->particles_set_custom_aabb(particles, visibility_aabb);
  120. update_gizmos();
  121. }
  122. void GPUParticles3D::set_use_local_coordinates(bool p_enable) {
  123. local_coords = p_enable;
  124. RS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords);
  125. }
  126. void GPUParticles3D::set_process_material(const Ref<Material> &p_material) {
  127. #ifdef TOOLS_ENABLED
  128. if (process_material.is_valid()) {
  129. if (Ref<ParticleProcessMaterial>(process_material).is_valid()) {
  130. process_material->disconnect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
  131. }
  132. }
  133. #endif
  134. process_material = p_material;
  135. RID material_rid;
  136. if (process_material.is_valid()) {
  137. material_rid = process_material->get_rid();
  138. #ifdef TOOLS_ENABLED
  139. if (Ref<ParticleProcessMaterial>(process_material).is_valid()) {
  140. process_material->connect("emission_shape_changed", callable_mp((Node3D *)this, &GPUParticles3D::update_gizmos));
  141. }
  142. #endif
  143. }
  144. RS::get_singleton()->particles_set_process_material(particles, material_rid);
  145. update_configuration_warnings();
  146. }
  147. void GPUParticles3D::set_speed_scale(double p_scale) {
  148. speed_scale = p_scale;
  149. RS::get_singleton()->particles_set_speed_scale(particles, p_scale);
  150. }
  151. void GPUParticles3D::set_collision_base_size(real_t p_size) {
  152. collision_base_size = p_size;
  153. RS::get_singleton()->particles_set_collision_base_size(particles, p_size);
  154. }
  155. bool GPUParticles3D::is_emitting() const {
  156. return emitting;
  157. }
  158. int GPUParticles3D::get_amount() const {
  159. return amount;
  160. }
  161. double GPUParticles3D::get_lifetime() const {
  162. return lifetime;
  163. }
  164. float GPUParticles3D::get_interp_to_end() const {
  165. return interp_to_end_factor;
  166. }
  167. bool GPUParticles3D::get_one_shot() const {
  168. return one_shot;
  169. }
  170. double GPUParticles3D::get_pre_process_time() const {
  171. return pre_process_time;
  172. }
  173. real_t GPUParticles3D::get_explosiveness_ratio() const {
  174. return explosiveness_ratio;
  175. }
  176. real_t GPUParticles3D::get_randomness_ratio() const {
  177. return randomness_ratio;
  178. }
  179. AABB GPUParticles3D::get_visibility_aabb() const {
  180. return visibility_aabb;
  181. }
  182. bool GPUParticles3D::get_use_local_coordinates() const {
  183. return local_coords;
  184. }
  185. Ref<Material> GPUParticles3D::get_process_material() const {
  186. return process_material;
  187. }
  188. double GPUParticles3D::get_speed_scale() const {
  189. return speed_scale;
  190. }
  191. real_t GPUParticles3D::get_collision_base_size() const {
  192. return collision_base_size;
  193. }
  194. void GPUParticles3D::set_draw_order(DrawOrder p_order) {
  195. draw_order = p_order;
  196. RS::get_singleton()->particles_set_draw_order(particles, RS::ParticlesDrawOrder(p_order));
  197. }
  198. void GPUParticles3D::set_trail_enabled(bool p_enabled) {
  199. trail_enabled = p_enabled;
  200. RS::get_singleton()->particles_set_trails(particles, trail_enabled, trail_lifetime);
  201. update_configuration_warnings();
  202. }
  203. void GPUParticles3D::set_trail_lifetime(double p_seconds) {
  204. ERR_FAIL_COND(p_seconds < 0.01);
  205. trail_lifetime = p_seconds;
  206. RS::get_singleton()->particles_set_trails(particles, trail_enabled, trail_lifetime);
  207. }
  208. bool GPUParticles3D::is_trail_enabled() const {
  209. return trail_enabled;
  210. }
  211. double GPUParticles3D::get_trail_lifetime() const {
  212. return trail_lifetime;
  213. }
  214. GPUParticles3D::DrawOrder GPUParticles3D::get_draw_order() const {
  215. return draw_order;
  216. }
  217. void GPUParticles3D::set_draw_passes(int p_count) {
  218. ERR_FAIL_COND(p_count < 1);
  219. for (int i = p_count; i < draw_passes.size(); i++) {
  220. set_draw_pass_mesh(i, Ref<Mesh>());
  221. }
  222. draw_passes.resize(p_count);
  223. RS::get_singleton()->particles_set_draw_passes(particles, p_count);
  224. notify_property_list_changed();
  225. }
  226. int GPUParticles3D::get_draw_passes() const {
  227. return draw_passes.size();
  228. }
  229. void GPUParticles3D::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) {
  230. ERR_FAIL_INDEX(p_pass, draw_passes.size());
  231. if (Engine::get_singleton()->is_editor_hint() && draw_passes.write[p_pass].is_valid()) {
  232. draw_passes.write[p_pass]->disconnect_changed(callable_mp((Node *)this, &Node::update_configuration_warnings));
  233. }
  234. draw_passes.write[p_pass] = p_mesh;
  235. if (Engine::get_singleton()->is_editor_hint() && draw_passes.write[p_pass].is_valid()) {
  236. draw_passes.write[p_pass]->connect_changed(callable_mp((Node *)this, &Node::update_configuration_warnings), CONNECT_DEFERRED);
  237. }
  238. RID mesh_rid;
  239. if (p_mesh.is_valid()) {
  240. mesh_rid = p_mesh->get_rid();
  241. }
  242. RS::get_singleton()->particles_set_draw_pass_mesh(particles, p_pass, mesh_rid);
  243. _skinning_changed();
  244. update_configuration_warnings();
  245. }
  246. Ref<Mesh> GPUParticles3D::get_draw_pass_mesh(int p_pass) const {
  247. ERR_FAIL_INDEX_V(p_pass, draw_passes.size(), Ref<Mesh>());
  248. return draw_passes[p_pass];
  249. }
  250. void GPUParticles3D::set_fixed_fps(int p_count) {
  251. fixed_fps = p_count;
  252. RS::get_singleton()->particles_set_fixed_fps(particles, p_count);
  253. }
  254. int GPUParticles3D::get_fixed_fps() const {
  255. return fixed_fps;
  256. }
  257. void GPUParticles3D::set_fractional_delta(bool p_enable) {
  258. fractional_delta = p_enable;
  259. RS::get_singleton()->particles_set_fractional_delta(particles, p_enable);
  260. }
  261. bool GPUParticles3D::get_fractional_delta() const {
  262. return fractional_delta;
  263. }
  264. void GPUParticles3D::set_interpolate(bool p_enable) {
  265. interpolate = p_enable;
  266. RS::get_singleton()->particles_set_interpolate(particles, p_enable);
  267. }
  268. bool GPUParticles3D::get_interpolate() const {
  269. return interpolate;
  270. }
  271. PackedStringArray GPUParticles3D::get_configuration_warnings() const {
  272. PackedStringArray warnings = GeometryInstance3D::get_configuration_warnings();
  273. bool meshes_found = false;
  274. bool anim_material_found = false;
  275. for (int i = 0; i < draw_passes.size(); i++) {
  276. if (draw_passes[i].is_valid()) {
  277. meshes_found = true;
  278. for (int j = 0; j < draw_passes[i]->get_surface_count(); j++) {
  279. anim_material_found = Object::cast_to<ShaderMaterial>(draw_passes[i]->surface_get_material(j).ptr()) != nullptr;
  280. BaseMaterial3D *spat = Object::cast_to<BaseMaterial3D>(draw_passes[i]->surface_get_material(j).ptr());
  281. anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
  282. }
  283. if (anim_material_found) {
  284. break;
  285. }
  286. }
  287. }
  288. anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != nullptr;
  289. {
  290. BaseMaterial3D *spat = Object::cast_to<BaseMaterial3D>(get_material_override().ptr());
  291. anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == BaseMaterial3D::BILLBOARD_PARTICLES);
  292. }
  293. if (!meshes_found) {
  294. warnings.push_back(RTR("Nothing is visible because meshes have not been assigned to draw passes."));
  295. }
  296. if (process_material.is_null()) {
  297. warnings.push_back(RTR("A material to process the particles is not assigned, so no behavior is imprinted."));
  298. } else {
  299. const ParticleProcessMaterial *process = Object::cast_to<ParticleProcessMaterial>(process_material.ptr());
  300. if (!anim_material_found && process &&
  301. (process->get_param_max(ParticleProcessMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param_max(ParticleProcessMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
  302. process->get_param_texture(ParticleProcessMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticleProcessMaterial::PARAM_ANIM_OFFSET).is_valid())) {
  303. warnings.push_back(RTR("Particles animation requires the usage of a BaseMaterial3D whose Billboard Mode is set to \"Particle Billboard\"."));
  304. }
  305. }
  306. if (trail_enabled) {
  307. int dp_count = 0;
  308. bool missing_trails = false;
  309. bool no_materials = false;
  310. for (int i = 0; i < draw_passes.size(); i++) {
  311. Ref<Mesh> draw_pass = draw_passes[i];
  312. if (draw_pass.is_valid() && draw_pass->get_builtin_bind_pose_count() > 0) {
  313. dp_count++;
  314. }
  315. if (draw_pass.is_valid()) {
  316. int mats_found = 0;
  317. for (int j = 0; j < draw_passes[i]->get_surface_count(); j++) {
  318. BaseMaterial3D *spat = Object::cast_to<BaseMaterial3D>(draw_passes[i]->surface_get_material(j).ptr());
  319. if (spat) {
  320. mats_found++;
  321. }
  322. if (spat && !spat->get_flag(BaseMaterial3D::FLAG_PARTICLE_TRAILS_MODE)) {
  323. missing_trails = true;
  324. }
  325. }
  326. if (mats_found != draw_passes[i]->get_surface_count()) {
  327. no_materials = true;
  328. }
  329. }
  330. }
  331. BaseMaterial3D *spat = Object::cast_to<BaseMaterial3D>(get_material_override().ptr());
  332. if (spat) {
  333. no_materials = false;
  334. }
  335. if (spat && !spat->get_flag(BaseMaterial3D::FLAG_PARTICLE_TRAILS_MODE)) {
  336. missing_trails = true;
  337. }
  338. if (dp_count && skin.is_valid()) {
  339. warnings.push_back(RTR("Using Trail meshes with a skin causes Skin to override Trail poses. Suggest removing the Skin."));
  340. } else if (dp_count == 0 && skin.is_null()) {
  341. warnings.push_back(RTR("Trails active, but neither Trail meshes or a Skin were found."));
  342. } else if (dp_count > 1) {
  343. warnings.push_back(RTR("Only one Trail mesh is supported. If you want to use more than a single mesh, a Skin is needed (see documentation)."));
  344. }
  345. if ((dp_count || skin.is_valid()) && (missing_trails || no_materials)) {
  346. warnings.push_back(RTR("Trails enabled, but one or more mesh materials are either missing or not set for trails rendering."));
  347. }
  348. if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
  349. warnings.push_back(RTR("Particle trails are only available when using the Forward+ or Mobile renderers."));
  350. }
  351. }
  352. if (sub_emitter != NodePath() && OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
  353. warnings.push_back(RTR("Particle sub-emitters are only available when using the Forward+ or Mobile renderers."));
  354. }
  355. return warnings;
  356. }
  357. void GPUParticles3D::restart(bool p_keep_seed) {
  358. if (!p_keep_seed && !use_fixed_seed) {
  359. set_seed(Math::rand());
  360. }
  361. RenderingServer::get_singleton()->particles_restart(particles);
  362. RenderingServer::get_singleton()->particles_set_emitting(particles, true);
  363. emitting = true;
  364. active = true;
  365. signal_canceled = false;
  366. time = 0;
  367. emission_time = lifetime * (1 - explosiveness_ratio);
  368. active_time = lifetime * (2 - explosiveness_ratio);
  369. set_process_internal(true);
  370. }
  371. AABB GPUParticles3D::capture_aabb() const {
  372. return RS::get_singleton()->particles_get_current_aabb(particles);
  373. }
  374. void GPUParticles3D::_validate_property(PropertyInfo &p_property) const {
  375. if (p_property.name == "emitting") {
  376. p_property.hint = one_shot ? PROPERTY_HINT_ONESHOT : PROPERTY_HINT_NONE;
  377. }
  378. if (p_property.name.begins_with("draw_pass_")) {
  379. int index = p_property.name.get_slicec('_', 2).to_int() - 1;
  380. if (index >= draw_passes.size()) {
  381. p_property.usage = PROPERTY_USAGE_NONE;
  382. return;
  383. }
  384. }
  385. if (p_property.name == "seed" && !use_fixed_seed) {
  386. p_property.usage = PROPERTY_USAGE_NONE;
  387. }
  388. }
  389. void GPUParticles3D::request_particles_process(real_t p_requested_process_time) {
  390. RS::get_singleton()->particles_request_process_time(particles, p_requested_process_time);
  391. }
  392. void GPUParticles3D::emit_particle(const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags) {
  393. RS::get_singleton()->particles_emit(particles, p_transform, p_velocity, p_color, p_custom, p_emit_flags);
  394. }
  395. void GPUParticles3D::_attach_sub_emitter() {
  396. Node *n = get_node_or_null(sub_emitter);
  397. if (n) {
  398. GPUParticles3D *sen = Object::cast_to<GPUParticles3D>(n);
  399. if (sen && sen != this) {
  400. RS::get_singleton()->particles_set_subemitter(particles, sen->particles);
  401. }
  402. }
  403. }
  404. void GPUParticles3D::set_sub_emitter(const NodePath &p_path) {
  405. if (is_inside_tree()) {
  406. RS::get_singleton()->particles_set_subemitter(particles, RID());
  407. }
  408. sub_emitter = p_path;
  409. if (is_inside_tree() && sub_emitter != NodePath()) {
  410. _attach_sub_emitter();
  411. }
  412. update_configuration_warnings();
  413. }
  414. NodePath GPUParticles3D::get_sub_emitter() const {
  415. return sub_emitter;
  416. }
  417. void GPUParticles3D::_notification(int p_what) {
  418. switch (p_what) {
  419. // Use internal process when emitting and one_shot is on so that when
  420. // the shot ends the editor can properly update.
  421. case NOTIFICATION_INTERNAL_PROCESS: {
  422. const Vector3 velocity = (get_global_position() - previous_position) / get_process_delta_time();
  423. if (velocity != previous_velocity) {
  424. RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
  425. previous_velocity = velocity;
  426. }
  427. previous_position = get_global_position();
  428. if (one_shot) {
  429. time += get_process_delta_time();
  430. if (time > emission_time) {
  431. emitting = false;
  432. if (!active) {
  433. set_process_internal(false);
  434. }
  435. }
  436. if (time > active_time) {
  437. if (active && !signal_canceled) {
  438. emit_signal(SceneStringName(finished));
  439. }
  440. active = false;
  441. if (!emitting) {
  442. set_process_internal(false);
  443. }
  444. }
  445. }
  446. } break;
  447. case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
  448. // Update velocity in physics process, so that velocity calculations remain correct
  449. // if the physics tick rate is lower than the rendered framerate (especially without physics interpolation).
  450. const Vector3 velocity = (get_global_position() - previous_position) / get_physics_process_delta_time();
  451. if (velocity != previous_velocity) {
  452. RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
  453. previous_velocity = velocity;
  454. }
  455. previous_position = get_global_position();
  456. } break;
  457. case NOTIFICATION_ENTER_TREE: {
  458. set_process_internal(false);
  459. set_physics_process_internal(false);
  460. if (sub_emitter != NodePath()) {
  461. _attach_sub_emitter();
  462. }
  463. if (can_process()) {
  464. RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
  465. } else {
  466. RS::get_singleton()->particles_set_speed_scale(particles, 0);
  467. }
  468. previous_position = get_global_transform().origin;
  469. set_process_internal(true);
  470. set_physics_process_internal(true);
  471. } break;
  472. case NOTIFICATION_EXIT_TREE: {
  473. RS::get_singleton()->particles_set_subemitter(particles, RID());
  474. } break;
  475. case NOTIFICATION_SUSPENDED:
  476. case NOTIFICATION_UNSUSPENDED:
  477. case NOTIFICATION_PAUSED:
  478. case NOTIFICATION_UNPAUSED: {
  479. if (is_inside_tree()) {
  480. if (can_process()) {
  481. RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
  482. } else {
  483. RS::get_singleton()->particles_set_speed_scale(particles, 0);
  484. }
  485. }
  486. } break;
  487. case NOTIFICATION_VISIBILITY_CHANGED: {
  488. // Make sure particles are updated before rendering occurs if they were active before.
  489. if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) {
  490. RS::get_singleton()->particles_request_process(particles);
  491. }
  492. } break;
  493. }
  494. }
  495. void GPUParticles3D::_skinning_changed() {
  496. Vector<Transform3D> xforms;
  497. if (skin.is_valid()) {
  498. xforms.resize(skin->get_bind_count());
  499. for (int i = 0; i < skin->get_bind_count(); i++) {
  500. xforms.write[i] = skin->get_bind_pose(i);
  501. }
  502. } else {
  503. for (int i = 0; i < draw_passes.size(); i++) {
  504. Ref<Mesh> draw_pass = draw_passes[i];
  505. if (draw_pass.is_valid() && draw_pass->get_builtin_bind_pose_count() > 0) {
  506. xforms.resize(draw_pass->get_builtin_bind_pose_count());
  507. for (int j = 0; j < draw_pass->get_builtin_bind_pose_count(); j++) {
  508. xforms.write[j] = draw_pass->get_builtin_bind_pose(j);
  509. }
  510. break;
  511. }
  512. }
  513. }
  514. RS::get_singleton()->particles_set_trail_bind_poses(particles, xforms);
  515. update_configuration_warnings();
  516. }
  517. void GPUParticles3D::set_skin(const Ref<Skin> &p_skin) {
  518. skin = p_skin;
  519. _skinning_changed();
  520. }
  521. Ref<Skin> GPUParticles3D::get_skin() const {
  522. return skin;
  523. }
  524. void GPUParticles3D::set_transform_align(TransformAlign p_align) {
  525. ERR_FAIL_INDEX(uint32_t(p_align), 4);
  526. transform_align = p_align;
  527. RS::get_singleton()->particles_set_transform_align(particles, RS::ParticlesTransformAlign(transform_align));
  528. }
  529. GPUParticles3D::TransformAlign GPUParticles3D::get_transform_align() const {
  530. return transform_align;
  531. }
  532. void GPUParticles3D::convert_from_particles(Node *p_particles) {
  533. CPUParticles3D *cpu_particles = Object::cast_to<CPUParticles3D>(p_particles);
  534. ERR_FAIL_NULL_MSG(cpu_particles, "Only CPUParticles3D nodes can be converted to GPUParticles3D.");
  535. set_emitting(cpu_particles->is_emitting());
  536. set_amount(cpu_particles->get_amount());
  537. set_lifetime(cpu_particles->get_lifetime());
  538. set_one_shot(cpu_particles->get_one_shot());
  539. set_pre_process_time(cpu_particles->get_pre_process_time());
  540. set_explosiveness_ratio(cpu_particles->get_explosiveness_ratio());
  541. set_randomness_ratio(cpu_particles->get_randomness_ratio());
  542. set_use_local_coordinates(cpu_particles->get_use_local_coordinates());
  543. set_fixed_fps(cpu_particles->get_fixed_fps());
  544. set_fractional_delta(cpu_particles->get_fractional_delta());
  545. set_speed_scale(cpu_particles->get_speed_scale());
  546. set_draw_order(DrawOrder(cpu_particles->get_draw_order()));
  547. set_draw_pass_mesh(0, cpu_particles->get_mesh());
  548. Ref<ParticleProcessMaterial> proc_mat = memnew(ParticleProcessMaterial);
  549. set_process_material(proc_mat);
  550. proc_mat->set_direction(cpu_particles->get_direction());
  551. proc_mat->set_spread(cpu_particles->get_spread());
  552. proc_mat->set_flatness(cpu_particles->get_flatness());
  553. proc_mat->set_color(cpu_particles->get_color());
  554. Ref<Gradient> grad = cpu_particles->get_color_ramp();
  555. if (grad.is_valid()) {
  556. Ref<GradientTexture1D> tex = memnew(GradientTexture1D);
  557. tex->set_gradient(grad);
  558. proc_mat->set_color_ramp(tex);
  559. }
  560. Ref<Gradient> grad_init = cpu_particles->get_color_initial_ramp();
  561. if (grad_init.is_valid()) {
  562. Ref<GradientTexture1D> tex = memnew(GradientTexture1D);
  563. tex->set_gradient(grad_init);
  564. proc_mat->set_color_initial_ramp(tex);
  565. }
  566. proc_mat->set_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY, cpu_particles->get_particle_flag(CPUParticles3D::PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY));
  567. proc_mat->set_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_ROTATE_Y, cpu_particles->get_particle_flag(CPUParticles3D::PARTICLE_FLAG_ROTATE_Y));
  568. proc_mat->set_particle_flag(ParticleProcessMaterial::PARTICLE_FLAG_DISABLE_Z, cpu_particles->get_particle_flag(CPUParticles3D::PARTICLE_FLAG_DISABLE_Z));
  569. proc_mat->set_emission_shape(ParticleProcessMaterial::EmissionShape(cpu_particles->get_emission_shape()));
  570. proc_mat->set_emission_sphere_radius(cpu_particles->get_emission_sphere_radius());
  571. proc_mat->set_emission_box_extents(cpu_particles->get_emission_box_extents());
  572. proc_mat->set_emission_ring_height(cpu_particles->get_emission_ring_height());
  573. proc_mat->set_emission_ring_radius(cpu_particles->get_emission_ring_radius());
  574. proc_mat->set_emission_ring_inner_radius(cpu_particles->get_emission_ring_inner_radius());
  575. proc_mat->set_emission_ring_cone_angle(cpu_particles->get_emission_ring_cone_angle());
  576. if (cpu_particles->get_split_scale()) {
  577. Ref<CurveXYZTexture> scale3D = memnew(CurveXYZTexture);
  578. scale3D->set_curve_x(cpu_particles->get_scale_curve_x());
  579. scale3D->set_curve_y(cpu_particles->get_scale_curve_y());
  580. scale3D->set_curve_z(cpu_particles->get_scale_curve_z());
  581. proc_mat->set_param_texture(ParticleProcessMaterial::PARAM_SCALE, scale3D);
  582. }
  583. proc_mat->set_gravity(cpu_particles->get_gravity());
  584. proc_mat->set_lifetime_randomness(cpu_particles->get_lifetime_randomness());
  585. #define CONVERT_PARAM(m_param) \
  586. proc_mat->set_param_min(ParticleProcessMaterial::m_param, cpu_particles->get_param_min(CPUParticles3D::m_param)); \
  587. { \
  588. Ref<Curve> curve = cpu_particles->get_param_curve(CPUParticles3D::m_param); \
  589. if (curve.is_valid()) { \
  590. Ref<CurveTexture> tex = memnew(CurveTexture); \
  591. tex->set_curve(curve); \
  592. proc_mat->set_param_texture(ParticleProcessMaterial::m_param, tex); \
  593. } \
  594. } \
  595. proc_mat->set_param_max(ParticleProcessMaterial::m_param, cpu_particles->get_param_max(CPUParticles3D::m_param));
  596. CONVERT_PARAM(PARAM_INITIAL_LINEAR_VELOCITY);
  597. CONVERT_PARAM(PARAM_ANGULAR_VELOCITY);
  598. CONVERT_PARAM(PARAM_ORBIT_VELOCITY);
  599. CONVERT_PARAM(PARAM_LINEAR_ACCEL);
  600. CONVERT_PARAM(PARAM_RADIAL_ACCEL);
  601. CONVERT_PARAM(PARAM_TANGENTIAL_ACCEL);
  602. CONVERT_PARAM(PARAM_DAMPING);
  603. CONVERT_PARAM(PARAM_ANGLE);
  604. CONVERT_PARAM(PARAM_SCALE);
  605. CONVERT_PARAM(PARAM_HUE_VARIATION);
  606. CONVERT_PARAM(PARAM_ANIM_SPEED);
  607. CONVERT_PARAM(PARAM_ANIM_OFFSET);
  608. #undef CONVERT_PARAM
  609. }
  610. void GPUParticles3D::set_amount_ratio(float p_ratio) {
  611. amount_ratio = p_ratio;
  612. RS::get_singleton()->particles_set_amount_ratio(particles, p_ratio);
  613. }
  614. float GPUParticles3D::get_amount_ratio() const {
  615. return amount_ratio;
  616. }
  617. void GPUParticles3D::_bind_methods() {
  618. ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &GPUParticles3D::set_emitting);
  619. ClassDB::bind_method(D_METHOD("set_amount", "amount"), &GPUParticles3D::set_amount);
  620. ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &GPUParticles3D::set_lifetime);
  621. ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &GPUParticles3D::set_one_shot);
  622. ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &GPUParticles3D::set_pre_process_time);
  623. ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &GPUParticles3D::set_explosiveness_ratio);
  624. ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &GPUParticles3D::set_randomness_ratio);
  625. ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &GPUParticles3D::set_visibility_aabb);
  626. ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &GPUParticles3D::set_use_local_coordinates);
  627. ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &GPUParticles3D::set_fixed_fps);
  628. ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &GPUParticles3D::set_fractional_delta);
  629. ClassDB::bind_method(D_METHOD("set_interpolate", "enable"), &GPUParticles3D::set_interpolate);
  630. ClassDB::bind_method(D_METHOD("set_process_material", "material"), &GPUParticles3D::set_process_material);
  631. ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &GPUParticles3D::set_speed_scale);
  632. ClassDB::bind_method(D_METHOD("set_collision_base_size", "size"), &GPUParticles3D::set_collision_base_size);
  633. ClassDB::bind_method(D_METHOD("set_interp_to_end", "interp"), &GPUParticles3D::set_interp_to_end);
  634. ClassDB::bind_method(D_METHOD("is_emitting"), &GPUParticles3D::is_emitting);
  635. ClassDB::bind_method(D_METHOD("get_amount"), &GPUParticles3D::get_amount);
  636. ClassDB::bind_method(D_METHOD("get_lifetime"), &GPUParticles3D::get_lifetime);
  637. ClassDB::bind_method(D_METHOD("get_one_shot"), &GPUParticles3D::get_one_shot);
  638. ClassDB::bind_method(D_METHOD("get_pre_process_time"), &GPUParticles3D::get_pre_process_time);
  639. ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &GPUParticles3D::get_explosiveness_ratio);
  640. ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &GPUParticles3D::get_randomness_ratio);
  641. ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &GPUParticles3D::get_visibility_aabb);
  642. ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &GPUParticles3D::get_use_local_coordinates);
  643. ClassDB::bind_method(D_METHOD("get_fixed_fps"), &GPUParticles3D::get_fixed_fps);
  644. ClassDB::bind_method(D_METHOD("get_fractional_delta"), &GPUParticles3D::get_fractional_delta);
  645. ClassDB::bind_method(D_METHOD("get_interpolate"), &GPUParticles3D::get_interpolate);
  646. ClassDB::bind_method(D_METHOD("get_process_material"), &GPUParticles3D::get_process_material);
  647. ClassDB::bind_method(D_METHOD("get_speed_scale"), &GPUParticles3D::get_speed_scale);
  648. ClassDB::bind_method(D_METHOD("get_collision_base_size"), &GPUParticles3D::get_collision_base_size);
  649. ClassDB::bind_method(D_METHOD("get_interp_to_end"), &GPUParticles3D::get_interp_to_end);
  650. ClassDB::bind_method(D_METHOD("set_use_fixed_seed", "use_fixed_seed"), &GPUParticles3D::set_use_fixed_seed);
  651. ClassDB::bind_method(D_METHOD("get_use_fixed_seed"), &GPUParticles3D::get_use_fixed_seed);
  652. ClassDB::bind_method(D_METHOD("set_seed", "seed"), &GPUParticles3D::set_seed);
  653. ClassDB::bind_method(D_METHOD("get_seed"), &GPUParticles3D::get_seed);
  654. ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &GPUParticles3D::set_draw_order);
  655. ClassDB::bind_method(D_METHOD("get_draw_order"), &GPUParticles3D::get_draw_order);
  656. ClassDB::bind_method(D_METHOD("set_draw_passes", "passes"), &GPUParticles3D::set_draw_passes);
  657. ClassDB::bind_method(D_METHOD("set_draw_pass_mesh", "pass", "mesh"), &GPUParticles3D::set_draw_pass_mesh);
  658. ClassDB::bind_method(D_METHOD("get_draw_passes"), &GPUParticles3D::get_draw_passes);
  659. ClassDB::bind_method(D_METHOD("get_draw_pass_mesh", "pass"), &GPUParticles3D::get_draw_pass_mesh);
  660. ClassDB::bind_method(D_METHOD("set_skin", "skin"), &GPUParticles3D::set_skin);
  661. ClassDB::bind_method(D_METHOD("get_skin"), &GPUParticles3D::get_skin);
  662. ClassDB::bind_method(D_METHOD("restart", "keep_seed"), &GPUParticles3D::restart, DEFVAL(false));
  663. ClassDB::bind_method(D_METHOD("capture_aabb"), &GPUParticles3D::capture_aabb);
  664. ClassDB::bind_method(D_METHOD("set_sub_emitter", "path"), &GPUParticles3D::set_sub_emitter);
  665. ClassDB::bind_method(D_METHOD("get_sub_emitter"), &GPUParticles3D::get_sub_emitter);
  666. ClassDB::bind_method(D_METHOD("emit_particle", "xform", "velocity", "color", "custom", "flags"), &GPUParticles3D::emit_particle);
  667. ClassDB::bind_method(D_METHOD("set_trail_enabled", "enabled"), &GPUParticles3D::set_trail_enabled);
  668. ClassDB::bind_method(D_METHOD("set_trail_lifetime", "secs"), &GPUParticles3D::set_trail_lifetime);
  669. ClassDB::bind_method(D_METHOD("is_trail_enabled"), &GPUParticles3D::is_trail_enabled);
  670. ClassDB::bind_method(D_METHOD("get_trail_lifetime"), &GPUParticles3D::get_trail_lifetime);
  671. ClassDB::bind_method(D_METHOD("set_transform_align", "align"), &GPUParticles3D::set_transform_align);
  672. ClassDB::bind_method(D_METHOD("get_transform_align"), &GPUParticles3D::get_transform_align);
  673. ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &GPUParticles3D::convert_from_particles);
  674. ClassDB::bind_method(D_METHOD("set_amount_ratio", "ratio"), &GPUParticles3D::set_amount_ratio);
  675. ClassDB::bind_method(D_METHOD("get_amount_ratio"), &GPUParticles3D::get_amount_ratio);
  676. ClassDB::bind_method(D_METHOD("request_particles_process", "process_time"), &GPUParticles3D::request_particles_process);
  677. ADD_SIGNAL(MethodInfo("finished"));
  678. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting", PROPERTY_HINT_ONESHOT), "set_emitting", "is_emitting");
  679. ADD_PROPERTY_DEFAULT("emitting", true); // Workaround for doctool in headless mode, as dummy rasterizer always returns false.
  680. ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); // FIXME: Evaluate support for `exp` in integer properties, or remove this.
  681. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "amount_ratio", PROPERTY_HINT_RANGE, "0,1,0.0001"), "set_amount_ratio", "get_amount_ratio");
  682. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "sub_emitter", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GPUParticles3D"), "set_sub_emitter", "get_sub_emitter");
  683. ADD_GROUP("Time", "");
  684. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater,exp,suffix:s"), "set_lifetime", "get_lifetime");
  685. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "interp_to_end", PROPERTY_HINT_RANGE, "0.00,1.0,0.01"), "set_interp_to_end", "get_interp_to_end");
  686. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "get_one_shot");
  687. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "preprocess", PROPERTY_HINT_RANGE, "0.00,10.0,0.01,or_greater,exp,suffix:s"), "set_pre_process_time", "get_pre_process_time");
  688. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
  689. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
  690. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
  691. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_fixed_seed"), "set_use_fixed_seed", "get_use_fixed_seed");
  692. ADD_PROPERTY(PropertyInfo(Variant::INT, "seed", PROPERTY_HINT_RANGE, "0," + itos(UINT32_MAX) + ",1"), "set_seed", "get_seed");
  693. ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1,suffix:FPS"), "set_fixed_fps", "get_fixed_fps");
  694. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interpolate"), "set_interpolate", "get_interpolate");
  695. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
  696. ADD_GROUP("Collision", "collision_");
  697. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_base_size", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater,suffix:m"), "set_collision_base_size", "get_collision_base_size");
  698. ADD_GROUP("Drawing", "");
  699. ADD_PROPERTY(PropertyInfo(Variant::AABB, "visibility_aabb", PROPERTY_HINT_NONE, "suffix:m"), "set_visibility_aabb", "get_visibility_aabb");
  700. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
  701. ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime,Reverse Lifetime,View Depth"), "set_draw_order", "get_draw_order");
  702. ADD_PROPERTY(PropertyInfo(Variant::INT, "transform_align", PROPERTY_HINT_ENUM, "Disabled,Z-Billboard,Y to Velocity,Z-Billboard + Y to Velocity"), "set_transform_align", "get_transform_align");
  703. ADD_GROUP("Trails", "trail_");
  704. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "trail_enabled"), "set_trail_enabled", "is_trail_enabled");
  705. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "trail_lifetime", PROPERTY_HINT_RANGE, "0.01,10,0.01,or_greater,suffix:s"), "set_trail_lifetime", "get_trail_lifetime");
  706. ADD_GROUP("Process Material", "");
  707. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "process_material", PROPERTY_HINT_RESOURCE_TYPE, "ParticleProcessMaterial,ShaderMaterial"), "set_process_material", "get_process_material");
  708. ADD_GROUP("Draw Passes", "draw_");
  709. ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_passes", PROPERTY_HINT_RANGE, "0," + itos(MAX_DRAW_PASSES) + ",1"), "set_draw_passes", "get_draw_passes");
  710. for (int i = 0; i < MAX_DRAW_PASSES; i++) {
  711. ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "draw_pass_" + itos(i + 1), PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_draw_pass_mesh", "get_draw_pass_mesh", i);
  712. }
  713. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "draw_skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
  714. BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX);
  715. BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME);
  716. BIND_ENUM_CONSTANT(DRAW_ORDER_REVERSE_LIFETIME);
  717. BIND_ENUM_CONSTANT(DRAW_ORDER_VIEW_DEPTH);
  718. BIND_ENUM_CONSTANT(EMIT_FLAG_POSITION);
  719. BIND_ENUM_CONSTANT(EMIT_FLAG_ROTATION_SCALE);
  720. BIND_ENUM_CONSTANT(EMIT_FLAG_VELOCITY);
  721. BIND_ENUM_CONSTANT(EMIT_FLAG_COLOR);
  722. BIND_ENUM_CONSTANT(EMIT_FLAG_CUSTOM);
  723. BIND_CONSTANT(MAX_DRAW_PASSES);
  724. BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_DISABLED);
  725. BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_Z_BILLBOARD);
  726. BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_Y_TO_VELOCITY);
  727. BIND_ENUM_CONSTANT(TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY);
  728. ADD_PROPERTY_DEFAULT("seed", 0);
  729. }
  730. GPUParticles3D::GPUParticles3D() {
  731. particles = RS::get_singleton()->particles_create();
  732. RS::get_singleton()->particles_set_mode(particles, RS::PARTICLES_MODE_3D);
  733. set_base(particles);
  734. one_shot = false; // Needed so that set_emitting doesn't access uninitialized values
  735. set_emitting(true);
  736. set_one_shot(false);
  737. set_seed(Math::rand());
  738. set_amount_ratio(1.0);
  739. set_amount(8);
  740. set_lifetime(1);
  741. set_fixed_fps(30);
  742. set_fractional_delta(true);
  743. set_interpolate(true);
  744. set_pre_process_time(0);
  745. set_explosiveness_ratio(0);
  746. set_randomness_ratio(0);
  747. set_trail_lifetime(0.3);
  748. set_visibility_aabb(AABB(Vector3(-4, -4, -4), Vector3(8, 8, 8)));
  749. set_use_local_coordinates(false);
  750. set_draw_passes(1);
  751. set_draw_order(DRAW_ORDER_INDEX);
  752. set_speed_scale(1);
  753. set_collision_base_size(collision_base_size);
  754. set_transform_align(TRANSFORM_ALIGN_DISABLED);
  755. set_use_fixed_seed(false);
  756. }
  757. GPUParticles3D::~GPUParticles3D() {
  758. ERR_FAIL_NULL(RenderingServer::get_singleton());
  759. RS::get_singleton()->free(particles);
  760. }