Unravel Engine C++ Reference
Loading...
Searching...
No Matches
particle_system_soa.cpp File Reference
#include "particle_system_soa.h"
#include <bgfx/bgfx.h>
#include <bx/allocator.h>
#include <bx/bx.h>
#include <bx/handlealloc.h>
#include <bx/rng.h>
#include <core/logging/logging.h>
#include <engine/assets/asset_manager.h>
#include <engine/profiler/profiler.h>
#include <engine/rendering/gpu_program.h>
#include <graphics/graphics.h>
#include <graphics/render_pass.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdint>
#include <memory>
#include <vector>
#include <poolstl/poolstl.hpp>

Go to the source code of this file.

Namespaces

namespace  unravel
 
namespace  unravel::ps_soa
 

Macros

#define POOLSTL_STD_SUPPLEMENT   1
 

Functions

void unravel::ps_soa::init (uint16_t max_emitters=64)
 Initialize the soa particle system.
 
void unravel::ps_soa::init_gpu (rtti::context &ctx)
 Load compute pack program and enable GPU backend when available.
 
void unravel::ps_soa::shutdown ()
 Shutdown and free all emitters / GPU resources.
 
void unravel::ps_soa::set_default_sim_backend (particle_sim_backend backend)
 Set default sim backend for new / unset emitters (cpu remains fallback).
 
auto unravel::ps_soa::get_default_sim_backend () -> particle_sim_backend
 Current default sim backend.
 
void unravel::ps_soa::set_emitter_sim_backend (emitter_handle handle, particle_sim_backend backend)
 Override backend for one emitter.
 
auto unravel::ps_soa::get_emitter_sim_backend (emitter_handle handle) -> particle_sim_backend
 Effective backend for an emitter (after availability checks).
 
auto unravel::ps_soa::is_gpu_sim_available () -> bool
 True when compute pack program loaded successfully.
 
auto unravel::ps_soa::create_emitter (emitter_shape shape, emitter_direction direction, uint32_t max_particles) -> emitter_handle
 Create an emitter with shape/direction and capacity.
 
void unravel::ps_soa::destroy_emitter (emitter_handle handle)
 Destroy an emitter and free its particle storage.
 
void unravel::ps_soa::reset_emitter (emitter_handle handle)
 Clear particles and reset sim bookkeeping.
 
void unravel::ps_soa::update_emitter (emitter_handle handle, float dt, const emitter_desc &desc, emitter_transform_state &transform, emitter_playback_desc &playback)
 Advance simulation for one emitter.
 
void unravel::ps_soa::update_emitter_bounds_only (emitter_handle handle, const emitter_desc &desc, emitter_transform_state &transform)
 Refresh transform-driven world bounds without advancing sim (renderer-based freeze).
 
void unravel::ps_soa::sync_gpu_simulation ()
 Flush staged GPU spawns and advance resident GPU sim for awake emitters.
 
auto unravel::ps_soa::has_updated (emitter_handle handle) -> bool
 True after the first successful update.
 
void unravel::ps_soa::get_aabb (emitter_handle handle, math::bbox &out_aabb)
 World-space AABB used for culling.
 
auto unravel::ps_soa::get_num_particles (emitter_handle handle) -> uint32_t
 Live particle count.
 
auto unravel::ps_soa::render_emitter_batch (const emitter_handle *handles, uint32_t count, uint8_t view, bgfx::ProgramHandle program, const float *mtx_view, const math::vec3 &eye, bgfx::TextureHandle texture, uint64_t blend_state, bool sort_by_depth=true) -> uint32_t
 Submit a homogeneous material batch (same texture / texture_mode / blend).
 

Macro Definition Documentation

◆ POOLSTL_STD_SUPPLEMENT

#define POOLSTL_STD_SUPPLEMENT   1

Definition at line 22 of file particle_system_soa.cpp.

Variable Documentation

◆ active_slots

std::vector<uint32_t> active_slots

Definition at line 123 of file particle_system_soa.cpp.

◆ allocator_

bx::AllocatorI* allocator_ = nullptr

Definition at line 2318 of file particle_system_soa.cpp.

◆ backend_override

particle_sim_backend backend_override = particle_sim_backend::gpu

Definition at line 100 of file particle_system_soa.cpp.

◆ batched_scratch_

std::vector<batched_particle> batched_scratch_

Definition at line 2321 of file particle_system_soa.cpp.

◆ cached_constants_

emitter_sim_constants cached_constants_ {}

Definition at line 1453 of file particle_system_soa.cpp.

◆ cached_ease_pos

bx::EaseFn cached_ease_pos = nullptr

Definition at line 107 of file particle_system_soa.cpp.

◆ cached_features

emitter_feature cached_features = emitter_feature::none

Definition at line 106 of file particle_system_soa.cpp.

◆ cached_need_color_speed

bool cached_need_color_speed = false

Definition at line 104 of file particle_system_soa.cpp.

◆ cached_need_ease

bool cached_need_ease = false

Definition at line 105 of file particle_system_soa.cpp.

◆ cached_speed

std::vector<float> cached_speed

Definition at line 377 of file particle_system_soa.cpp.

◆ capacity

uint32_t capacity = 0

Definition at line 382 of file particle_system_soa.cpp.

◆ color

std::vector<math::color> color

Definition at line 375 of file particle_system_soa.cpp.

◆ color_lut

std::vector<math::vec4> color_lut

Definition at line 126 of file particle_system_soa.cpp.

◆ color_lut_vb

bgfx::DynamicVertexBufferHandle color_lut_vb = BGFX_INVALID_HANDLE

Definition at line 116 of file particle_system_soa.cpp.

◆ color_speed_lut

std::vector<math::vec4> color_speed_lut

Definition at line 127 of file particle_system_soa.cpp.

◆ color_speed_lut_vb

bgfx::DynamicVertexBufferHandle color_speed_lut_vb = BGFX_INVALID_HANDLE

Definition at line 117 of file particle_system_soa.cpp.

◆ constants

emitter_sim_constants constants {}

Definition at line 129 of file particle_system_soa.cpp.

◆ count

uint32_t count = 0

Definition at line 381 of file particle_system_soa.cpp.

◆ counter_ib

bgfx::DynamicIndexBufferHandle counter_ib = BGFX_INVALID_HANDLE

Definition at line 114 of file particle_system_soa.cpp.

◆ cpu_handles_scratch_

std::vector<emitter_handle> cpu_handles_scratch_

Definition at line 2325 of file particle_system_soa.cpp.

◆ direction_

emitter_direction direction_ = emitter_direction::up

Definition at line 1449 of file particle_system_soa.cpp.

◆ dist

float dist = 0.0f

Definition at line 1459 of file particle_system_soa.cpp.

◆ ease_lut

std::vector<math::vec4> ease_lut

Definition at line 128 of file particle_system_soa.cpp.

◆ ease_lut_vb

bgfx::DynamicVertexBufferHandle ease_lut_vb = BGFX_INVALID_HANDLE

Definition at line 118 of file particle_system_soa.cpp.

◆ emitter_alloc_

bx::HandleAlloc* emitter_alloc_ = nullptr

Definition at line 2319 of file particle_system_soa.cpp.

◆ emitter_idx

uint32_t emitter_idx = 0

Definition at line 1460 of file particle_system_soa.cpp.

◆ emitters_

std::vector<emitter> emitters_

Definition at line 2320 of file particle_system_soa.cpp.

◆ end0

std::vector<math::vec3> end0

Definition at line 367 of file particle_system_soa.cpp.

◆ end1

std::vector<math::vec3> end1

Definition at line 368 of file particle_system_soa.cpp.

◆ eye_pos_

bgfx::UniformHandle eye_pos_ = BGFX_INVALID_HANDLE

Definition at line 2330 of file particle_system_soa.cpp.

◆ free_list

std::vector<uint32_t> free_list

Definition at line 122 of file particle_system_soa.cpp.

◆ gpu_

emitter_gpu_resources gpu_

Definition at line 1454 of file particle_system_soa.cpp.

◆ gpu_capacity

uint32_t gpu_capacity = 0

Definition at line 108 of file particle_system_soa.cpp.

◆ gpu_emitters_scratch_

std::vector<emitter_handle> gpu_emitters_scratch_

Definition at line 2324 of file particle_system_soa.cpp.

◆ has_backend_override

bool has_backend_override = false

Definition at line 101 of file particle_system_soa.cpp.

◆ high_water

uint32_t high_water = 0

Exclusive end of slot range that may contain live sim data (for compact dispatch).

Definition at line 110 of file particle_system_soa.cpp.

◆ indirect_buf

bgfx::IndirectBufferHandle indirect_buf = BGFX_INVALID_HANDLE

Definition at line 115 of file particle_system_soa.cpp.

◆ instance_vb

bgfx::DynamicVertexBufferHandle instance_vb = BGFX_INVALID_HANDLE

Definition at line 113 of file particle_system_soa.cpp.

◆ life

std::vector<float> life

Definition at line 371 of file particle_system_soa.cpp.

◆ lifespan

std::vector<float> lifespan

Definition at line 372 of file particle_system_soa.cpp.

◆ luts_gpu_dirty

bool luts_gpu_dirty = true

Definition at line 103 of file particle_system_soa.cpp.

