Dream Hills – Particle System

A Particle System is a technique used in Game Physics, Motion Graphics and Computer Graphics to simulate phenomena very hard to reproduce with conventional rendering techniques.
On Dream Hills we have lots of this kind of phenomena and effects like fountains, water splashes, waterfalls, explosions, smoke, dust, electric sparks and more, so we decide to implement our own Particle System and was my responsibility to do it.


First Implementation

Fire Hydrant Particles

The first version of the Particle System was a simple implementation with a mesh representing each points one particle in the system, another mesh and a texture meant to be the graphical representation of each particle, all the particles in the system have the same graphical representation. And of course there were methods to initialize, update and render the Particle System. This implementation allows to render a group of sprites (or 3D models) with a very simple behavior implemented in the update method, and adding a new variable that defines the frame of an animated texture to render on the sprite this particles can be animated.

This behavior wasn’t enough for what we wanted to do on our game, one of the first Particle System we thought we would need was the water that a fire hydrant throws up to the air when it breaks, and after the water goes up has to go down because of the gravity. So because of the gravity, I decide to integrate the PhysX (of NVidia) Particle & Fluid System to our Particle System to let PhysX do the work of the physics on the particles like the rest of the physical objects in the game. Apart for using the PhysX gravity (take a look to the GIF at the right) I wanted to render the water as a fluid (PhysX can simulate a fluid behavior with the particles), but after 3 weeks of trying I had to discard because the volume of particles to render a good looking mass of water was too big and would consume many CPU and GPU resources.

The PhysX Particle System has a lot of variables to play with, like activate or not the gravity, set if the particle is a fluid or not, bouncing, viscosity, if they should collide between them or with dynamic objects in the scene, and some others. All this attributes are cool to have an automatic behavior controlled by PhysX but I wanted to have more control over the particles, like where they spawn, how long they live, their velocity, etc. Because of all this parameters the Particle System starts to become a monster and a pain to manage, so I decided to do a refactor of the system.

Unreal Like Implementation

Unreal Engine 4 Particle System

As the title says, I used the Unreal Engine 4 Particle System as example to develop our Particle System, one of the reasons is because always we wanted to implement a new particle effect we found ourselves looking on examples made on Unreal, and of course because how they did it is one of the best. Then what have they (and I copied) done?. We have 3 levels in the particle system (I am going to use my nomenclature because I am going to keep talking about my system not theirs after this):

  • Particle System: each System represents a whole effect (explosion, electric sparks, etc.) by itself. The class members are a Slots container, and methods to start, stop and reset the system, add and get a Slot, and initialize, render and update each Slot.
  • Slot: each Slot represents a part of an effect, an explosion effect is made by 3 Slots: an animated explosion particle texture, smoke and the shock-wave. The base class members are a Mesh where each point is a particle, another Mesh and Material for the render of each particle, containers for the CPU and GPU data of the particles. This is the base class, but I have implemented 2 derived Slots of it.
    • Particle Slot: this will spawn particles each frame depending on the frequency, emission rate, the maximum number of particles and if the emission loops, also it defines if the particles are rendered in additive mode, if the frequency has to be random (from 0 to frequency), or if the particles should rotate to the velocity vector. This Slot has a container of modifiers.
    • Text Slot: I created this Slot as a fast way to render subtitles on our game, using the same principles of the particles. The class parses a string of characters, and using a texture with the alphabet sets a particle for each character, also is possible to set the position of the subtitles in the screen and modify the size and the offset between each character. We used it for the subtitles and for the countdown in the RC race.
  • Particle Modifier: this Modifiers affects to the attributes of the particle, they can modify the particle when it is spawned (onCreate) or on every frame (onUpdate), this attributes can be the position, scale, color, size, etc. Some examples of modifiers: InitialPosition, InitialColor, ColorOverLife, TimeToLive, etc.



Waterfall Particle System

The waterfall of Dream Hills is the biggest in size and amount of particles of all the particles effects. The first implementations had over 10.000 white deformed sphere particles like the fire hydrant particles. But this approach had a very bad performance so I decided to change it. Now it has 2 Slots, in the next XML code the first slot is the splash and next the fall. The XML is quite self-explanatory. I am using a Smoke texture, the Color by Daytime Modifier sets the initial color of the particle depending if the game is in the Noon, Afternoon or Night illumination, and the Color Over Life Modifier interpolates the color from the Initial Color to the parameter End Color over the TTL of the particle (if the particle does not have a TTL modifier this modifier won’t work)

Smoke Texture


Recollectable Particle System

Another effect that is seen all the time is the bubble of each recollectable that makes them more visible to the player. The Ping Pong Scale Modifier interpolates from min to max and from max to min every second.

Much more

There are much more Particle Systems in Dream Hills like the firecracker explosion and all the projectiles effects, the barbecue smoke, the fireworks in the RC Race, etc. But it would take too long to explain all of them and they are all very similar or combination of them.

Barbacue Smoke Particle SystemFirecracker Particle SystemRC Race Ramp Particle System