MART Term 3, Lecture 1
Particles for Beginners

Particles

Today we're going to play around with particles a little. As per usual, this lecture will only show you the basics: particles is an enormous part of Maya. Animation of particles takes a long time to get right, so it is best, like a lot of things, not to use it unless you absolutely have to.

[screenshot: MART_T3L01_html_m6444351b]It is also worth pointing out that there are some very nice examples built in to Maya: for example, get a new scene, create a nurbs sphere, and select Effects → Create Fire (from the Dynamics menu set). Press play and you'll see the particles. They come out green in a viewport, but do a quick render (click on Window → Rendering Editors → Render View... or on the left-most clapper board icon at the top of the screen) and you'll see that they look pretty nice. While we're looking at the effects menu, try fireworks too. Again, the default options look pretty nice, but there are also loads of settings to change in the ❐ box of the menu item. Once you know a bit about particles, it is possible to learn a lot by dissecting these examples.

The Particle Tool and Particle Emitters

There are two (main) ways to create particles. One is to use the particle tool, which lets you draw particles straight in to the viewport, and the other is to create an object which emits particles over the course of your animation. First let's look at the former. Select Particles → Particle Tool. Now, in an orthographic viewport, click in various places, and you'll see little crosses appear. Press enter to finish with the tool, and you'll see there are little dots at each point you clicked on.

[screenshot: MART_T3L01_html_m3279dd50]Now the thing about particles is that you usually want a lot of them: usually a minimum of a few hundred, with large particle systems comprising tens of millions. So clicking the mouse for each one is not often the best way. There is also the option to sketch particles: bring up the options of the particle tool (by clicking the ❐), and set the options as shown. Now we can sketch the particles in, and it's much easier to drop a few thousand particles in. We could also make an object live and sketch them on the surface of it if we wanted.

Finally, we can be more scientific and add particles in a grid. We set the spacing between particles, and then we can either click in a viewport to define the two corners, or type them in. Click on Create Particle Grid and With Text Fields, and type in the following values for the two corners: <-10,-10,-10> and <10,10,10>. Now press enter (you may have to MMB click in a viewport* for this to work) and the particles will appear.

Open up the attribute editor, and go to the particleShape1 node. This is where most of the adjustment of the particle systems happens: there are a LOT of attributes for particles, so we'll look at them as we come across them. Towards the top is a (locked) attribute called Count: this shows you how many particles the object contains (each individual particle is a component of the Particle1 object, in the same way that a vertex is a component of a polygon object).

Emitters

Let's delete our grid and try creating particles in a different way: we're going to make objects that emit particles. We can either create an emitter without a visible object, or we can take an existing object and make it emit. Let's start with the first.

Now that we're going to be moving our particles, we need to set Maya to Play Every Frame: this is in the Settings > Timeline section of Window → Settings / Preferences → Preferences.... The reason for this is that the position of each particle in a frame will depend upon its position in the last frame: if Maya has to drop frames in order to play back in real-time, the results will be incorrect and not reproducible.

[screenshot: MART_T3L01_html_30290094]Go to Particles → Create Emitter. There are three types of emitter that do not have a "physical" shape: omni (the default), directional, and volume. We have just made an omni emitter, which throws particles out in all directions. A couple of attributes are immediately helpful: Rate (Particles/Sec) (in Basic Emitter Attributes) lets us change how many particles it emits every second, and Speed (in Basic Emission Speed Attributes) let's us change how fast they move. Try playing with these values.

Now change the emitter to a directional emitter. All the particles now go in the same direction (they may be difficult to see: try moving the emitter up and playing the animation again). This is useful, but it would be better if we could spread them out a little bit. Thus we want to change the spread parameter: set it to about 0.2. We can also change the direction of emission using the Direction X, Y, and Z parameters. Change the direction so that it's going straight down (Direction Y = -1). Now turn the rate up to 10,000, and the speed up to 5. We can also change speed random: this adds a random factor to the speed, to make it look a little less faked. Change the playback range to 0 - 1,000, make sure you have the frame rate displayed on screen (Display → Heads Up Display → Frame Rate), and play the animation all the way through.

[screenshot: MART_T3L01_html_m5befafb7]What you'll notice is that the frame rate gets lower and lower as more particles are added. I got bored of waiting when it was on frame 500 or so at 7 frames per second, with about 200k particles. For this reason, it is not only important to think about how particles are created, but also how they are destroyed. If you zoom out, you'll see that we have a huge trail of particles that are no longer on screen: it is important to remove ones that are no longer needed. For this reason, The particleShape node has a lifespan: an attribute which kills off the particle after a certain time. Change Lifespan Mode (in Lifespan Attributes) to Random range. The range (for some bizarre reason) is in seconds, so set it to 4. If you wish, you can also change Lifespan Random, which acts in a similar way to the Speed Random that we saw before. Now when we play back the animation, the particles that are more than 4 seconds old get destroyed so that Maya doesn't have to think about them any more, and thus our frame rate stays constant (after the first 100 frames).

Get a new scene. Now we'll have a look at the last type of simple emitter. Go to the ❐ box of Create Emitter, reset the settings (though I don't think we used them before) and create a volume emitter. This does exactly what the name suggests: instead of emitting from a point like the previous two, it emits from a volume. There are lots of nice attributes for volume emitters: I won't go into any now, but play around with the Volume Speed Attributes section if you're interested.

Rendering Particles

Now we'll look at different ways to render our particles. Though our particles are just points in space, we can choose different ways for them to look.

Create a directional emitter that emits upwards, with a little spread, and a lifespan of 10. Now select the particles, bring up the attribute editor of particleShape, and find the Render Attributes section. We can now try the different drawing styles.

They are:

All of the above rendering types use hardware rendering. This means that they need to be rendered using the Maya Hardware renderer, rather than Maya Software (the default) or mental ray. If you don't know what this means, don't worry, we'll cover it later. The following are software rendered:

Fields

Our particles at the moment have two events in their lives: they start moving in a particular direction when they are created, and they die (and therefore stop moving). How do we go about changing their direction? We use fields.

Go back to points or streaks (something small, anyway). Have a play with all of the different fields on the Fields menu; they're mostly self-explanatory:

If you select the particles first, then when you create the field it will automatically affect the particles. If you don't, select both the field and the particles, and go to Fields → Affect Selected Object(s).

Snowfall

Having done this, try to simulate snowfall using the following file as a sprite:

snowflakesprite.png

Try it yourself first, but if you don't know where to start, here are a few hints:

Save this scene: we'll come back to it later.

Batch Rendering

When rendering out an entire animation, we do not have to click Save file in the render view for each frame in turn: on the render menu there is a Batch Render command. The options of this let us choose how many processors to render on: given that these are multiprocessor machines, you'll probably want to change this to Use all Available Processors. This isn't the only way to batch render though: we can also batch render on the command line. Not only does this give us the ability to use complicated shell scripts to control our rendering (if we so choose), but it also gets rid of the memory overhead of running the GUI all the time.

I have already set up a Maya scene file for us to batch render: it's a scene with Maya's default fireworks in (Effects → Create Fireworks), and it will serve this purpose nicely:

batchrender-fireworks.ma

In order to batch render it, first open up a terminal window. Now copy this file to your home directory:

cp batchrender-fireworks.ma ~/

The command to use for batch rendering is Render (not to be confused with the command render, which lets us batch render Renderman files). Running

Render -help

will give us a clue about the options for it. At first glance there don't seem to be many options, but there is a hint at the bottom of the output:

Specify a valid -r option to get a more detailed help about a renderer.

For example: Render -help -r sw

Running this command gives us all the options for the Maya software renderer: a much longer list of command arguments. As you can see, we can change lots of things about our render without even having to open up the scene file. The most important switch for this lecture is this one:

-rd path Directory in which to store image files

If we all tried to render to /bacva1 at the same time, the whole thing would clag up horribly. So we'll render to /tmp/transfer: make a new directory there (called "lemon", or whatever), and run the following command:

Render -rd /tmp/transfer/lemon/ batchrender-fireworks.ma

You should find that this goes away and renders, but not for very long. The reason is that in the render globals of our scene, the start and end frame are not set correctly. Fortunately, we can again change this without opening the scene file. Going back to our list of flags, we see:

-s float Starting frame for an animation sequence
-e float End frame for an animation sequence

There is also the following:

-n int Number of processors to use (0 indicates use all available)

We can use the -n 0 flag, although the default is usually to use all available processors. The start and end frames are 1 and 250 respectively, so our command has now become:

Render -rd /tmp/transfer/lemon/ -s 1 -e 250 -n 0 batchrender-fireworks.ma

Run this command, and Maya will go away and render all 250 of the frames (it'll take about 10 minutes or so).

Note: it is possible to render remotely using ssh. If you wish to do this you MUST reduce the priority of your render using nice: if you don't know how, find out before you render.

When it's done, we'll use fcheck to have a look at it. On the command line, fcheck will assume we're giving it a single image unless we tell it otherwise. Thus we want to type:

fcheck -n 1 250 1 /tmp/transfer/lemon/batchrender-fireworks.iff

(the numbers refer, respectively, to start frame, end frame, and step number)

The Spreadsheet

Reload the snowing scene, and we'll have a look at yet another useful editor. The spreadsheet only works on the currently selected objects, so go to Edit → Select Hierarchy. Now click on Window → General Editors → Attribute Spread Sheet.

What you'll get is a list of each object in the scene down the left hand side, with different attributes along the top. The names of the various tabs give you an indication of the type of attributes you can expect to find in each tab. The spreadsheet is useful for comparing the attributes of different objects: for example, the intensity of light sources (Shape Keyable tab), the ability of objects to cast shadows (Render tab), and the curve precision (Geometry tab). Notice also that you can change the values in the spreadsheet. If you want to play around with it a bit more, you might want to load a scene with more stuff in it.

Split Your Outliner

[screenshot: MART_T3L01_html_m2cc116f]While we're on the subject of random things that are useful, let's do a couple more. At the bottom of the outliner window there is a "split" that you can drag upwards, and therefore you can be in two different places in it at once.

Virtual Sliders in the Attribute Editor

We know that we can select an attribute in the channel box and use it as a virtual slider with the middle mouse button. This is good. But when we're in the attribute editor it doesn't work. How annoying is that? Very, until you know that in the attribute editor you can ctrl-drag on any of the parameters: dragging with the LMB is normal speed, MMB is fast, RMB is really fast.



*MMB clicking a viewport makes that viewport active (i.e. it has the blue line around it) without selecting any objects in it.