gpu_particles_2d.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**************************************************************************/
  2. /* gpu_particles_2d.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. #ifndef GPU_PARTICLES_2D_H
  31. #define GPU_PARTICLES_2D_H
  32. #include "scene/2d/node_2d.h"
  33. class GPUParticles2D : public Node2D {
  34. private:
  35. GDCLASS(GPUParticles2D, Node2D);
  36. public:
  37. enum DrawOrder {
  38. DRAW_ORDER_INDEX,
  39. DRAW_ORDER_LIFETIME,
  40. DRAW_ORDER_REVERSE_LIFETIME,
  41. };
  42. private:
  43. RID particles;
  44. bool one_shot = false;
  45. int amount = 0;
  46. double lifetime = 0.0;
  47. double pre_process_time = 0.0;
  48. real_t explosiveness_ratio = 0.0;
  49. real_t randomness_ratio = 0.0;
  50. double speed_scale = 0.0;
  51. Rect2 visibility_rect;
  52. bool local_coords = false;
  53. int fixed_fps = 0;
  54. bool fractional_delta = false;
  55. bool interpolate = true;
  56. #ifdef TOOLS_ENABLED
  57. bool show_visibility_rect = false;
  58. #endif
  59. Ref<Material> process_material;
  60. DrawOrder draw_order = DRAW_ORDER_LIFETIME;
  61. Ref<Texture2D> texture;
  62. void _update_particle_emission_transform();
  63. NodePath sub_emitter;
  64. real_t collision_base_size = 1.0;
  65. bool trail_enabled = false;
  66. double trail_lifetime = 0.3;
  67. int trail_sections = 8;
  68. int trail_section_subdivisions = 4;
  69. RID mesh;
  70. void _attach_sub_emitter();
  71. void _texture_changed();
  72. protected:
  73. static void _bind_methods();
  74. void _validate_property(PropertyInfo &p_property) const;
  75. void _notification(int p_what);
  76. void _update_collision_size();
  77. public:
  78. void set_emitting(bool p_emitting);
  79. void set_amount(int p_amount);
  80. void set_lifetime(double p_lifetime);
  81. void set_one_shot(bool p_enable);
  82. void set_pre_process_time(double p_time);
  83. void set_explosiveness_ratio(real_t p_ratio);
  84. void set_randomness_ratio(real_t p_ratio);
  85. void set_visibility_rect(const Rect2 &p_visibility_rect);
  86. void set_use_local_coordinates(bool p_enable);
  87. void set_process_material(const Ref<Material> &p_material);
  88. void set_speed_scale(double p_scale);
  89. void set_collision_base_size(real_t p_ratio);
  90. void set_trail_enabled(bool p_enabled);
  91. void set_trail_lifetime(double p_seconds);
  92. void set_trail_sections(int p_sections);
  93. void set_trail_section_subdivisions(int p_subdivisions);
  94. #ifdef TOOLS_ENABLED
  95. void set_show_visibility_rect(bool p_show_visibility_rect);
  96. #endif
  97. bool is_emitting() const;
  98. int get_amount() const;
  99. double get_lifetime() const;
  100. bool get_one_shot() const;
  101. double get_pre_process_time() const;
  102. real_t get_explosiveness_ratio() const;
  103. real_t get_randomness_ratio() const;
  104. Rect2 get_visibility_rect() const;
  105. bool get_use_local_coordinates() const;
  106. Ref<Material> get_process_material() const;
  107. double get_speed_scale() const;
  108. real_t get_collision_base_size() const;
  109. bool is_trail_enabled() const;
  110. double get_trail_lifetime() const;
  111. int get_trail_sections() const;
  112. int get_trail_section_subdivisions() const;
  113. void set_fixed_fps(int p_count);
  114. int get_fixed_fps() const;
  115. void set_fractional_delta(bool p_enable);
  116. bool get_fractional_delta() const;
  117. void set_interpolate(bool p_enable);
  118. bool get_interpolate() const;
  119. void set_draw_order(DrawOrder p_order);
  120. DrawOrder get_draw_order() const;
  121. void set_texture(const Ref<Texture2D> &p_texture);
  122. Ref<Texture2D> get_texture() const;
  123. PackedStringArray get_configuration_warnings() const override;
  124. void set_sub_emitter(const NodePath &p_path);
  125. NodePath get_sub_emitter() const;
  126. enum EmitFlags {
  127. EMIT_FLAG_POSITION = RS::PARTICLES_EMIT_FLAG_POSITION,
  128. EMIT_FLAG_ROTATION_SCALE = RS::PARTICLES_EMIT_FLAG_ROTATION_SCALE,
  129. EMIT_FLAG_VELOCITY = RS::PARTICLES_EMIT_FLAG_VELOCITY,
  130. EMIT_FLAG_COLOR = RS::PARTICLES_EMIT_FLAG_COLOR,
  131. EMIT_FLAG_CUSTOM = RS::PARTICLES_EMIT_FLAG_CUSTOM
  132. };
  133. void emit_particle(const Transform2D &p_transform, const Vector2 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags);
  134. void restart();
  135. Rect2 capture_rect() const;
  136. GPUParticles2D();
  137. ~GPUParticles2D();
  138. };
  139. VARIANT_ENUM_CAST(GPUParticles2D::DrawOrder)
  140. VARIANT_ENUM_CAST(GPUParticles2D::EmitFlags)
  141. #endif // GPU_PARTICLES_2D_H