Unravel Engine C++ Reference
Loading...
Searching...
No Matches
particle_emitter_component.h
Go to the documentation of this file.
1#pragma once
2
5#include <graphics/texture.h>
7#include <bx/easing.h>
8#include <math/math.h>
9#include <base/basetypes.hpp>
10#include <chrono>
11
12namespace unravel
13{
14
19class particle_emitter_component : public component_crtp<particle_emitter_component, owned_component>
20{
21public:
22 enum class culling_mode : uint8_t
23 {
26 };
27
28 static void on_create_component(entt::registry& r, entt::entity e);
29 static void on_destroy_component(entt::registry& r, entt::entity e);
30
31 void set_enabled(bool enabled);
32 auto is_enabled() const -> bool;
33
35 auto get_culling_mode() const -> culling_mode;
36
37 void set_last_render_frame(uint64_t frame);
38 auto get_last_render_frame() const noexcept -> uint64_t;
39 auto is_newly_created() const noexcept -> bool;
40 auto was_used_last_frame() const noexcept -> bool;
41
42 auto get_emitter_handle() const -> ps_soa::emitter_handle;
43
44 void set_shape(ps_soa::emitter_shape shape);
45 auto get_shape() const -> ps_soa::emitter_shape;
46
47 void set_direction(ps_soa::emitter_direction direction);
48 auto get_direction() const -> ps_soa::emitter_direction;
49
50 void set_spawn_location(ps_soa::spawn_location spawn_location);
51 auto get_spawn_location() const -> ps_soa::spawn_location;
52
53 void set_max_particles(uint32_t max_particles);
54 auto get_max_particles() const -> uint32_t;
55
56 void set_emission_lifetime(std::chrono::duration<float> lifetime);
57 auto get_emission_lifetime() const -> std::chrono::duration<float>;
58
59 void set_gravity_scale(float scale);
60 auto get_gravity_scale() const -> float;
61
62 void set_emission_rate(float emission_rate);
63 auto get_emission_rate() const -> float;
64
65 void set_temporal_motion(float temporal_motion);
66 auto get_temporal_motion() const -> float;
67
68 void set_velocity_damping(float velocity_damping);
69 auto get_velocity_damping() const -> float;
70
71 void set_force_over_lifetime(const math::vec3& force);
72 auto get_force_over_lifetime() const -> math::vec3;
73
74 void set_emission_shape_position(const math::vec3& position);
75 auto get_emission_shape_position() const -> math::vec3;
76
77 void set_emission_shape_scale(const math::vec3& scale);
78 auto get_emission_shape_scale() const -> math::vec3;
79
80 void set_size_by_speed_range(const frange_t& size_range);
81 auto get_size_by_speed_range() const -> const frange_t&;
82
83 void set_size_by_speed_velocity_range(const frange_t& velocity_range);
84 auto get_size_by_speed_velocity_range() const -> const frange_t&;
85
86 void set_color_by_speed_gradient(const math::gradient<math::color>& gradient);
87 auto get_color_by_speed_gradient() const -> const math::gradient<math::color>&;
88
89 void set_color_by_speed_velocity_range(const frange_t& velocity_range);
90 auto get_color_by_speed_velocity_range() const -> const frange_t&;
91
92 void set_lifetime_by_emitter_speed_gradient(const math::gradient<float>& gradient);
93 auto get_lifetime_by_emitter_speed_gradient() const -> const math::gradient<float>&;
94
95 void set_lifetime_by_emitter_speed_range(const frange_t& speed_range);
96 auto get_lifetime_by_emitter_speed_range() const -> const frange_t&;
97
98 void set_lifetime(std::chrono::duration<float> lifetime);
99 auto get_lifetime() const -> std::chrono::duration<float>;
100
101 void set_velocity_gradient(const math::gradient<frange_t>& gradient);
102 auto get_velocity_gradient() const -> const math::gradient<frange_t>&;
103
104 void set_scale_gradient(const math::gradient<frange_t>& gradient);
105 auto get_scale_gradient() const -> const math::gradient<frange_t>&;
106
107 void set_initial_scale_3d(const math::vec3& scale);
108 auto get_initial_scale_3d() const -> math::vec3;
109
110 void set_opacity(float opacity);
111 auto get_opacity() const -> float;
112
113 void set_color_intensity(float intensity);
114 auto get_color_intensity() const -> float;
115
116 void play();
117 void play_sub_emitters();
118 void stop();
119 void stop_sub_emitters();
120 void stop_and_reset();
122 void pause();
123 void pause_sub_emitters();
124 void resume();
125 void resume_sub_emitters();
126 auto is_playing() const -> bool;
127 auto is_paused() const -> bool;
128 auto is_stopped() const -> bool;
129
130 void set_loop(bool loop);
131 auto is_loop() const -> bool;
132
133 void set_start_delay(std::chrono::duration<float> delay);
134 auto get_start_delay() const -> std::chrono::duration<float>;
135
136 void set_align_to_direction(bool align);
137 auto get_align_to_direction() const -> bool;
138
139 void set_pivot(const math::vec2& pivot);
140 auto get_pivot() const -> math::vec2;
141
142 void set_color_gradient(const math::gradient<math::color>& gradient);
143 auto get_color_gradient() const -> const math::gradient<math::color>&;
144
145 void set_position_easing(bx::Easing::Enum easing);
146 auto get_position_easing() const -> bx::Easing::Enum;
147
148 void set_simulation_space(ps_soa::simulation_space space);
149 auto get_simulation_space() const -> ps_soa::simulation_space;
150
154 void set_simulation_backend(ps_soa::particle_sim_backend backend);
155 auto get_simulation_backend() const -> ps_soa::particle_sim_backend;
156
157 auto get_num_particles() const -> uint32_t;
158 auto get_world_bounds() const -> math::bbox;
159 auto get_updated_world_bounds(const math::transform& world_transform) const -> math::bbox;
160
161 void set_texture(const asset_handle<gfx::texture>& texture);
162 auto get_texture() const -> const asset_handle<gfx::texture>&;
163
164 void set_texture_mode(ps_soa::texture_mode mode);
165 auto get_texture_mode() const -> ps_soa::texture_mode;
166
167 void set_render_mode(ps_soa::render_mode mode);
168 auto get_render_mode() const -> ps_soa::render_mode;
169
170 void set_blend_mode(ps_soa::blend_mode mode);
171 auto get_blend_mode() const -> ps_soa::blend_mode;
172
173 void set_texture_sheet_tiles(math::vec2 tiles);
174 auto get_texture_sheet_tiles() const -> math::vec2;
175
176 void set_texture_sheet_cycles(float cycles);
177 auto get_texture_sheet_cycles() const -> float;
178
179 void set_texture_sheet_randomize(bool randomize);
180 auto get_texture_sheet_randomize() const -> bool;
181
182 void update_emitter(const math::transform& world_transform, delta_t dt);
183
184 auto get_desc() const -> const ps_soa::emitter_desc&;
185
186 void recreate_emitter();
187 void reset_emitter();
188
189private:
190 bool enabled_ = true;
192 uint64_t last_render_frame_ = 0;
193 ps_soa::emitter_shape shape_ = ps_soa::emitter_shape::sphere;
194 ps_soa::emitter_direction direction_ = ps_soa::emitter_direction::up;
195 uint32_t max_particles_ = 1024;
196 ps_soa::particle_sim_backend simulation_backend_ = ps_soa::particle_sim_backend::cpu;
197 ps_soa::emitter_handle emitter_handle_{};
198 ps_soa::emitter_desc desc_{};
199 ps_soa::emitter_transform_state transform_state_{};
201};
202
203} // namespace unravel
Component that wraps the soa particle system emitter.
auto get_texture() const -> const asset_handle< gfx::texture > &
auto get_desc() const -> const ps_soa::emitter_desc &
auto get_size_by_speed_range() const -> const frange_t &
void set_size_by_speed_range(const frange_t &size_range)
void set_color_by_speed_velocity_range(const frange_t &velocity_range)
auto get_color_by_speed_velocity_range() const -> const frange_t &
void set_texture(const asset_handle< gfx::texture > &texture)
void set_start_delay(std::chrono::duration< float > delay)
static void on_destroy_component(entt::registry &r, entt::entity e)
auto get_shape() const -> ps_soa::emitter_shape
auto get_emitter_handle() const -> ps_soa::emitter_handle
void set_spawn_location(ps_soa::spawn_location spawn_location)
auto get_render_mode() const -> ps_soa::render_mode
auto get_blend_mode() const -> ps_soa::blend_mode
auto get_start_delay() const -> std::chrono::duration< float >
void set_lifetime(std::chrono::duration< float > lifetime)
void update_emitter(const math::transform &world_transform, delta_t dt)
void set_simulation_space(ps_soa::simulation_space space)
void set_color_by_speed_gradient(const math::gradient< math::color > &gradient)
auto get_lifetime_by_emitter_speed_gradient() const -> const math::gradient< float > &
void set_size_by_speed_velocity_range(const frange_t &velocity_range)
void set_initial_scale_3d(const math::vec3 &scale)
auto get_texture_mode() const -> ps_soa::texture_mode
auto was_used_last_frame() const noexcept -> bool
void set_simulation_backend(ps_soa::particle_sim_backend backend)
CPU vs GPU particle pack/sim path for this emitter (artist-selectable).
void set_position_easing(bx::Easing::Enum easing)
auto get_scale_gradient() const -> const math::gradient< frange_t > &
void set_velocity_gradient(const math::gradient< frange_t > &gradient)
void set_force_over_lifetime(const math::vec3 &force)
void set_emission_shape_scale(const math::vec3 &scale)
void set_color_gradient(const math::gradient< math::color > &gradient)
void set_texture_mode(ps_soa::texture_mode mode)
auto get_color_by_speed_gradient() const -> const math::gradient< math::color > &
auto get_velocity_gradient() const -> const math::gradient< frange_t > &
auto get_lifetime() const -> std::chrono::duration< float >
auto get_updated_world_bounds(const math::transform &world_transform) const -> math::bbox
auto get_direction() const -> ps_soa::emitter_direction
void set_lifetime_by_emitter_speed_gradient(const math::gradient< float > &gradient)
void set_emission_lifetime(std::chrono::duration< float > lifetime)
auto get_simulation_space() const -> ps_soa::simulation_space
void set_shape(ps_soa::emitter_shape shape)
auto get_color_gradient() const -> const math::gradient< math::color > &
auto get_simulation_backend() const -> ps_soa::particle_sim_backend
auto get_size_by_speed_velocity_range() const -> const frange_t &
auto get_spawn_location() const -> ps_soa::spawn_location
static void on_create_component(entt::registry &r, entt::entity e)
auto get_emission_lifetime() const -> std::chrono::duration< float >
void set_lifetime_by_emitter_speed_range(const frange_t &speed_range)
void set_emission_shape_position(const math::vec3 &position)
auto get_last_render_frame() const noexcept -> uint64_t
void set_scale_gradient(const math::gradient< frange_t > &gradient)
void set_direction(ps_soa::emitter_direction direction)
auto get_position_easing() const -> bx::Easing::Enum
auto get_lifetime_by_emitter_speed_range() const -> const frange_t &
std::chrono::duration< float > delta_t
math::vec3 position
Definition defaults.cpp:52
uint32_t frame
Definition graphics.cpp:23
Definition imgui.h:25
Definition bbox.cpp:5
Hash specialization for batch_key to enable use in std::unordered_map.
@ sphere
Sphere type reflection probe.
std::vector< math::color > color
std::vector< float > scale
Thread-safe handle to an asset.
CRTP (Curiously Recurring Template Pattern) base structure for components.
bool enabled