◆ luts_valid

bool luts_valid = false

Definition at line 102 of file particle_system_soa.cpp.

◆ ms_layout

bgfx::VertexLayout ms_layout
static

Definition at line 350 of file particle_system_soa.cpp.

◆ particle_idx

uint32_t particle_idx = 0

Definition at line 1461 of file particle_system_soa.cpp.

◆ particles_

particle_soa particles_

Definition at line 1450 of file particle_system_soa.cpp.

◆ pending_pack

bool pending_pack = false

Definition at line 99 of file particle_system_soa.cpp.

◆ position

std::vector<math::vec3> position

Definition at line 374 of file particle_system_soa.cpp.

◆ prefix_scratch_

std::vector<uint32_t> prefix_scratch_

Definition at line 2323 of file particle_system_soa.cpp.

◆ quad_ibh_

bgfx::IndexBufferHandle quad_ibh_ = BGFX_INVALID_HANDLE

Definition at line 2327 of file particle_system_soa.cpp.

◆ quad_vbh_

bgfx::VertexBufferHandle quad_vbh_ = BGFX_INVALID_HANDLE

Definition at line 2326 of file particle_system_soa.cpp.

◆ radix_scratch_

std::vector<batched_particle> radix_scratch_

Definition at line 2322 of file particle_system_soa.cpp.

◆ rng_

bx::RngMwc rng_

Definition at line 1452 of file particle_system_soa.cpp.

◆ rotation

std::vector<math::quat> rotation

Definition at line 380 of file particle_system_soa.cpp.

◆ scale

std::vector<float> scale

Definition at line 376 of file particle_system_soa.cpp.

◆ scale_end

std::vector<float> scale_end

Definition at line 370 of file particle_system_soa.cpp.

◆ scale_start

std::vector<float> scale_start

Definition at line 369 of file particle_system_soa.cpp.

◆ shape_

emitter_shape shape_ = emitter_shape::sphere

Definition at line 1448 of file particle_system_soa.cpp.

◆ sim

emitter_sim_state sim

Definition at line 1451 of file particle_system_soa.cpp.

◆ sim_dt

float sim_dt = 0.0f

Definition at line 111 of file particle_system_soa.cpp.

◆ sim_vb

bgfx::DynamicVertexBufferHandle sim_vb = BGFX_INVALID_HANDLE

Definition at line 112 of file particle_system_soa.cpp.

◆ spawn_particles

std::vector<gpu_sim_particle> spawn_particles

Definition at line 124 of file particle_system_soa.cpp.

◆ spawn_slots

std::vector<uint32_t> spawn_slots

Definition at line 125 of file particle_system_soa.cpp.

◆ spawn_slots_ib

bgfx::DynamicIndexBufferHandle spawn_slots_ib = BGFX_INVALID_HANDLE

Definition at line 120 of file particle_system_soa.cpp.

◆ spawn_upload_capacity

uint32_t spawn_upload_capacity = 0

Definition at line 121 of file particle_system_soa.cpp.

◆ spawn_vb

bgfx::DynamicVertexBufferHandle spawn_vb = BGFX_INVALID_HANDLE

Definition at line 119 of file particle_system_soa.cpp.

◆ start

std::vector<math::vec3> start

Definition at line 366 of file particle_system_soa.cpp.

◆ tex_color_

bgfx::UniformHandle tex_color_ = BGFX_INVALID_HANDLE

Definition at line 2328 of file particle_system_soa.cpp.

◆ texsheet_seed

std::vector<float> texsheet_seed

Definition at line 373 of file particle_system_soa.cpp.

◆ trail_bounds

math::bbox trail_bounds {}

Grow-only world-space trail AABB (union of particle trajectory hulls).

Definition at line 131 of file particle_system_soa.cpp.

◆ trail_bounds_valid

bool trail_bounds_valid = false

Definition at line 132 of file particle_system_soa.cpp.

◆ u

float u

Definition at line 340 of file particle_system_soa.cpp.

◆ uv_offset

std::vector<math::vec2> uv_offset

Definition at line 378 of file particle_system_soa.cpp.

◆ uv_scale

std::vector<math::vec2> uv_scale

Definition at line 379 of file particle_system_soa.cpp.

◆ v

float v

Definition at line 340 of file particle_system_soa.cpp.

◆ view_camera_

bgfx::UniformHandle view_camera_ = BGFX_INVALID_HANDLE

Definition at line 2329 of file particle_system_soa.cpp.

◆ x

float x

Definition at line 340 of file particle_system_soa.cpp.

◆ y

float y

Definition at line 340 of file particle_system_soa.cpp.

◆ z

float z

Definition at line 340 of file particle_system_soa.cpp.