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