Particle engine/effects
Hey, I was wandering how to make all those cute effect called "particle effects" and used by all the new game makers. Things like smoke, explosions, dust, especially explosions. I just need a brief hint on how to make them and I''ll be OK.
ph33l th3 l0v3
ph33l th3 l0v3
Take a few steps:
First, think about what a particle is. Obviously, it''s an object that starts somewhere, then has some behaviour and then it dies. After it dies it''ll respawn and behave likewise. Particles do not all act the same though. A particle effect is made up of a lot of particles, and they all behave quite much the same, but not totally, so there''s a random factor.
Now you should put this in a class, something like this:
Well I didn''t do particles for a long time so it''s not really good but it''s a start. Most of the time particles use the same texture, but the color might be different. So you can add some random value to the r, g and b values. (Or semi-random, most of the time) and give them a semi-random position (not too far away from eachother though) and give them some semi-random velocity. This is in the init function. Then, in the draw function, you draw the particles. The life variabele is more of an alpha value. It''s between 0.0f and 1.0f probably. For each frame you substract a bit of the life, making it fade out. When life reaches 0.0f, the particle should be respawned, which is something like resetting it and reinitting. Also, in the drawing routine, you should apply some force (for example gravity) to the particles, to change the velocity.
This is basically it. But particle systems can be extended very much. For example you could make parent-child particles (for example for fireworks. First the parent particle goes upwards, then the velocity is decreased and at a certain speed it''ll blow up, and the child particles will make the resulting explosing. Get what I mean?) and you could add something like motion blurring to it.
Well, my explaination is really really bad, I just wrote it very fast. There are tons of articles/tutorials about this, but I don''t have any urls at hand. This site has a few, nehe.gamedev.net also has a nice particle tutorial. www.gametutorials.com has one, etc. etc. There is so much to know about this. Once you got a system up and running, you''ll just want to do more and more with it. Particle systems are something you can make as simple or as complicated as you like.
Oh and I forgot to mention, just make an array of CParticles (the class described above) like this:
CParticle g_particle;
g_particle = new CParticle[intNumberOfParticles];
and then do
for int i = 0; i < intNumberOfParticles; i++)
{
g_particle.vInit();
}
and in your main loop
for int i = 0; i < intNumberOfParticles; i++)
{
g_particle.vDraw();<br>}<br><br>Let other people make better replies to your topic. What I just said is pretty badly said but it''s a start. </i> <br><br><font size="1">| <a href="http://www.panoramaengine.com">Panorama 3D Engine</a> | <a href="mailto:HNSProgramming@hotmail.com">Contact me</a> |<br>| <a href="http://msdn.microsoft.com">MSDN</a> | <a href="http://www.google.com">Google</a> | <a href="http://www.sourceforge.net">SourceForge</a> |</font>
First, think about what a particle is. Obviously, it''s an object that starts somewhere, then has some behaviour and then it dies. After it dies it''ll respawn and behave likewise. Particles do not all act the same though. A particle effect is made up of a lot of particles, and they all behave quite much the same, but not totally, so there''s a random factor.
Now you should put this in a class, something like this:
class CParticle{float life;// for RGB color:float r;float g;float b;float xpos;float ypos;float zpos; // Only for 3Dfloat xv; // velocityfloat yv;float zv; // Only for 3D// Probably more// Functions:void vInit();void vDraw();void vRespawn();}
Well I didn''t do particles for a long time so it''s not really good but it''s a start. Most of the time particles use the same texture, but the color might be different. So you can add some random value to the r, g and b values. (Or semi-random, most of the time) and give them a semi-random position (not too far away from eachother though) and give them some semi-random velocity. This is in the init function. Then, in the draw function, you draw the particles. The life variabele is more of an alpha value. It''s between 0.0f and 1.0f probably. For each frame you substract a bit of the life, making it fade out. When life reaches 0.0f, the particle should be respawned, which is something like resetting it and reinitting. Also, in the drawing routine, you should apply some force (for example gravity) to the particles, to change the velocity.
This is basically it. But particle systems can be extended very much. For example you could make parent-child particles (for example for fireworks. First the parent particle goes upwards, then the velocity is decreased and at a certain speed it''ll blow up, and the child particles will make the resulting explosing. Get what I mean?) and you could add something like motion blurring to it.
Well, my explaination is really really bad, I just wrote it very fast. There are tons of articles/tutorials about this, but I don''t have any urls at hand. This site has a few, nehe.gamedev.net also has a nice particle tutorial. www.gametutorials.com has one, etc. etc. There is so much to know about this. Once you got a system up and running, you''ll just want to do more and more with it. Particle systems are something you can make as simple or as complicated as you like.
Oh and I forgot to mention, just make an array of CParticles (the class described above) like this:
CParticle g_particle;
g_particle = new CParticle[intNumberOfParticles];
and then do
for int i = 0; i < intNumberOfParticles; i++)
{
g_particle.vInit();
}
and in your main loop
for int i = 0; i < intNumberOfParticles; i++)
{
g_particle.vDraw();<br>}<br><br>Let other people make better replies to your topic. What I just said is pretty badly said but it''s a start. </i> <br><br><font size="1">| <a href="http://www.panoramaengine.com">Panorama 3D Engine</a> | <a href="mailto:HNSProgramming@hotmail.com">Contact me</a> |<br>| <a href="http://msdn.microsoft.com">MSDN</a> | <a href="http://www.google.com">Google</a> | <a href="http://www.sourceforge.net">SourceForge</a> |</font>
Thanks for the tip, but I really have been troungh that part already. I''m just wandering what should be the behaviour og the particles for smoke, explosions and so on, so they would look 3D and be beautiful.
ph33l th3 l0v3
ph33l th3 l0v3
ph33l th3 l0v3
Behaviour is hard to describe - each effect has differing behaviour and better engines can do more different types of behaviour. An explosion for example emits its particles from a single point and they get smaller. The explosion is spherical and only one wave of particles is necessary. Smoke on the other hand has no point emitter, stays fairly constant in the air, and disappears by drifting down.
As for making it look beautiful; just make sure you have enough particles - you usually get a nicer effect with more particles but i will make your program run slower.
As for making it look beautiful; just make sure you have enough particles - you usually get a nicer effect with more particles but i will make your program run slower.
I was thinking to create a sphere explosion, but there''s a little catch - enlargeing the sphere means more distance between the particles, so this means that there must be a whole bunch of particles to create such an explosion, especially if you have a small particle. Nevertheless thanks for the help. And I just got an idea abou the explosion:
what if I have a big texture and instead of moving the particles, I enlarge them? An explosion probably will be created by 5-10 particles that are big enough but one thing is still bothering be: what blending function should I use? (GL_SRC_ALPHA, GL_ONE)? And what should the texture look like?
ph33l th3 l0v3
what if I have a big texture and instead of moving the particles, I enlarge them? An explosion probably will be created by 5-10 particles that are big enough but one thing is still bothering be: what blending function should I use? (GL_SRC_ALPHA, GL_ONE)? And what should the texture look like?
ph33l th3 l0v3
ph33l th3 l0v3
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement