E N D
1. Particle Systems CS 536
Rahul Malhotra Hi, my name is Rahul Malhotra and my presentation is about Particle Systems.Hi, my name is Rahul Malhotra and my presentation is about Particle Systems.
2. Effects Here is an image I found on the internet that show differenct kinds of effects that can be created using particle systems. It includes, explosion, weapon effects, smoke, etc.Here is an image I found on the internet that show differenct kinds of effects that can be created using particle systems. It includes, explosion, weapon effects, smoke, etc.
3. History Spacewar (1962) Let me start with history of particles systems. How many of you have seen or played spacewar?? Used pixel clouds as explosions. Let me start with history of particles systems. How many of you have seen or played spacewar?? Used pixel clouds as explosions.
4. History Asteroids (1978) Uses short moving vectors for explosions. Probably first physical particle simulation in CG/games by Justin IrwinUses short moving vectors for explosions. Probably first physical particle simulation in CG/games by Justin Irwin
5. History Star Trek II (1983) Star Trek II:The Wrath of Kahn these effects created using particle systems.Star Trek II:The Wrath of Kahn these effects created using particle systems.
6. Uses of Particle Systems Explosions
Smoke
Fog
Weapon Effects
Impact Effectsa Particle systems are often used in game development for creating such effects like smoke, explosions, fog, impacts, etc.Particle systems are often used in game development for creating such effects like smoke, explosions, fog, impacts, etc.
7. Definition A particle system is a collection of a number of individual elements or particles.
Particle systems control a set of particles that act autonomously but share some common attributes. Definitions
A particle system simply put is a collection of a number of individual elements or particles.
They control a set of particles that act autonomously but share some common attributes. so even though the individual particles act independently, together they create a common effect.
Each particle has individual attributes, such as velocity, color, life span.
Each particle acts mostly autonomously it doesnt care about what other particles are doing. Definitions
A particle system simply put is a collection of a number of individual elements or particles.
They control a set of particles that act autonomously but share some common attributes. so even though the individual particles act independently, together they create a common effect.
Each particle has individual attributes, such as velocity, color, life span.
Each particle acts mostly autonomously it doesnt care about what other particles are doing.
8. Basic Particle System Physics Particle is a point in 3D space.
Forces (e.g. gravity or wind) accelerate a particle.
Acceleration changes velocity.
Velocity changes position A particle is a point in 3d space and then we have forces that act or affect a particle. Forces such as wind, gravity, impact. A particle is a point in 3d space and then we have forces that act or affect a particle. Forces such as wind, gravity, impact.
9. Attributes of a Particle Position
Velocity
Life Span
Size
Weight
Representation
Color
Owner For creating an effect using particle system, youll need to define what a particle is and what attributes should it posses.
Position: We need to know where the particle in 3d space is so we can render it correctly. You may also want to track the particles last position to achieve effects such as trails.
Velocity: If the particle is going to be moving then we need to store their velocity. It can stored as a vector representing both speed and direction. Velocity is affected by forces such as wind and gravity. If the particle is capable of accelerating itself, that could affect the velocity as well, and youd want to create an additional attribute to store the acceleration.
Life Span: For most effects, particles are going to be emitted from their source and, after some period of time, are going to disappear. So well need to keep track of how long a particle has been alive or how long it has left to live.
Size: Youll also need to store Size if particles with varying sizes are involved and then also you may want to store another attribute to store how the size should change over time.
Weight: It determines how much of an affect external forces will have on a particle.
Representation: Points, Lines or Texture-mapped quads
Owner: If you have multiple particles systems then you also want to store which particle system it belongs to so that it can access methods in the particle system class.For creating an effect using particle system, youll need to define what a particle is and what attributes should it posses.
Position: We need to know where the particle in 3d space is so we can render it correctly. You may also want to track the particles last position to achieve effects such as trails.
Velocity: If the particle is going to be moving then we need to store their velocity. It can stored as a vector representing both speed and direction. Velocity is affected by forces such as wind and gravity. If the particle is capable of accelerating itself, that could affect the velocity as well, and youd want to create an additional attribute to store the acceleration.
Life Span: For most effects, particles are going to be emitted from their source and, after some period of time, are going to disappear. So well need to keep track of how long a particle has been alive or how long it has left to live.
Size: Youll also need to store Size if particles with varying sizes are involved and then also you may want to store another attribute to store how the size should change over time.
Weight: It determines how much of an affect external forces will have on a particle.
Representation: Points, Lines or Texture-mapped quads
Owner: If you have multiple particles systems then you also want to store which particle system it belongs to so that it can access methods in the particle system class.
10. Attributes of a Particle System Particle List
Position
Emission Rate
Forces
Current State
Blending
Representation Just as we store certain attributes of a particle, youll need to decide what attributes we want to store for a particle system.
Particle List: One of the most important attribute will be a pointer or reference to the particle list.
Position: particle system must be located somehwere to determine were particles start.
Emission Rate: determines how often a new particle is created. To maintain a regular emission rate, the particle system will also need to keep track of how much time has elapsed since the last particle was emitted, and reset that value each time a new particle is emitted.
Forces: Adding one or more external forces acting on a particle system can create a greater degree of realism. You can assign a force vector to each particle system.
Current state: If youre creating an explosion effect, in that case after a while youll want the system to stop emitting new particles therefore youll need to include a variable to track which state the particle is in.
Blending: Most particles systems use some form of blending. You can include the source and destination blend settings to pass to the blend function.
Representation: You can store information about the representation within the particle system itself. For example, if youre using texture maps, you can store the name of the texture.
Just as we store certain attributes of a particle, youll need to decide what attributes we want to store for a particle system.
Particle List: One of the most important attribute will be a pointer or reference to the particle list.
Position: particle system must be located somehwere to determine were particles start.
Emission Rate: determines how often a new particle is created. To maintain a regular emission rate, the particle system will also need to keep track of how much time has elapsed since the last particle was emitted, and reset that value each time a new particle is emitted.
Forces: Adding one or more external forces acting on a particle system can create a greater degree of realism. You can assign a force vector to each particle system.
Current state: If youre creating an explosion effect, in that case after a while youll want the system to stop emitting new particles therefore youll need to include a variable to track which state the particle is in.
11. Methods of a particle system Initialize
Update
Render
Move
Get/Set force Here are some of the common methods youll need to implement for a particle system class.
Initialize: Set the properties to create the desired effect.
Update: Use time delta to update the particles managed by the system. This function can also decide on whether to release one or more new particles.
Render: This function will just loop thru its particles and use their position, size and color to render.
Move: You may want to relocate the entire particle system in your 3d world.
Get/Set Force: You may want to modify the force acting on the system as it changes over time.Here are some of the common methods youll need to implement for a particle system class.
Initialize: Set the properties to create the desired effect.
Update: Use time delta to update the particles managed by the system. This function can also decide on whether to release one or more new particles.
Render: This function will just loop thru its particles and use their position, size and color to render.
Move: You may want to relocate the entire particle system in your 3d world.
Get/Set Force: You may want to modify the force acting on the system as it changes over time.
12. Implementation - Particle struct Particle
{
Vector3 m_pos; // current position of the particle
Vector3 m_prevPos; // last position of the particle
Vector3 m_velocity; // direction and speed
Vector3 m_acceleration; // acceleration
float m_energy; // determines how long the particle is alive
float m_size; // size of particle
float m_sizeDelta; // amount to change the size over time
float m_weight; // determines how gravity affects the particle
float m_weightDelta; // change over time
float m_color[4]; // current color of the particle
float m_colorDelta[4]; // how the color changes with time
}; Here is an example of how we can implement a Particle. In most cases youll create a base class which will have the most common attributes and methods and then for specific effects you can inherit from the base class. For example you can have a particle base class and then specific classes for smoke or fog.
This struct is just outlining some of the common attributes you may want to store.
Here is an example of how we can implement a Particle. In most cases youll create a base class which will have the most common attributes and methods and then for specific effects you can inherit from the base class. For example you can have a particle base class and then specific classes for smoke or fog.
This struct is just outlining some of the common attributes you may want to store.
13. Implementation - Particle System class ParticleSystem{
public:
ParticleSystem(int maxParticles, Vector3 origin);
// abstract functions
virtual void Update(float elapsedTime) = 0;
virtual void Render() = 0;
virtual int Emit(int numParticles);
virtual void InitializeSystem();
virtual void KillSystem();
protected:
virtual void InitializeParticle(int index) = 0;
Particle *m_particleList; // particles for this emitter
int m_maxParticles; // maximum number of particles in total
int m_numParticles; // indicies of all free particles
Vector3 m_origin; // center of the particle system
float m_accumulatedTime; //track when waslast particle emitted
Vector3 m_force; // force (gravity, wind, etc.) acting on the particle system
}; Here is an implementation of the particle system class and some the methods youll need when implementing a particle system.
Notice some of the most important attributes of particle system are the reference to a list which stores all the particles which will be accessed by methods and also the origin.
Here is an implementation of the particle system class and some the methods youll need when implementing a particle system.
Notice some of the most important attributes of particle system are the reference to a list which stores all the particles which will be accessed by methods and also the origin.
14. How to represent particles? Points
Lines
Texture-mapped quads
Point Sprites How do we represent a particle?
The most common ways of representing a particle are:
Points: Points can be used for a number of effects, especially that arent viewed closely.
Lines: Lines can be used to create a trailing effect. The lines connects the particles current position with its last position.
Texture-mapped quads offers the greatest flexibility, and are probably the most widely used. The particle itself is a quad or pair of triangles, which alows to have any texture drawn over it. One example of this would be to use an image of an actual spark as the texture for a spark particle.
Point Sprites are basically hardware-accelerated billboards capable of being textured. Rather than specifying a texture-mapped quad, which requires four vertices and all of their relevant attributes, you speicify particles as a single point, which reduces the amount of geometry sent to the graphics card. For each point, OpenGL will automatically calculate a billboard and apply any enabled textures to it.
How do we represent a particle?
The most common ways of representing a particle are:
Points: Points can be used for a number of effects, especially that arent viewed closely.
Lines: Lines can be used to create a trailing effect. The lines connects the particles current position with its last position.
Texture-mapped quads offers the greatest flexibility, and are probably the most widely used. The particle itself is a quad or pair of triangles, which alows to have any texture drawn over it. One example of this would be to use an image of an actual spark as the texture for a spark particle.
Point Sprites are basically hardware-accelerated billboards capable of being textured. Rather than specifying a texture-mapped quad, which requires four vertices and all of their relevant attributes, you speicify particles as a single point, which reduces the amount of geometry sent to the graphics card. For each point, OpenGL will automatically calculate a billboard and apply any enabled textures to it.
15. Render Particles as Points glBegin( GL_POINTS );
glVertex3f( m_position.x, m_position.y, m_position.z );
glEnd(); How do we render particles?
If youre rendering a Particle using points then its easy, you can provide the points to the glVertex function.How do we render particles?
If youre rendering a Particle using points then its easy, you can provide the points to the glVertex function.
16. Render Partices as Lines glBegin(GL_LINES);
glColor4f( r, g, b, 0.1f );
glVertex3f(m_position.x, m_position.y, m_position.z);
glColor4f( r, g, b, a );
glVertex3f(m_position.x + m_direction.x,
m_position.y + m_direction.y,
m_position.z + m_direction.z);
glEnd(); If were rendering particles as lines, that is pretty straight forward as well, we just provide a set of points.If were rendering particles as lines, that is pretty straight forward as well, we just provide a set of points.
17. Render Particles as Quads glBegin(GL_TRIANGLE_FAN);
if(textured)
glTexCoord2f(0.0f, 0.0f);
glVertex3f(pts[0].x, pts[0].y, pts[0].z);
if(textured)
glTexCoord2f(1.0f, 0.0f);
glVertex3f(pts[1].x, pts[1].y, pts[1].z);
if(textured)
glTexCoord2f(1.0f, 1.0f);
glVertex3f(pts[2].x, pts[2].y, pts[2].z);
if(textured)
glTexCoord2f(0.0f, 1.0f);
glVertex3f(pts[3].x, pts[3].y, pts[3].z);
glEnd(); Here is how we can render a texture-mapped quads as a particle. If were using a texture then we can bind the texture to coordinates and vertices.Here is how we can render a texture-mapped quads as a particle. If were using a texture then we can bind the texture to coordinates and vertices.
18. Render Particles as Point Sprites glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
glEnable(GL_POINT_SPRITE);
glBegin( GL_POINTS );
glVertex3f( m_position.x, m_position.y, m_position.z );
glEnd();
glDisable(GL_POINT_SPRITE); To render points as point sprites it takes a few more steps.
First you need to verify that the implementation supports them.
Make sure youre using OpenGL version 2.0 or have the ARB_point_sprite extension.
Then tell open gl to automatically calculate the texture coordinates for the points youre going to generate and texure youre using. Enable point sprites,
Draw your points
And finally disable point sprites.
To render points as point sprites it takes a few more steps.
First you need to verify that the implementation supports them.
Make sure youre using OpenGL version 2.0 or have the ARB_point_sprite extension.
Then tell open gl to automatically calculate the texture coordinates for the points youre going to generate and texure youre using. Enable point sprites,
Draw your points
And finally disable point sprites.
19. Point Sprites vs Textured Quads Point Sprites dissappear suddenly
Cannot rotate a point.
Point sprites are not supported in older cards.
Point sprite size is dependent on available OpenGL point sizes.
Even though point sprites have a number of advantages there some reasons why you may want to use texture-mapped quads over sprites. Some of the disadvantages of using point sprites are:
Since point sprites are transformed in the pipeline as points, they are clipped by their center vertex position. So they can disappear suddenly around the edges of the screen when the center vertex goes off the screen.
You cannot rotate a point, youll need to rotate the associated texture coordinates in a fragment shader.
Point sprites are not supported in older cards.
Point sprite size is dependent on available OpenGL point sizes.Even though point sprites have a number of advantages there some reasons why you may want to use texture-mapped quads over sprites. Some of the disadvantages of using point sprites are:
Since point sprites are transformed in the pipeline as points, they are clipped by their center vertex position. So they can disappear suddenly around the edges of the screen when the center vertex goes off the screen.
You cannot rotate a point, youll need to rotate the associated texture coordinates in a fragment shader.
Point sprites are not supported in older cards.
Point sprite size is dependent on available OpenGL point sizes.
20. Snowstorm - Demo This example is a simple snowstorm effect. Uses textured quads to represent individual snowflakes and emits the particles from a rectangular area.
This example is a simple snowstorm effect. Uses textured quads to represent individual snowflakes and emits the particles from a rectangular area.
21. Particle Systems API 2.0 Free Particle System
Much lighter than a full physics engine
Simulations of groups of moving objects: explosion, bounce, etc.
Download from www.particlesystems.org
Demo One of the things I wanted to share is that is a freely available API I found on the internet that I plan to use for my part of the final project.
The Particle System API allows C++ application developers to easily include dynamic simulations of groups of moving objects. It is especially useful for eye candy in games and screen savers, but is also used in off-line animation software.
The API is much lighter weight than a full physics engine.
You can create a group of particles, then describe the components of the particle effect using actions like Gravity(), Explosion(), Bounce(), etc.
You apply the actions to the particle group at each time step, then read back the particle positions and other attributes into your app.
One of the things I wanted to share is that is a freely available API I found on the internet that I plan to use for my part of the final project.
The Particle System API allows C++ application developers to easily include dynamic simulations of groups of moving objects. It is especially useful for eye candy in games and screen savers, but is also used in off-line animation software.
The API is much lighter weight than a full physics engine.
You can create a group of particles, then describe the components of the particle effect using actions like Gravity(), Explosion(), Bounce(), etc.
You apply the actions to the particle group at each time step, then read back the particle positions and other attributes into your app.
22. Advanced Topics Adding Scripting capability
Particle Systems Manager
Improving Particle Systems with the GPU Some of the advanced topics you might find useful are:
Scripting: allows you to make your particle system more flexible. It makes it possible for you to change the behavior of the particle system without requiring recompilation of the game.
Particle Systems Manager: If you have multiple particle systems within a game, you might consider adding another layer of particle systems manager. This layer can do things like move particle systems around, change the focus acting on particle systems, create or kill certain particle systems.
Improving particle systems: you can use GPU to implement a stateless particle system which means that particles position and velocity are calculated in the GPU giving you a much better performance. Some of the advanced topics you might find useful are:
Scripting: allows you to make your particle system more flexible. It makes it possible for you to change the behavior of the particle system without requiring recompilation of the game.
Particle Systems Manager: If you have multiple particle systems within a game, you might consider adding another layer of particle systems manager. This layer can do things like move particle systems around, change the focus acting on particle systems, create or kill certain particle systems.
Improving particle systems: you can use GPU to implement a stateless particle system which means that particles position and velocity are calculated in the GPU giving you a much better performance.
23. Refernces More OPENGL Game Programming Dave Astle
http://www.particlesystems.org/
http://www.2ld.de/gdc2007/EverythingAboutParticleEffectsSlides.pdf
www.evl.uic.edu/aej/527/lecture05.html
mit.edu/groups/el/projects/spacewar/
http://www.mirwin.net/
http://www.javaworld.com/javaworld/jw-05-2006/jw-0529-funandgames.html?page=1