View Full Version : Fireworks Simulation

08-31-2006, 12:38 AM
Hi! I'm planning to create a 3D fireworks simulation with OpenGL for a school project. I'm an absolute beginner to OpenGL, that's why I would like to check on some premises before I start doing anything.

The major challenge will be the handling of the many tiny particles which emerge upon the burst of most pyrotechnic products.

a) Intuitively I would model the particles as bodyless light emitting objects. Is this idea suitable to OpenGL?

b) Poses the modelling of many (1000s of) objects specific problems in OpenGL?

c) Since I'm most experienced with Java, I'd like to program with the JOGL API. Does this implicate any important limitations?

d) There will be 180 hs of time available. Any chance?

Every hint is appreciated! Thanks a lot!

08-31-2006, 01:24 AM
What you need is a particle system. I suggest you start with rendering points - place them at center of explosion and throw them in random directions. So you will need an array of positions and array of velocities and simulate this on CPU.
At first use just glBegin/glVertex/glEnd to draw your points but when you have it working then start using vertex arrays - it will be much faster.
When you're done with points, you can replace them with small quads with a texture (a bright, glowy circle), and make these points leave a trial - every moving point will leave a copy of itself behind - that copy would fade away.
You don't need any lighting for it - just quads with textures and alpha blending.

08-31-2006, 02:13 AM
Great suggestions, thanks a lot. You have anticipated a lot of ideas. I think I have some starting point now.

One more question: Do you think it will be possible to render in real time on a not high-end system?

- AMD Athlon 64 3200+ 2.0GHZ
- 512 MB RAM
- ASUS Extreme AX800 graphic card with ATI Radeon X800 VPU (PCI-Express, 16 Lanes Native Support, 6 Vertex Shader Pipelines, OpenGL 1.5)

08-31-2006, 02:50 AM
No performance problem for fireworks, unless you have too many particules :)

08-31-2006, 03:08 AM
I'm relieved. Thanks for comment.

08-31-2006, 12:49 PM
Incidentally, I think that ATI X800 should have OpenGL 2.0 support. Have you updated your drivers lately?

08-31-2006, 10:22 PM
Hi Lupo!
I have just created 3 months ago a Particle System for my game engine.
With it you can also create fireworks effects.

Let me help you giving you some tips:
1) Use a point-sprite particle system. This will be enough for fireworks and its easier than using a billboard particle system. You must use the point sprite OpenGL extension. Don't panic because of the word! It's easy ;)
2) I don't know how real you want it. For cool effect you should add some additional properties to your particles in addition to Position, Velocity, Acceleration, Particle_Life_Time and Color.

I want really cool effects you must add Color per particle coloring. In this way you can control the color of each individual particle.

There an intresting concept called "Milestones", that is when a particle's Life reached the Milestone value something else happens. In my particle system I have Color milestone and Alpha Milestone. In this way, if Color Milestone for the particle system is 80%, then when a particle's life reaches 80% the color will fade with ColorFadeVelocity(R,G,B). That is, you will need to add ColorFadeVeloicity as a propery for each particle system.

As with the other mielstone, If the Alpha Milestone is 50% then the particle starts becoming transparent at a rate of AlphaFadeSpeed(seed).

This enables you to add special effects such as particles that change colors, or that fade to transparent. The milestones feautre provides an intresting effect, since the colors of the particles persist and only change once reached certain point of the particle's life. The changes are gradual, so the effects can be astonishing.

3)If you are concerned with performance then you should use Vertex Arrays (OpenGl feature). Others may argue that you should use Vertex Buffer Arrays (and they are right! :) ); However, this vertex arrays is very easy to implement and should do fine (I am still using vertex arrays).

Beware that if you are just rendering fireworks then you will probably have no problems at all! :)
My particle system renders with a full skybox, mountainbox, animated clouds, and some complex vertex objects and it only consumes few FPS.
So you will probably have no problem.

Another important feature is Velocity Varianze. That is you must add and stochastic factor -a random factor- to your particle system in other to make particles follow different directions.
In each frame, each particle's velocity is updated with the Velocity Varianze factor. If the factor is 0 then all particles will be superposed and follow the same direction. If the factor is very large, particles will behave very randomly going everywhere.

Last thing to consider is Emmission Mode.
Emmision modes can be point, line, plane, volume, etc. The easiest to do is point emmision, which will be useful for you fireworks. However, doing line, plane, or volume emmiision is easy. Just change the initial position values by multiplying with random numbers in some predermined intervals. In other words, doing all the emission modes mentioned above is really easy, for example for volume emission multiple the original position values (the position where the particles revive after dying) by (Random(-3,3) ,Random(-3,3),Random(-3,3)) to get an emmission cube of sides equal 6.
Multiply by (Random(-3,3) ,0,0)
to get 6 length emmission line.

Just to mention, if you don't know, as I said before particles have a property called Life. You must define in the particle system what is the maximum time they can live. Once this time is reached particles must 'die' and regenerate. Particles are regenerated with the emission modes mentioned above at a particular point, region or volume.

For the particles to regenerate, it means that the memory of the pointer particle is reused and taken to the list of active or alive particles.

This may all sound difficult, but it isn't! ;)
Don't start alone. Learn from examples.

These are the examples that helped me build my particle system:
Simple Particle System Example with Fire (http://www.codeproject.com/opengl/ParticleEngine.asp)
Most inspiring example from Advanced OpenGL Book (http://glbook.gamedev.net/moglgp/code.asp)
Download the whole source code examples. There is a source example on Particle Systems. It's really good. It even includes a script loader. The only drawback is that it's in 2D, however, it should be easy to make it 3D with some changes.

These are articles that helped me learn more about the subject and add new features:
- Article on Milestones and Emitters (http://www.cescg.org/CESCG-2004/web/Sabo-Miroslav/)
- Others call it \'Energy\' instead of Life Time, but the idea is the same (http://www.devmaster.net/articles/particle_systems/)
- Particle system sub systems (http://www.cescg.org/CESCG-2004/web/Sabo-Miroslav/)

Hope all this is useful.
I hope you achieve great success in your project!

180hrs is plenty plenty of time in my consideration! You'll be fine, but work hard so you finish earlier.


09-01-2006, 03:43 AM
Originally posted by Minstrel:
Incidentally, I think that ATI X800 should have OpenGL 2.0 support. Have you updated your drivers lately? Yes, I recently installed Catalyst-Suite 6.8. It seems that the included drivers support OpenGL 2.0. Thanks for the hint!

09-01-2006, 04:15 AM
Dear Rodrix
Thanks a lot for this *load* of information...! Please give me some time for digestion. I would like to comment on some points you've made. So far, again, thank you so much.

09-01-2006, 10:20 AM
Yes it's a lot of information! :)
It's actually a summary about everything a I learned about particle systems on the last months.

Go at your on pace. You will see that as you advance, each one of the points I mentioned will have more meaning.

You are welcome to ask any questions. ;)


09-03-2006, 02:01 PM
Ok, I've read through most of the resources indicated by you. It was very helpful, also the examples worked well. It really seems like an interesting topic, I'm looking very much forward to this project.

The article by Miroslav Sabo gave me a good overview on the principles of particle systems. The examples of the book "More OpenGL Game Programming" gave a good impression of the wealth of possibilities with OpenGL, including particle systems. I'll probably go on now reading a book, i.e. "Beginning OpenGL Game Programming".

Alright, thanks a lot for all the hints and ideas!

09-03-2006, 05:53 PM
You are most welcome!
Wish you success with your project! ;)