gpu_particles_3d.h 6.1 KB

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