ComputerGraphik TU WIEN
Classes | Public Member Functions | Private Attributes | List of all members
ParticleSystemGPU Class Reference

Implementation of GPU particle system. More...

#include <particleSystemGPU.hpp>

Inheritance diagram for ParticleSystemGPU:
Tessellation SceneObject

Classes

struct  NewParticle
 Helper class to upload new particles. More...
 

Public Member Functions

 ParticleSystemGPU (const std::string &name, Scene *scene=0, Model *model=0, const glm::mat4 &modelMatrix=glm::mat4(1.0f))
 
virtual ~ParticleSystemGPU ()
 
void push (const NewParticle &pos)
 Add a new particle to upload in next frame. More...
 
GLuint getActiveCount () const
 
GLuint getParticlePosVBO () const
 
void draw () const
 
bool animate (double time)
 
void update (double deltaT)
 
void setShader (Shader *val)
 
- Public Member Functions inherited from Tessellation
 Tessellation (const std::string &name, Scene *scene=0, Model *model=0, const glm::mat4 &modelMatrix=glm::mat4(1))
 
virtual ~Tessellation ()
 
void draw () const
 
bool animate (double time)
 
void update (double deltaT)
 
void setShader (Shader *val)
 
GLuint getDispTexture () const
 
unsigned int getTessLevelIn () const
 
unsigned int getTessLevelOut () const
 
void setTessLevelIn (unsigned int val)
 
void setTessLevelOut (unsigned int val)
 
- Public Member Functions inherited from SceneObject
 SceneObject (std::shared_ptr< SceneObject > &effectParent, const glm::mat4 &modelMatrix=glm::mat4(1))
 
 SceneObject (const std::string &name, Scene *scene=0, Model *model=0, const glm::mat4 &modelMatrix=glm::mat4(1))
 
virtual ~SceneObject ()
 
ModelgetModel () const
 
ShadergetShader () const
 
glm::mat4 getModelMatrix () const
 
glm::mat4 getGlobalModelMatrix () const
 
std::string getName () const
 
std::shared_ptr< SceneObjectgetParent () const
 
void setAnimationTime (double time)
 
bool setAnimation (const Animation &anim)
 
bool delChild (size_t idx)
 
bool getChild (size_t idx, std::shared_ptr< SceneObject > &child) const
 
bool addChild (std::shared_ptr< SceneObject > &child)
 
bool remEffect (const std::string &name)
 
SceneObjectgetEffect (const std::string &name) const
 
bool addEffect (const std::string &name, std::unique_ptr< SceneObject > &effect)
 
bool doNotRender ()
 
bool getIsVolSun ()
 
virtual void reset ()
 

Private Attributes

double lastUpdate
 
double lastAnimate
 
ShadercomputeShader
 
GLuint countersVBO
 
GLuint particlesVBO
 
GLuint particlesPosVBO
 
std::vector< GLuint > counters
 
std::vector< NewParticlenewParticles
 

Additional Inherited Members

- Public Types inherited from SceneObject
typedef std::vector< std::pair< double, glm::mat4 > > Animation
 
- Protected Attributes inherited from Tessellation
GLuint dispTexture
 
unsigned int tessLevelIn
 
unsigned int tessLevelOut
 
- Protected Attributes inherited from SceneObject
GLuint vao
 
Scenescene
 
Modelmodel
 
Shadershader
 
glm::mat4 modelMatrix
 
std::string name
 
std::weak_ptr< SceneObjectparent
 
std::vector< std::shared_ptr< SceneObject > > childs
 
std::map< std::string, std::unique_ptr< SceneObject > > effectChilds
 
size_t animIDX
 
Animation animation
 
bool norender
 
bool isVolSun
 

Detailed Description

Implementation of GPU particle system.

Author
Adam

For the moving of animated flying bullets effect, a GPU particle system was implemented using the Compute Shader. This way the moving of the particles are computed on the GPU and it could handle even more bullets, then what appears in the demo. Two Shader Storage Buffer Objects and one Atomic Counter Buffer Object are used. In the first buffer particles can have arbitrary order, in this buffer all the attributes of a bullet are stored. The second buffer stores the position and life of the particles aligned, this is the render buffer. A GPU thread is executed on one particle. If it lives, then its new position is computed, the active particle atomic counter is incremented and data is placed into the render buffer at the position retrieved from the atomic operation. When a particle is dead and a new particle should be inserted, an atomic increment is done. If the prefix from the atomic operation is smaller then the number of new particles, then the particle at the prefix is loaded by the current thread. There is an article about atomic counter on LightHouse 3D, according to this article, when atomic counters are supported by hardware, the cost of atomic functions are just like any other function call. Finally, the value of the atomic counter of active particles is read back to the CPU to be able to render with instancing.

See also
https://www.opengl.org/wiki/Compute_Shader

Constructor & Destructor Documentation

ParticleSystemGPU::ParticleSystemGPU ( const std::string &  name,
Scene scene = 0,
Model model = 0,
const glm::mat4 &  modelMatrix = glm::mat4(1.0f) 
)
ParticleSystemGPU::~ParticleSystemGPU ( )
virtual

Member Function Documentation

bool ParticleSystemGPU::animate ( double  time)
virtual

Reimplemented from SceneObject.

void ParticleSystemGPU::draw ( ) const
virtual

Reimplemented from SceneObject.

GLuint ParticleSystemGPU::getActiveCount ( ) const
inline
GLuint ParticleSystemGPU::getParticlePosVBO ( ) const
inline
void ParticleSystemGPU::push ( const NewParticle pos)

Add a new particle to upload in next frame.

Note
Currently only one particle can be uploaded as an uniform by frame.
void ParticleSystemGPU::setShader ( Shader val)
virtual

Reimplemented from SceneObject.

void ParticleSystemGPU::update ( double  deltaT)
virtual

Reimplemented from SceneObject.

Member Data Documentation

Shader* ParticleSystemGPU::computeShader
private
std::vector<GLuint> ParticleSystemGPU::counters
private
GLuint ParticleSystemGPU::countersVBO
private
double ParticleSystemGPU::lastAnimate
private
double ParticleSystemGPU::lastUpdate
private
std::vector<NewParticle> ParticleSystemGPU::newParticles
private
GLuint ParticleSystemGPU::particlesPosVBO
private
GLuint ParticleSystemGPU::particlesVBO
private

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