How to create a candle flame using particles



In this lesson you will learn how to create a candle flame by using particles, particle emitters, fields, and shading groups.


Step 1: Open the file

Download and open the file flame tutorial.ma. The file has the dining room, place settings, and a candelabra. Everything has been modeled and shaded so you can focus on creating the candle flames. You will also notice that the time slider is set from 0 to 400 frames. This will be the length of your animation.


Step 2: Create and position a particle emitter.

If not already selected, select the Dynamics menu from your Menu Set to make it active.

 

Next, create a particle emitter by selecting the Particles->Create Emitter->Options menu.

In the Create Emitter Option box, set the following options:

  • Emitter Type to Directional

    By setting the Emitter Type to Directional, the particle emitter will emit particles only in the specified direction. If we had set the Emitter Type to Omni, the particle emitter would have emitted particles in all directions. However, to best emulate a candle flame, we want the particles to all go in the logical direction -- up.

  • Rate to 100.
  • DirectionX to 0.00. (This and DirectionY are under the Emission Direction tab).
  • DirectionY to 1.00.

    Set the direction to up, for the reasons mentioned above.

  • Emission Speed to 0.488.

    By setting the Emission Speed to 0.488, we will (along with other options to be set later) better approximate the motion of a candle flame.

When you have correctly set all of the options, hit the Create button.

The Emitter will be created at the origin of the scene (which unfortunately is not near the table setting), so you will have to move the emitter to the top of the center candle.

At this point, if you press play, you will see a single stream of particles shoot straight upward. The next step is to make the particles behave more like a flame.

 


Step 3: Set Particle attributes such as Lifespan, Type, and Size

In order to make the particles behave more like a flame, we are going to have to change the lifespan the particles, the radius of the particles, as well as the render type (which affects how the radius is interpreted).


Changing the Lifespan

In the Outliner window, select the particle that has just been created. Open up the Attribute Editor either by double-clicking on the icon, or by choosing the Window->Attribute Editor menu. (Make sure that the particleShape1 tab is the one you are working in; the emitter1 tab may come up as the front tab by default).

Scroll down to the end of the dialog box, and make sure that the Per Particle (Array) Attributes and the Add Dynamic Attributes sections are open.

We will control the lifespan of the particle with an expression. To create the expression, right click on the field next to the lifespanPP entry, then select Creation Expression... from the menu.

Type in the expression shown in the image on the right. As you can see, we are setting the lifespan equal to a random value. By using randomness, we will obtain a more natural looking flame. When you're done typing in the expression, hit the Create button to assign the expression to the lifespanPP attribute.


Changing the Particle Type

