gpu_particles_3d.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**************************************************************************/
  2. /* gpu_particles_3d.h */
  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. #pragma once
  31. #include "scene/3d/visual_instance_3d.h"
  32. #include "scene/resources/3d/skin.h"
  33. class GPUParticles3D : public GeometryInstance3D {
  34. private:
  35. GDCLASS(GPUParticles3D, GeometryInstance3D);
  36. public:
  37. enum DrawOrder {
  38. DRAW_ORDER_INDEX,
  39. DRAW_ORDER_LIFETIME,
  40. DRAW_ORDER_REVERSE_LIFETIME,
  41. DRAW_ORDER_VIEW_DEPTH,
  42. };
  43. enum TransformAlign {
  44. TRANSFORM_ALIGN_DISABLED,
  45. TRANSFORM_ALIGN_Z_BILLBOARD,
  46. TRANSFORM_ALIGN_Y_TO_VELOCITY,
  47. TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY
  48. };
  49. enum {
  50. MAX_DRAW_PASSES = 4
  51. };
  52. private:
  53. RID particles;
  54. bool emitting = false;
  55. bool active = false;
  56. bool signal_canceled = false;
  57. bool one_shot = false;
  58. int amount = 0;
  59. float amount_ratio = 1.0;
  60. double lifetime = 0.0;
  61. double pre_process_time = 0.0;
  62. real_t explosiveness_ratio = 0.0;
  63. real_t randomness_ratio = 0.0;
  64. double speed_scale = 0.0;
  65. AABB visibility_aabb;
  66. bool local_coords = false;
  67. int fixed_fps = 0;
  68. bool fractional_delta = false;
  69. bool interpolate = true;
  70. NodePath sub_emitter;
  71. real_t collision_base_size = 0.01;
  72. uint32_t seed = 0;
  73. bool use_fixed_seed = false;
  74. bool trail_enabled = false;
  75. double trail_lifetime = 0.3;
  76. TransformAlign transform_align = TRANSFORM_ALIGN_DISABLED;
  77. Ref<Material> process_material;
  78. DrawOrder draw_order = DRAW_ORDER_INDEX;
  79. Vector<Ref<Mesh>> draw_passes;
  80. Ref<Skin> skin;
  81. double time = 0.0;
  82. double emission_time = 0.0;
  83. double active_time = 0.0;
  84. float interp_to_end_factor = 0;
  85. Vector3 previous_velocity;
  86. Vector3 previous_position;
  87. void _attach_sub_emitter();
  88. void _skinning_changed();
  89. protected:
  90. static void _bind_methods();
  91. void _notification(int p_what);
  92. void _validate_property(PropertyInfo &p_property) const;
  93. #ifndef DISABLE_DEPRECATED
  94. void _restart_bind_compat_92089();
  95. static void _bind_compatibility_methods();
  96. #endif
  97. public:
  98. AABB get_aabb() const override;
  99. void set_emitting(bool p_emitting);
  100. void set_amount(int p_amount);
  101. void set_lifetime(double p_lifetime);
  102. void set_one_shot(bool p_one_shot);
  103. void set_pre_process_time(double p_time);
  104. void set_explosiveness_ratio(real_t p_ratio);
  105. void set_randomness_ratio(real_t p_ratio);
  106. void set_visibility_aabb(const AABB &p_aabb);
  107. void set_use_local_coordinates(bool p_enable);
  108. void set_process_material(const Ref<Material> &p_material);
  109. void set_speed_scale(double p_scale);
  110. void set_collision_base_size(real_t p_ratio);
  111. void set_trail_enabled(bool p_enabled);
  112. void set_trail_lifetime(double p_seconds);
  113. void set_interp_to_end(float p_interp);
  114. bool is_emitting() const;
  115. int get_amount() const;
  116. double get_lifetime() const;
  117. bool get_one_shot() const;
  118. double get_pre_process_time() const;
  119. real_t get_explosiveness_ratio() const;
  120. real_t get_randomness_ratio() const;
  121. AABB get_visibility_aabb() const;
  122. bool get_use_local_coordinates() const;
  123. Ref<Material> get_process_material() const;
  124. double get_speed_scale() const;
  125. real_t get_collision_base_size() const;
  126. bool is_trail_enabled() const;
  127. double get_trail_lifetime() const;
  128. float get_interp_to_end() const;
  129. void set_amount_ratio(float p_ratio);
  130. float get_amount_ratio() const;
  131. void set_fixed_fps(int p_count);
  132. int get_fixed_fps() const;
  133. void set_fractional_delta(bool p_enable);
  134. bool get_fractional_delta() const;
  135. void set_interpolate(bool p_enable);
  136. bool get_interpolate() const;
  137. void set_draw_order(DrawOrder p_order);
  138. DrawOrder get_draw_order() const;
  139. void set_draw_passes(int p_count);
  140. int get_draw_passes() const;
  141. void set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh);
  142. Ref<Mesh> get_draw_pass_mesh(int p_pass) const;
  143. PackedStringArray get_configuration_warnings() const override;
  144. void set_sub_emitter(const NodePath &p_path);
  145. NodePath get_sub_emitter() const;
  146. void set_skin(const Ref<Skin> &p_skin);
  147. Ref<Skin> get_skin() const;
  148. void set_transform_align(TransformAlign p_align);
  149. TransformAlign get_transform_align() const;
  150. void restart(bool p_keep_seed = false);
  151. void set_use_fixed_seed(bool p_use_fixed_seed);
  152. bool get_use_fixed_seed() const;
  153. void set_seed(uint32_t p_seed);
  154. uint32_t get_seed() const;
  155. void request_particles_process(real_t p_requested_process_time);
  156. enum EmitFlags {
  157. EMIT_FLAG_POSITION = RS::PARTICLES_EMIT_FLAG_POSITION,
  158. EMIT_FLAG_ROTATION_SCALE = RS::PARTICLES_EMIT_FLAG_ROTATION_SCALE,
  159. EMIT_FLAG_VELOCITY = RS::PARTICLES_EMIT_FLAG_VELOCITY,
  160. EMIT_FLAG_COLOR = RS::PARTICLES_EMIT_FLAG_COLOR,
  161. EMIT_FLAG_CUSTOM = RS::PARTICLES_EMIT_FLAG_CUSTOM
  162. };
  163. void emit_particle(const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags);
  164. AABB capture_aabb() const;
  165. void convert_from_particles(Node *p_particles);
  166. GPUParticles3D();
  167. ~GPUParticles3D();
  168. };
  169. VARIANT_ENUM_CAST(GPUParticles3D::DrawOrder)
  170. VARIANT_ENUM_CAST(GPUParticles3D::TransformAlign)
  171. VARIANT_ENUM_CAST(GPUParticles3D::EmitFlags)