Unravel Engine C++ Reference
Loading...
Searching...
No Matches
emitter_desc.cpp
Go to the documentation of this file.
1#include "emitter_desc.h"
2#include "emitter_runtime.h"
3
4namespace unravel
5{
6namespace ps_soa
7{
8
10{
12 emission_lifetime = 2.0f;
13 start_delay = 0.0f;
14 loop = true;
16 shape_position = math::vec3(0.0f, 0.0f, 0.0f);
17 shape_scale = math::vec3(1.0f, 1.0f, 1.0f);
18}
19
39
41{
43 color_gradient.add_point(math::color(0x00ffffff), 0.0f);
44 color_gradient.add_point(math::color(0xffffffff), 0.25f);
45 color_gradient.add_point(math::color(0xffffffff), 0.5f);
46 color_gradient.add_point(math::color(0xffffffff), 0.75f);
47 color_gradient.add_point(math::color(0x00ffffff), 1.0f);
50 scale_gradient.add_point(frange_t(0.1f, 0.2f), 0.0f);
51 scale_gradient.add_point(frange_t(0.3f, 0.4f), 1.0f);
52 scale_gradient.generate_lut(256);
53 initial_scale_3d = math::vec3(1.0f, 1.0f, 1.0f);
54 opacity = 1.0f;
55 color_intensity = 1.0f;
56 size_by_speed_range = frange_t(1.0f, 1.0f);
63}
64
66{
70 align_to_direction = false;
71 pivot = math::vec2(0.5f, 0.5f);
72 tex_sheet_tiles = math::vec2(1.0f, 1.0f);
73 tex_sheet_cycles = 0.0f;
74 tex_sheet_randomize = false;
75}
76
78{
79 playing = true;
80 paused = false;
81}
82
91
93{
96 {
97 features = features | emitter_feature::align_to_direction;
98 }
99 if(render.tex_sheet_cycles > 0.0f && render.tex_sheet_tiles.x > 0.0f && render.tex_sheet_tiles.y > 0.0f)
100 {
101 features = features | emitter_feature::texsheet;
102 }
104 {
105 features = features | emitter_feature::color_by_speed;
106 }
109 {
110 features = features | emitter_feature::size_by_speed;
111 }
113 {
114 features = features | emitter_feature::lifetime_by_emitter_speed;
115 }
117 {
118 features = features | emitter_feature::local_space;
119 }
120 if(motion.position_easing != bx::Easing::Linear)
121 {
122 features = features | emitter_feature::non_linear_ease;
123 }
124 return features;
125}
126
128{
129 emission_time_accum = 0.0f;
130 start_delay_elapsed = 0.0f;
132 first_update = true;
133 playing = true;
134 loop = true;
136 temporal_count = 0;
137 temporal_positions.fill(math::vec3(0.0f));
138 temporal_dts.fill(0.0f);
139 world_bounds = math::bbox(math::vec3(-1.0f), math::vec3(1.0f));
140}
141
142void emitter_sim_state::push_temporal_sample(const math::vec3& position, float dt)
143{
145 {
149 return;
150 }
151 for(uint32_t i = 1; i < temporal_buffer_size; ++i)
152 {
154 temporal_dts[i - 1] = temporal_dts[i];
155 }
158}
159
160auto emitter_sim_state::calculate_smoothed_emitter_speed(float max_speed) const -> float
161{
162 if(temporal_count < temporal_buffer_size)
163 {
164 return max_speed;
165 }
166 float total_distance = 0.0f;
167 float total_time = 0.0f;
168 for(uint32_t i = 1; i < temporal_count; ++i)
169 {
170 const math::vec3 delta = temporal_positions[i] - temporal_positions[i - 1];
171 total_distance += math::length(delta);
172 total_time += temporal_dts[i];
173 }
174 if(total_time > 0.0f)
175 {
176 return total_distance / total_time;
177 }
178 return 0.0f;
179}
180
181} // namespace ps_soa
182} // namespace unravel
auto add_point(const T &element, float progress) -> size_t
Definition gradient.hpp:8
void generate_lut(size_t lut_size=256)
Definition gradient.hpp:222
range< float > frange_t
math::vec3 position
Definition defaults.cpp:52
blend_mode
Blend mode. Ordinals match legacy BlendMode.
texture_mode
Texture interpretation. Ordinals match legacy TextureMode.
spawn_location
Where particles spawn within the shape. Ordinals match legacy EmitterSpawnLocation.
emitter_feature
Feature bits baked from authoring desc for specialized update/render paths.
render_mode
Billboard / facing mode. Ordinals match legacy RenderMode.
Storage for box vector values and wraps up common functionality.
Definition bbox.h:21
math::gradient< math::color > color_by_speed_gradient
math::gradient< math::color > color_gradient
math::gradient< frange_t > scale_gradient
emitter_appearance_desc appearance
emitter_emission_desc emission
emitter_render_desc render
auto bake_features() const -> emitter_feature
Derive feature mask used to specialize update/render kernels.
emitter_motion_desc motion
emitter_playback_desc playback
math::gradient< frange_t > velocity_gradient
math::gradient< float > lifetime_by_emitter_speed_gradient
std::array< float, temporal_buffer_size > temporal_dts
std::array< math::vec3, temporal_buffer_size > temporal_positions
auto calculate_smoothed_emitter_speed(float max_speed) const -> float
static constexpr size_t temporal_buffer_size
void push_temporal_sample(const math::vec3 &position, float dt)