Creating a Simple Particle Effect

Overview

This tutorial covers the basic functions of the particle system, and more specifically, demonstrates how to create a fire effect.

In preparation for the tutorial, start the Sandbox Editor and open an already created level.

Prepare a New Particle Library

Particle Library

Most of the data in CryENGINE is handled and stored in libraries. The Particle Effect libraries are stored in the game folder, under: Game\Libs\Particles.

To create a particle effect, start by preparing a new particle library.

Opening the Database View

On the View menu, click Open View Pane, and then click DataBase View to open the DataBase View.

Adding a New Library

In the Database View, among the tabs at the top of the window, is the Particles tab. This is where all the Particle libraries are found.

Before creating a new particle, choose a library in which to place it. The best way to do this is to first create a new library.

The default library is called Level and should be active. You can create as many Particle libraries as you need. They will each be saved as a separate file in the game folder.

Select the Particles tab and click the Add Library button to create a new library.

In the New Library Name window, enter MyTutorials as the name of the library.

Adding a New Particle Effect to the Library

Click the Add New Item button to add a new particle effect. All effects will be organized in groups. As you don't have any groups yet, you have to create a new group too.

In the New Particle Name window, enter ExampleFire as the name of the Group and Fire1 as the name of the particle.

The new particle will be displayed in the particle list. Now, you're ready to work on it.

On the File menu, click Save to save the progress.

Preparing the Particle Effect

Typically, you will need to prepare the textures before making any new effects. However, this tutorial uses already finished textures and focuses on using the different texture types.

The default location to save the textures for particle use is the Game\Textures\Sprites folder.

Setting Up a Sprite Texture

Make sure that the Fire1 particle is currently selected.

In the Appearance tab (located next to the particle browser list), click the open folder icon next to the Texture text box.

Now, in Game\Textures\Sprites, select the texture called fire_ball6.dds. The path of the texture will be displayed in the Texture text box. You can check the texture when you hover the mouse pointer over the text box.

To align the particle direction to the sprite's movement, select the Orient To Velocity check box.

The next step is for the life time of the particle. To create a continuous fire, select the Continuous check box, in the Emitter section of the particle properties.

To have more than one particle displayed at any time, set the Count (of visible particles at the same time) to 10, and to have each particle rise higher, set the Particle Life Time to 3.

Keep the other values at their default (Emitter Life Time, 0; Spawn Delay, 0; Pulse Period, 0).

In the Movement section, set the Speed parameter to 3 to speed up the particle.

Placing the Particle Effect in a Level

To place the effect in the level, you need to drag the effect from the particle browser list to the level.

Note that you should not drag a child particle into the level, this will not work. You need to use the parent (container) particle.

However, before you do this, activate the Select and Move tool on the Editor toolbar and turn on Follow Terrain and Snap to Objects to make the placement easier.

Now drag the Fire1 particle effect to the level.

You'll be able to see the particle continuously spawning from the emitter. However, right now, it still looks very unrealistic. The next step is to tweak more parameters in the Particle Editor and improve the fire's appearance.

You can use the Goto Selected Object button to align the camera position to be just in front of the emitter.

Save the scene again before proceeding to the next step.

Creating a More Realistic Look

To get a more fire-like look, you will need to tweak a few more parameters within the particle.

Pay special attention to the following options:

  • Spawning condition
  • Appearance
  • Movement

Tweaking How the Sprites Spawn

Go to the Emitter section on the top-left part of the parameter lists. If the Emitter Life Time is set to 0, particles will spawn infinitely, until the emitter is disabled or deleted.

Set Particle Life Time to 1 and the appearance of the particle will change.

The parameter Count controls how many particles are alive in the scene at any time. If it's set to 10, at the time that the particle number 11 is spawned, particle number 1 will disappear.

The Particle Life Time option controls the life time of each particle. If it's set to 3, particles die 3 seconds after they were spawned.

Adding Randomness

Until now, all particles have been spawned in exactly the same way, and this doesn't look natural. To add some randomness, click the + button in front of the Particle Life Time parameter to open its additional parameters.

Set the Particle Life Time Var Random to 0.4.

The particle will start to look a little more irregular now. The Var Random parameter exists for almost all the parameters. The randomness is measured from 0 to 1 (0% to 100%).

If the Particle Life Time is set as 10 (sec), and the Var Random value is set to 1, the particle life time is randomized to be between 0 to 20 sec (/- 100%). If Var Random is set to 0.3, the Particle Life Time is randomized to between 7 and 13 seconds (/- 30%).

For now, though, keep the settings as shown.

Don't forget to save the level from time to time.

The Lighting Tab

Go to the Lighting pane and add the following settings:

  • Set Diffuse Lighting to 0.
  • Set Diffuse Backlighting to 0.
  • Set Emissive Lighting to 3.
  • Set Emissive HDR Dynamic to 3.

The particle will start to glow as shown:

Diffuse Lighting is the most basic lighting parameter for sprites. It controls how much the sprite is influenced by any dynamic or ambient light in the level.

Usually, you have to set an appropriate value for this (like 0.7). However, in the case of a fire that can't actually be lit, you should set this value to 0.

Diffuse Backlighting is a simple parameter to add some brightness to the particle (often called Ambient or Incandescence in common 3D software).

By increasing this value, you can make a more translucent appearance. Conversely, by decreasing this value, you can create a more solid looking particle.

Emissive Lighting and Emissive HDR Dynamic are different from the other lighting parameters. They control emissive lights on the effect; for example, the light that is created by the particle.

Usually, these parameters are used if the particle is self illuminating (like fire, sparks, explosions). Emissive HDR Dynamic works only when HDR is turned on; that is, Config Spec is set as high or highest.

Tweaking the Sprite Alpha Curve

Now, change the lifespan curve to add a natural transparent look to the fire. Open the additional parameters of the Alpha parameter in the Appearance section.

A particle's Alpha value controls how transparent it is. Click and drag the yellow square in Var Particle Life to create a key point (red point).

Double-click the top-left edge of the green line to create a second point and drag this to the bottom of the graph.

Double-click the top-right edge of the curve to create a third point and drag this also to the bottom of the graph.

The Var Particle Life curve controls the Alpha value of the sprite, independent of the texture's Alpha. Longitudinal represents the Alpha value, transversal, the Particle Life Time.

In this case, the particle will be displayed with 0 Alpha value (invisible), then increase to 100% Alpha value at 25% of its life time, and then finally fade out and disappear at the end of its life time.

You can add or delete more key points by double-clicking them, and also move key points by dragging them in both dimensions.

Tweaking the Sprite Scaling and Stretch Parameters

Go to the Size pane and set the Size parameter to 1.3, and then open the additional parameters and set the Size Var Random to 0.4.

Adjust the Size Var Particle Life curve to match the graph below:

Next, add a little stretch effect to the sprite. Set Stretch to 0.2, and set the Stretch Var Particle Life curve as shown below:

The Stretch option will stretch the sprite. A default value of 0 means that the sprite has not been stretched at all; for example, a perfect square shape. In this case, the particle is stretched up to 0.2 at the start of its life and back to a perfect square shape at the end of its life.

Now, the particle will look more like real fire, but with some more tweaking, you can further better it.

Tweaking the Movement and Air Resistance of the Particle

Movement of particles is also very important to add realism to the effect. In this section, you will tweak the particle movement parameters.

Access the Movement tab and set the Speed to 3 and Var Random to 0.4. You'll find the Var Random hidden behind the little + button. The Speed value controls the speed of the particle. It controls the speed along the direction of the Emit Angle, which you will tweak later.

Remember that adding a random value to parameters is an effective way to get a more realistic effect, in most cases.

Air Resistance simulates the denseness of air or any medium where the particle is situated. In a dense medium like water, the energy of motion is consumed faster because water has a higher resistance than air. The opposite is true in space, as particles never loose their velocity.

Set the Air Resistance to 0.2 and the Air Resistance Var Random to 0.4.

Note

Particles with air resistance are also affected by the environmental forces in the level such as wind, turbulence, or global wind. Thus, if you set high values for air resistance, the particles will be strongly affected by the wind forces in the level, maybe so much that you won't see any particles. To avoid this, first try assigning low values (like 0) to the air resistance, and then check the effect.

Tweaking the Angles Tab

Go to the Angles section and tweak some more options.

Set Emit Angle to 20 and Emit Angle Var Random to 1.

The particle's default direction is exactly along the z-axis of the emitter. The changes above mean that the particle emits at a 20 degree angle around the z-axis, and also gets a random direction within -20 to 20 degrees.

If you don't set a Random value other than 0, the particles will always get an exact -20 or 20 degrees direction from the z-axis; consequently, the whole shape of the effect will look like an umbrella turned upside down.

Tweaking the Rotation Tab

Set the Random Angles and Random Rotation Rate as shown below:

These parameters control the rotation of each sprite. The left column refers to the x-axis, the center column to the y-axis, and the right column to the z-axis.

In this case, the particle has a possible 180 degree rotation value on the z-axis when they spawn, and a maximum of 30 degrees random rotation on the z-axis while they live.

For sprite particles like this fire, the x and y axes are not affected at all, because sprites are 2D objects – they have no x- or y-axis. The particle system also supports imported 3D objects, which can be used as particles where all 3 axes are supported.

Soft Particles

When you get closer to the effect and check the area where the particle is intersecting with the terrain surface, you'll be able to see a significant edge at the bottom of the sprite.

To avoid this edge, access the Appearance pane and select the Soft Particle check box.

The edge will be removed and the fire will look even more realistic than before.

You now know how to create a simple 2D particle and how to tweak its basic parameters.