Unravel Engine C++ Reference
Loading...
Searching...
No Matches
particle_system.cpp File Reference
#include <bgfx/bgfx.h>
#include <bgfx/embedded_shader.h>
#include "particle_system.h"
#include "bx/bx.h"
#include <graphics/utils/bgfx_utils.h>
#include <bx/easing.h>
#include <bx/handlealloc.h>
#include <math/math.h>
#include <glm/gtc/random.hpp>
#include <algorithm>
#include <cstdint>
#include <vector>
#include <engine/profiler/profiler.h>
#include <core/logging/logging.h>
#include <poolstl/poolstl.hpp>

Go to the source code of this file.

Classes

struct  ParticleVertex
 
struct  ps::Particle
 
struct  ps::Emitter
 
struct  ps::ParticleSystem
 
struct  ps::ParticleSystem::BatchedParticle
 

Namespaces

namespace  ps
 

Macros

#define POOLSTL_STD_SUPPLEMENT   1
 

Functions

void psInit (uint16_t _maxEmitters, bx::AllocatorI *_allocator)
 
void psShutdown ()
 
EmitterHandle psCreateEmitter (EmitterShape::Enum _shape, EmitterDirection::Enum _direction, uint32_t _maxParticles)
 
void psUpdateEmitter (EmitterHandle _handle, float _dt, EmitterUniforms *_uniforms)
 
void psResetEmitter (EmitterHandle _handle)
 
void psGetAabb (EmitterHandle _handle, math::bbox &_outAabb)
 
uint32_t psGetNumParticles (EmitterHandle _handle)
 
bool psHasUpdated (EmitterHandle _handle)
 
void psDestroyEmitter (EmitterHandle _handle)
 
uint32_t psRenderEmitterBatch (const EmitterHandle *_handles, uint32_t _count, uint8_t _view, bgfx::ProgramHandle _program, const float *_mtxView, const math::vec3 &_eye, bgfx::TextureHandle _texture, uint64_t _blend_state, bool _sort_by_depth)
 

Variables

static ParticleVertex s_quadVertices [4]
 
static const uint16_t s_quadIndices [6]
 
static ParticleSystem ps::s_ctx
 

Macro Definition Documentation

◆ POOLSTL_STD_SUPPLEMENT

#define POOLSTL_STD_SUPPLEMENT   1

Definition at line 24 of file particle_system.cpp.

Function Documentation

◆ psCreateEmitter()

EmitterHandle psCreateEmitter ( EmitterShape::Enum _shape,
EmitterDirection::Enum _direction,
uint32_t _maxParticles )

Definition at line 1570 of file particle_system.cpp.

◆ psDestroyEmitter()

void psDestroyEmitter ( EmitterHandle _handle)

Definition at line 1602 of file particle_system.cpp.

◆ psGetAabb()

void psGetAabb ( EmitterHandle _handle,
math::bbox & _outAabb )

Definition at line 1587 of file particle_system.cpp.

◆ psGetNumParticles()

uint32_t psGetNumParticles ( EmitterHandle _handle)

Definition at line 1592 of file particle_system.cpp.

◆ psHasUpdated()

bool psHasUpdated ( EmitterHandle _handle)

Definition at line 1597 of file particle_system.cpp.

◆ psInit()

void psInit ( uint16_t _maxEmitters,
bx::AllocatorI * _allocator )

Definition at line 1558 of file particle_system.cpp.

◆ psRenderEmitterBatch()

uint32_t psRenderEmitterBatch ( const EmitterHandle * _handles,
uint32_t _count,
uint8_t _view,
bgfx::ProgramHandle _program,
const float * _mtxView,
const math::vec3 & _eye,
bgfx::TextureHandle _texture,
uint64_t _blend_state,
bool _sort_by_depth = true )

Submit one homogeneous particle batch: same texture, TextureMode (mask vs multi-channel), and BlendMode. RenderMode is per-instance. The pipeline groups emitters by material. When _sort_by_depth is true, instances are sorted back-to-front (sequential for small counts, parallel above a threshold) then gathered into the instance buffer. When false, particles are streamed directly from each emitter's array in emission order (additive / order-independent blends) with no sort-key scratch. May issue multiple submits if the transient instance buffer is smaller than the particle count.

Definition at line 1607 of file particle_system.cpp.

◆ psResetEmitter()

void psResetEmitter ( EmitterHandle _handle)

Definition at line 1580 of file particle_system.cpp.

◆ psShutdown()

void psShutdown ( )

Definition at line 1563 of file particle_system.cpp.

◆ psUpdateEmitter()

void psUpdateEmitter ( EmitterHandle _handle,
float _dt,
EmitterUniforms * _uniforms )

Definition at line 1575 of file particle_system.cpp.

Variable Documentation

◆ s_quadIndices

const uint16_t s_quadIndices[6]
static
Initial value:
= {
0, 1, 2, 2, 3, 0
}

Definition at line 56 of file particle_system.cpp.

◆ s_quadVertices

ParticleVertex s_quadVertices[4]
static
Initial value:
= {
{-0.5f, -0.5f, 0.0f, 0.0f, 1.0f},
{ 0.5f, -0.5f, 0.0f, 1.0f, 1.0f},
{ 0.5f, 0.5f, 0.0f, 1.0f, 0.0f},
{-0.5f, 0.5f, 0.0f, 0.0f, 0.0f}
}

Definition at line 49 of file particle_system.cpp.