9#include "core/reflect.h"
10#include "core/math/curve.h"
11#include "ecs/component/render/mesh.h"
12#include "resource/asset/texture_asset.h"
14namespace Vkm::Engine {
19enum class EmitShape : uint8_t {
32enum class ParticleBlend : uint8_t {
42enum class ParticleRender : uint8_t {
53enum class ParticleEvent : uint8_t {
88 EmitShape
shape = EmitShape::Cone;
90 float angle = glm::radians(25.0f);
106 Math::Gradient color{{{0.0f, {1.0f, 0.8f, 0.4f, 1.0f}}, {1.0f, {1.0f, 0.2f, 0.0f, 0.0f}}}};
112 ParticleBlend blend = ParticleBlend::Additive;
124 ParticleRender render = ParticleRender::Billboard;
138 uint32_t sheetRows = 1;
166 ParticleEvent
event = ParticleEvent::Death;
177 return std::max(emitter.
sheetColumns, 1u) * std::max(emitter.sheetRows, 1u);
201 const uint32_t frames = sheetFrames(emitter);
202 const auto count =
static_cast<float>(frames);
203 const bool loops = emitter.
sheetFps > 0.0f;
204 float position = 0.0f;
206 position = std::fmod(std::max(age * emitter.
sheetFps, 0.0f), count);
208 const float share = lifetime > 0.0f ? std::clamp(age / lifetime, 0.0f, 1.0f) : 1.0f;
209 position = share * (emitter.
sheetBlend ? count - 1.0f : count);
212 const uint32_t ahead = std::min(
static_cast<uint32_t
>(position), frames - 1);
213 const uint32_t after = loops ? (ahead + 1) % frames : std::min(ahead + 1, frames - 1);
216 sheet.frame = (start + ahead) % frames;
217 sheet.next = (start + after) % frames;
218 sheet.blend = emitter.
sheetBlend && after != ahead ? position -
static_cast<float>(ahead) : 0.0f;
224VKM_ENUM_NAMES(::Vkm::Engine::EmitShape,
"Point",
"Sphere",
"Hemisphere",
"Cone",
"Box",
"Disc")
225VKM_ENUM_NAMES(::Vkm::Engine::ParticleBlend,
"Additive",
"Alpha",
"Distortion")
226VKM_ENUM_NAMES(::Vkm::Engine::ParticleRender,
"Billboard",
"Stretched",
"Ribbon",
"Trail")
227VKM_ENUM_NAMES(::Vkm::Engine::ParticleEvent,
"Birth",
"Death",
"Collision")
229VKM_REFLECT_BEGIN(::Vkm::Engine::ParticleEmitter)
235 VKM_F(destroyWhenSpent)
243 VKM_F(inheritVelocity)
247 VKM_F(turbulenceScale)
258 VKM_F(lightIntensity)
277VKM_REFLECT_BEGIN(::Vkm::Engine::ParticleTrigger)
One entity's view of a CollisionEvent, as its behaviors' collision hooks receive it.
Definition physics_events.h:47
A value over a span from 0 to 1 - a particle's life, say - straight between its keys.
Definition curve.h:72
A value drawn once, uniformly between min and max; equal ends are a constant.
Definition curve.h:16
A colour over a span from 0 to 1, straight between its keys in linear RGBA.
Definition curve.h:100
CPU-simulated particle emitter: fire, smoke, sparks, impacts, trails, heat haze.
Definition particle_emitter.h:74
float softness
The disc's edge, 1 soft to 0 hard. Unread with a texture.
Definition particle_emitter.h:110
float lifeLostOnHit
The share of its whole life a strike takes; 1 ends it.
Definition particle_emitter.h:147
Math::FloatRange spin
Radians a second it turns.
Definition particle_emitter.h:109
float turbulenceScale
Metres the swirls span.
Definition particle_emitter.h:102
EmitShape shape
Where particles are born and which way they leave, in the emitter's frame.
Definition particle_emitter.h:88
float rate
Particles a second.
Definition particle_emitter.h:76
Math::FloatRange rotation
Radians it is born turned by, about the view.
Definition particle_emitter.h:108
uint32_t burst
Particles to spawn at once on the next update, besides the rates; set again to fire again.
Definition particle_emitter.h:81
float intensity
Multiplies the colour: past 1, an emitting one blooms.
Definition particle_emitter.h:107
float bounce
The share of its speed into the surface it keeps, turned back.
Definition particle_emitter.h:146
Math::FloatRange speed
Definition particle_emitter.h:95
float sheetFps
Frames a second, looping; 0 plays the sheet once over a life.
Definition particle_emitter.h:139
uint32_t sheetColumns
The texture as a sheet of frames, columns by rows, read left to right from the top.
Definition particle_emitter.h:137
float ratePerMetre
Particles a metre the emitter travels, besides the rate.
Definition particle_emitter.h:77
bool destroyWhenSpent
Definition particle_emitter.h:85
bool fromSurface
Born on the shape's surface or rim, not inside it.
Definition particle_emitter.h:92
float turbulence
Scales the swirl it accelerates by (ParticleSystem::swirlAt).
Definition particle_emitter.h:101
float inheritVelocity
Definition particle_emitter.h:98
TextureHandle texture
Definition particle_emitter.h:130
float lightRadius
Metres the light reaches.
Definition particle_emitter.h:122
glm::vec3 acceleration
World space, metres a second squared: gravity.
Definition particle_emitter.h:99
float distortion
Distortion: how far it bends what is behind, in view heights.
Definition particle_emitter.h:114
float lightIntensity
Definition particle_emitter.h:120
float stretch
Stretched: seconds of its travel the card spans.
Definition particle_emitter.h:125
float trailLength
Trail: seconds of where it was the strip spans.
Definition particle_emitter.h:126
bool collide
Definition particle_emitter.h:145
Math::FloatRange size
Half the card's width, metres, drawn at birth.
Definition particle_emitter.h:104
SeenBy seenBy
Definition particle_emitter.h:153
float drag
Velocity lost a second: it keeps exp(-drag) of it.
Definition particle_emitter.h:100
bool randomFrame
Each particle starts on a frame of its own.
Definition particle_emitter.h:140
uint32_t maxParticles
Cap on live particles.
Definition particle_emitter.h:78
glm::vec3 halfExtents
Box, metres.
Definition particle_emitter.h:91
TextureHandle normalMap
Definition particle_emitter.h:134
float emission
Alpha: the share of its colour it gives off - fire in smoke.
Definition particle_emitter.h:113
float angle
Cone and Box: radians off +Y a particle may leave at.
Definition particle_emitter.h:90
glm::vec3 lightColor
The light's colour.
Definition particle_emitter.h:121
bool sheetBlend
Each frame fades into the next: a slow flipbook moves smoothly.
Definition particle_emitter.h:141
Math::FloatRange lifetime
Seconds.
Definition particle_emitter.h:94
Math::Curve sizeOverLife
Multiplies the drawn size.
Definition particle_emitter.h:105
float radius
Sphere, Hemisphere, Cone and Disc, metres.
Definition particle_emitter.h:89
Makes a child entity's ParticleEmitter a sub-emitter of its parent's.
Definition particle_emitter.h:165
Where in its sheet a particle is: the frame it shows, and how far it has faded into the next.
Definition particle_emitter.h:183
uint32_t frame
The frame it shows.
Definition particle_emitter.h:184
float blend
How far it has faded into next, 0..1; 0 unless sheetBlend.
Definition particle_emitter.h:186
uint32_t next
The frame after it.
Definition particle_emitter.h:185