Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CParticleEmitter Class Reference

Particle emitter. More...

#include <ParticleEmitter.h>

Collaboration diagram for CParticleEmitter:

Public Member Functions

 CParticleEmitter (const CParticleEmitterType &type)
 
void SetPosition (const CVector3D &pos)
 Set the position to be used for emission of new particles. More...
 
CVector3D GetPosition () const
 
void SetRotation (const CQuaternion &rot)
 Set the rotation to be used for emission of new particles (note: depends on particles). More...
 
const CQuaternion & GetRotation () const
 
const CBoundingBoxAligned & GetParticleBounds () const
 Get the bounding box of the center points of particles at their current positions. More...
 
void AddParticle (const SParticle &particle)
 Push a new particle onto the ring buffer. More...
 
void UpdateArrayData (int frameNumber)
 Update particle and vertex array data. More...
 
void PrepareForRendering ()
 Make the vertex data available for subsequent binding and rendering. More...
 
void UploadData (Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
 Upload the vertex data to the backend. More...
 
void Bind (Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IShaderProgram *shader)
 Bind rendering state (textures and blend modes). More...
 
void RenderArray (Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
 Draw the vertex array. More...
 
void SetEntityVariable (const std::string &name, float value)
 

Public Attributes

const CParticleEmitterType & m_Type
 
bool m_Active {true}
 Whether this emitter is still emitting new particles. More...
 
CVector3D m_Pos
 
CQuaternion m_Rot
 
std::map< std::string, float > m_EntityVariables
 
std::vector< SParticle > m_Particles
 
uint32_t m_NextParticleIdx {0}
 
uint32_t m_NumberOfVisibleParticles {0}
 
float m_LastUpdateTime
 
float m_EmissionRoundingError {0.0f}
 

Private Attributes

CBoundingBoxAligned m_ParticleBounds
 Bounding box of the current particle center points. More...
 
VertexIndexArray m_IndexArray
 
VertexArray m_VertexArray
 
VertexArray::Attribute m_AttributePos
 
VertexArray::Attribute m_AttributeColor
 
VertexArray::Attribute m_AttributeAxisX
 
VertexArray::Attribute m_AttributeAxisY
 
VertexArray m_VertexUVArray
 
VertexArray::Attribute m_AttributeUV
 
Renderer::Backend::IVertexInputLayout * m_VertexInputLayout = nullptr
 
int m_LastFrameNumber
 
bool m_UseInstancing {false}
 

Detailed Description

Particle emitter.

Emitters store particle data in two forms:

  • m_Particles contains the raw data used for the CPU particle simulation.
  • m_VertexArray contains the data required for rendering. Particles are rendered as billboard quads, so the vertex array contains four vertices per particle with different UV coordinates. The billboard position computation is performed by a vertex shader.

The number of particles is a constant for the entire life of the emitter, to simplify the updating and rendering. m_Particles acts like a ring buffer, so we don't have to worry about dynamically allocating particles. If particles have variable lifetimes, they'll exist in the array with alpha=0 until they're overwritten by a new particle after the maximum lifetime.

(It's quite likely this could be made more efficient, if the overhead of any added complexity is not high.)

Constructor & Destructor Documentation

◆ CParticleEmitter()

CParticleEmitter::CParticleEmitter ( const CParticleEmitterType &  type)

Member Function Documentation

◆ AddParticle()

void CParticleEmitter::AddParticle ( const SParticle &  particle)

Push a new particle onto the ring buffer.

(May overwrite an old particle.)

◆ Bind()

void CParticleEmitter::Bind ( Renderer::Backend::IDeviceCommandContext *  deviceCommandContext,
Renderer::Backend::IShaderProgram *  shader 
)

Bind rendering state (textures and blend modes).

◆ GetParticleBounds()

const CBoundingBoxAligned & CParticleEmitter::GetParticleBounds ( ) const
inline

Get the bounding box of the center points of particles at their current positions.

◆ GetPosition()

CVector3D CParticleEmitter::GetPosition ( ) const
inline

◆ GetRotation()

const CQuaternion & CParticleEmitter::GetRotation ( ) const
inline

◆ PrepareForRendering()

void CParticleEmitter::PrepareForRendering ( )

Make the vertex data available for subsequent binding and rendering.

◆ RenderArray()

void CParticleEmitter::RenderArray ( Renderer::Backend::IDeviceCommandContext *  deviceCommandContext)

Draw the vertex array.

◆ SetEntityVariable()

void CParticleEmitter::SetEntityVariable ( const std::string &  name,
float  value 
)

◆ SetPosition()

void CParticleEmitter::SetPosition ( const CVector3D &  pos)
inline

Set the position to be used for emission of new particles.

◆ SetRotation()

void CParticleEmitter::SetRotation ( const CQuaternion &  rot)
inline

Set the rotation to be used for emission of new particles (note: depends on particles).

◆ UpdateArrayData()

void CParticleEmitter::UpdateArrayData ( int  frameNumber)

Update particle and vertex array data.

Must be called before RenderArray.

If frameNumber is the same as the previous call to UpdateArrayData, then the function will do no work and return immediately.

◆ UploadData()

void CParticleEmitter::UploadData ( Renderer::Backend::IDeviceCommandContext *  deviceCommandContext)

Upload the vertex data to the backend.

Member Data Documentation

◆ m_Active

bool CParticleEmitter::m_Active {true}

Whether this emitter is still emitting new particles.

◆ m_AttributeAxisX

VertexArray::Attribute CParticleEmitter::m_AttributeAxisX
private

◆ m_AttributeAxisY

VertexArray::Attribute CParticleEmitter::m_AttributeAxisY
private

◆ m_AttributeColor

VertexArray::Attribute CParticleEmitter::m_AttributeColor
private

◆ m_AttributePos

VertexArray::Attribute CParticleEmitter::m_AttributePos
private

◆ m_AttributeUV

VertexArray::Attribute CParticleEmitter::m_AttributeUV
private

◆ m_EmissionRoundingError

float CParticleEmitter::m_EmissionRoundingError {0.0f}

◆ m_EntityVariables

std::map<std::string, float> CParticleEmitter::m_EntityVariables

◆ m_IndexArray

VertexIndexArray CParticleEmitter::m_IndexArray
private

◆ m_LastFrameNumber

int CParticleEmitter::m_LastFrameNumber
private

◆ m_LastUpdateTime

float CParticleEmitter::m_LastUpdateTime

◆ m_NextParticleIdx

uint32_t CParticleEmitter::m_NextParticleIdx {0}

◆ m_NumberOfVisibleParticles

uint32_t CParticleEmitter::m_NumberOfVisibleParticles {0}

◆ m_ParticleBounds

CBoundingBoxAligned CParticleEmitter::m_ParticleBounds
private

Bounding box of the current particle center points.

◆ m_Particles

std::vector<SParticle> CParticleEmitter::m_Particles

◆ m_Pos

CVector3D CParticleEmitter::m_Pos

◆ m_Rot

CQuaternion CParticleEmitter::m_Rot

◆ m_Type

const CParticleEmitterType& CParticleEmitter::m_Type

◆ m_UseInstancing

bool CParticleEmitter::m_UseInstancing {false}
private

◆ m_VertexArray

VertexArray CParticleEmitter::m_VertexArray
private

◆ m_VertexInputLayout

Renderer::Backend::IVertexInputLayout* CParticleEmitter::m_VertexInputLayout = nullptr
private

◆ m_VertexUVArray

VertexArray CParticleEmitter::m_VertexUVArray
private

The documentation for this class was generated from the following files: