Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Implementing the particle fountain effect

Implementing the particle fountain effect

Brain
Brain
Firework Factory Development Journal · · 2 min read
4,394 2
So, over the past week i have been busy implementing the first of many different particle effects for the game.

A video of the particle effect can be found here on my YouTube channel.

The whole of the game hinges around pretty (and rather deadly) particle effects, so this is an important part of the design. The first of these effects is a particle "fountain" much like a roman candle firework. The effect is implemented as a combination of a pixel and geometry shader, with instancing used to display many thousands of identical quads each containing a simple texture:

sparkle.png

This texture is used to build up the effect, with each particle having a pseudo-random velocity. Over time each particle is pulled back to earth via a gravity effect, which causes the outwards momentum to drop by 75% and the upwards momentum to be replaced slowly by downwards momentum as shown in the code below.[code=nocode:0]void ParticleSystem::Update(){ for (int i = 0; i < activeParticles; i++) { particles.pos.y += particles.yvelocity; particles.pos.x += particles.xvelocity; particles.pos.z += particles.zvelocity; particles.yvelocity -= particles.falloff; if (particles.zvelocity > particles.initialzvelocity / 6.0f) particles.zvelocity -= particles.falloff; if (particles.xvelocity > particles.initialxvelocity / 6.0f) particles.xvelocity -= particles.falloff; }}
In the game proper, each of these particles will be destructive to any crates they come into contact with so it is unlikely that i will be outputting so many particles during gameplay or this may make the game far too hard.

At present the system does not free particles which have been allocated, as this is for testing only - once i have finished this portion of the game the textures which are allocated will be freed back into a pool (with a maximum of 10,000 at a time) to be displayed when needed.

The particle effect seems to run quite well at over 100 frames per second, so long as fraps doesnt get loaded as fraps does not seem to like my laptop one bit.

Now that we have a basic firework particle effect, i will add the crate movement next and conveyor belts, which are also just as fundamental to the basic gameplay as the particle effect!

Stay tuned for further updates coming soon!

Discussion

Loading comments...