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 <graphics/utils/bgfx_utils.h>
#include <bx/easing.h>
#include <bx/handlealloc.h>
#include <math/math.h>
#include <vector>
#include <algorithm>
#include <engine/profiler/profiler.h>

Go to the source code of this file.

Classes

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

Namespaces

namespace  ps
 

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)
 
void psRenderEmitter (EmitterHandle _handle, uint8_t _view, bgfx::ProgramHandle _program, const float *_mtxView, const math::vec3 &_eye, bgfx::TextureHandle _texture)
 
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)
 

Function Documentation

◆ psCreateEmitter()

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

Definition at line 1053 of file particle_system.cpp.

◆ psDestroyEmitter()

void psDestroyEmitter ( EmitterHandle _handle)

Definition at line 1085 of file particle_system.cpp.

◆ psGetAabb()

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

Definition at line 1070 of file particle_system.cpp.

◆ psGetNumParticles()

uint32_t psGetNumParticles ( EmitterHandle _handle)

Definition at line 1075 of file particle_system.cpp.

◆ psHasUpdated()

bool psHasUpdated ( EmitterHandle _handle)

Definition at line 1080 of file particle_system.cpp.

◆ psInit()

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

Definition at line 1041 of file particle_system.cpp.

◆ psRenderEmitter()

void psRenderEmitter ( EmitterHandle _handle,
uint8_t _view,
bgfx::ProgramHandle _program,
const float * _mtxView,
const math::vec3 & _eye,
bgfx::TextureHandle _texture )

Definition at line 1090 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 )

Render multiple emitters in a single batched draw call (all must use the same texture) This is much more efficient than calling psRenderEmitter multiple times as it:

  • Combines all particles into a single instance buffer
  • Sorts all particles globally for proper alpha blending
  • Uses only one draw call instead of multiple

Example usage: EmitterHandle handles[] = {fire_emitter, smoke_emitter, spark_emitter}; psRenderEmitterBatch(handles, 3, view, program, viewMatrix, cameraPos, fireTexture);

Definition at line 1100 of file particle_system.cpp.

◆ psResetEmitter()

void psResetEmitter ( EmitterHandle _handle)

Definition at line 1063 of file particle_system.cpp.

◆ psShutdown()

void psShutdown ( )

Definition at line 1046 of file particle_system.cpp.

◆ psUpdateEmitter()

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

Definition at line 1058 of file particle_system.cpp.