Maya has several different types of particles. By default, particles are set to render as points (which as with many of Maya's particle types, require a separate hardware rendering pass). As we know from math class, points are infinitely small. Because points are infinitely small, the radius does not effect them.

In order to make our particles look like flame, we need to change our particles to the "cloud" render type. Changing the type to "cloud" has multiple advantages. Maya "cloud" particles will vary according to a specified radius. Maya "cloud" particles will also render in software, so we don't have to make a separate hardware rendering pass.

If you don't already have the Attribute Editor open with the attributes for the particles shown, please open it again.

Scroll down the the Render Attributes section and make sure that it is open. Change the Particle Render Type  to Cloud (s/w).


Changing the Size

If you don't already have the Attribute Editor open with the attributes for the particles shown, please open it again.

Scroll down to the end of the dialog box, and make sure that the Per Particle (Array) Attributes and the Add Dynamic Attributes sections are open.

Click on the General button in the Add Dynamic Attributes section.

When the dialog box appears, select the Particle tab, then scroll down and select the radiusPP option. After you have highlighted radiusPP, select the OK button.

You will see a new field in the Per Particle (Array) Attribute section of the dialog box. To easily control the radius of the particles being emitted, we will use a ramp. To tell Maya that we wish to do this, right click in the edit field of the radiusPP option, then choose the Create Ramp [option box] menu.

Before you press the OK button, be sure that Input U is set to <None>, Input V is set to Particle's Age, and that Map To is set to New Ramp.

Note that the order that you perform the steps is important. If you had not performed the steps outlined in Changing the Lifespan, when you created the ramp, Maya would have added a "Lifespan" field to the Render Attributes section of the particle attributes. Maya does this because when you created the ramp, you specified that one of the inputs would be based on the particles age. Although Maya creates the Lifespan field, it can be overridden later by adding the Lifespan Per Particle Attribute as described above.

After you have created your ramp, right click on the edit field of the radiusPP option, then choose arrayMapper1.outValuePP->Edit Ramp.

Please edit the ramp so it matches the image shown on the right. Set the value of the bottom entry on the ramp to 0.11. Editing ramps can be tricky, so here is a brief description of how it works. The ramp is a one-dimensional gradient of colors; you specify a few key points (denoted by the circle to left and box to right) and specify the colors at those points. Maya interpolates between the two. To add a new point, click inside the color bar. To delete a point, click the box to the right. To move a point, drag the circle (if you try to click inside the bar, you'll just make a new point). Also click the circle if you just want to select that point--the color and other info below will update. So to change the color (which includes the "value"), click the circle to select and then click the color patch below.

What we have done is to set how the radius is mapped to the particle's lifespan. When the particle is first created, it will have a radius of 0.11. As the particle ages, it will decrease in size, the radius eventually shrinking to 0.

 


Step 4: Add a Radial Field and Link it to the Particles

At this point, if you press play, you will still see a stream of particles shoot straight up into the air. Only now, they start out large at the bottom, then get smaller as they raise up in the air. At a position not too far above the wick, they die out. You should be able to see how each of the values that we set in the previous section has effected the particle stream. Feel free to play with the values to see how they effect the particles.

To get the particles to further look like flame, we are going to add a radial field. The radial field will make it look like the flames are moving in the natural air currents that permeate every room.


Creating a Radial Field

To create a radial field, go to the Fields menu, then select  Radial [option box].

In the Radial Field Option box, set the following options, then hit the Create button:

  • Magnitude to 0.8
  • Attenuation to 0
  • Uncheck Use Max Distance

Move the newly created field into the same position as the particle emitter that you worked on in step 2.

In the Outliner window, select the field that has just been created. Open up the Attribute Editor either by double-clicking on the icon, or by choosing the Window->Attribute Editor menu.

In the Transform Attributes section, right click on Translate X field, then select the Create New Expression... menu option.

You have just opened up the same Expression Editor that you had open when you were editing the particle lifespan. Now we will use it to randomly set the position of the radial field.

In the Expression section of the dialog box, perform the following steps. Each of the translate X, Y, and Z entries need to correspond to each of the radial field's translate attributes:

  • Type radialField1.translateX = 32.562 + 0.3*(sin(4*time + rand(-1,.1)));, then hit Create.

    Please replace the 32.562 with whatever value is currently in the Translate X field. In the steps below, perform the same replacement.

  • Next select the TranslateY property and type radialField1.translateY = 13.190 + 0.3*(sin(4*time + rand(-1,.2))); in the Expression box. Press Create.
  • Select the TranslateZ property and type radialField1.translateZ = 16.388 + 0.3*(sin(4*time + rand(-2,.5))); and hit Create again.


Linking the Radial Field to the Particles

We need to link the radial field to the particles in order to tell Maya that the radial field should affect the particles.

To link the radial field to the particles, go to the Window menu and select Relationship Editors->Dynamic Relationships....

On the left hand side of the Dynamic Relationships dialog, select the particle that you created in Step 2. On the right hand side of the dialog, select the radial field. This is all that you need to do to tell Maya that the radial field affects the particles.

 


Step 5: Create a Shader for the Particles

All of the details for particle creation and behavior have now been taken care of. We now need to make sure that the particles are shaded correctly so they look like a candle flame in the rendered images.


Adding Color

To create the particle shader, open up the Hypershade window by selecting the Window->Hypershade menu option.

Inside of the Hypershade window, click on the eraser icon to clear the view.

Right click in the main viewing pane, then select the Create->Volumetric Materials->Particle Cloud menu option.

Once the shader has been created, double click on the shader icon to open up it's attributes.

Move the color slider all of the way to the left to make it black. Because we are making a flame, we are solely going to use the Incandescence field to provide the color of the flame.

Map a Ramp texture to the Life Incandescence field. We are using the Life Incandescence field because it provides all of the functionality of the standard Incandescence field except for one crucial difference. The Life Incandescence field makes the shader assign incandescence values to individual particles based on the age of the particle. We will use this to our advantage to reproduce the effect of a hot flame at the wick, then as the flame rises, it cools and changes color. In the Hypershade window, you can see what has happened. Maya has mapped the age of the particle to the uv position on the ramp.

Double click on the newly created ramp texture, then add and remove colors until you have made your ramp approximately look like the image on the right. You will have to make changes to your color placement until the candle looks correct in the render window. Don't be disturbed by the offset circles and boxes next to the ramp--Maya just does that to avoid overlapping.

Before we can see the ramp applied to the particles, we have to assign the shader to the particles. To do so, select the particles in the Outliner window, then right click on the shader ball in the Hypershade window and select the Assign Material to Selection menu option. Once you have assigned the shader, you will have to go to the Rendering menu set, then choose the Render->Render Into New Window menu option to see how the shader is being applied to the flame. Unfortunately, IPR does not support particle shaders, so you will have to do Render Regions until the colors on the shader are positioned correctly.

Colors for flame


Adding Transparency

After you have created and positioned the color ramp, the next step is to add a transparency ramp.

As with the incandescence value, we will be assigning a ramp to the Life Transparency channel. As with the incandescence value, we are using the Life Transparency value because age of the particle determines which value in the ramp is used as the transparency.

Assign a ramp to the Life Transparency channel of the particle shader. Make the ramp look like the one on the right.

Transparency ramp


Adding Glow

The final step needed to make the flame shader look good is to add a bit of glow.

Make sure that the particle shader is shown in the Attribute window.

Set the Glow Intensity under Common Material Attributes to 0.3

 


Step 6: Adding a Point Light

The final detail we need to do to make the convincing flames, is to add a point light. As we all know from experience, flames emit light. To replicate this, we will add a point light to the flame. We will do it the easy way and just add a stationary light. If you want to do something more realistic, you can make the light flicker by move the point light around and by animating its intensity.


Adding a Point Light

Make sure that the Rendering Menu set is selected.

Select the Lights->Create Point Light menu option.

Select the newly created point light in the Outliner window.

As with the particle emitter we created earlier, move the point light from the origin to atop the center candle.

Open up the Attribute window so we can edit some attributes.

 


Step 7: Repeat Steps 2-6 to Create Flames for the Other Candles

At this point, we are done creating a candle flame. You may want to select all of the components that make up the flame and group them together to keep the Outliner window clean and readable.

The only thing left to do is to duplicate steps 2-6 for each of the other candles. When you duplicate the steps, you can reuse the shader on each of the new flames.

One thing to watch out for when creating the new flames is to insert enough randomness to make each flame look different. Be sure to use different values when specifying the LifespanPP, the RadiusPP, and the positions for the Radial Field.