Hello,
lately, I played a bit with particle systems (while developing SpaceCombat). I got some ideas and I post them here. Maybe something of that is useful for your projects...
Have more than one texture
First of all, I wanted more than one texture in a particle system. I achieved this by create a patchwork texture assigned it to the particle system.
In step 2 I put four texture coordinates in the SParticle struct. So, a particle generator can set the texture coordinates for each particle.
Finally, I put some code in the particle scene node, that draws the particles with the texture coordinates from the SParticle struct.
Done!
Separate calculation and drawing
A particle system has two tasks: calculation and drawing. Because both tasks takes some time, it is worthwhile to separate these tasks. So you can put them in different processes that can be done on separate CPU cores.
So, we remove the doParticleSystem() from the OnRegisterSceneNode() in the particle scene node and make it public. Additionally double the particle array (double buffer). Now we can work on one of both arrays while drawing the other one.
You have to sync both tasks at the end of each frame. Here you have to swap the particle buffers. Note, that you also have to copy new generated particles.
Sort the particles by distance to camera
When you now have particles, that can be good visual separated (e.g. wreckage), then it is essential, that the particles are drawn from back to front. (Or else objects far away maybe drawn over near objects). Since you separated the calculation, computing power is no problem. This can be achieved by a particle affector.
Fade particles near the camera
When you create clouds or smoke with particles and want to move through, you get some flickering. This occurs, when a particle is in one frame in front of the camera and in the next one behind it. My solution: Sort the particles by the distance to the camera (we do it already) and fade the particles near the camera out. So you get a smooth fading, when moving through the particles. This can be achieved by a particle affector.
Start a particle system with existing particles
I wanted a weather effect (sand storm) with a particle system. But this storm should be there, when the game starts. When you use the build-in particle system scene node, initial there is no particle and they will be generated as the time runs. That wasn't the effect, I wanted. So I tweaked it a bit.
Create an init function, that runs several loops of the doParticleSystem() function. You have to increase the time, that this function takes. Since all affectors work on this time, the result is a fast-forward of the whole particle system. Now you have to save this last time stamp (--> initial time).
Whenever in the game the function doParticleSystem() is called, increase the given time by the initial time.
Done!
Some ideas on particle systems
Re: Some ideas on particle systems
Several of those waste CPU time unnecessarily, and would be handled much better by shaders.
For example you could make a sand storm entirely gpu-side, including fading close to camera.
For example you could make a sand storm entirely gpu-side, including fading close to camera.
Re: Some ideas on particle systems
Maybe you are right.
But in my game, it takes about 30ms to draw a complex scene and only 5ms to calculate the collsions, AI, scripts and so on (one one CPU core!). So I have plenty of CPU power but none of GFX power. So, I try to get as much as possible done on the CPU...
Note, I have two tasks running, one is drawing with Irrlicht, the other one does all calculations. Both tasks are sync'd at the end of each frame.
But in my game, it takes about 30ms to draw a complex scene and only 5ms to calculate the collsions, AI, scripts and so on (one one CPU core!). So I have plenty of CPU power but none of GFX power. So, I try to get as much as possible done on the CPU...
Note, I have two tasks running, one is drawing with Irrlicht, the other one does all calculations. Both tasks are sync'd at the end of each frame.
Re: Some ideas on particle systems
Fading should also be done when a particle is near the Z value not only the camera. This will make smooth particles also near walls (ofcourse not need in a space game XD)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me