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.
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.
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.
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).
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.
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
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.
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.
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.
Points – As we've just seen, points are just points in space. If you click on
Add Attributes For Current Render Type, you can change their size.
MultiPoint – This simulates higher particle numbers by using multiple points for each particle.
MultiStreak – Like
MultiPoint, but for
Numeric – Not useful for rendering, but useful during testing. The particles do not render, but in the viewport they appear as the value of an attribute (by default the particleId) in text form.
Spheres – Particles are rendered as solid spheres. Transparency can't be used with this rendering method.
Sprites – These allow the user to put an image onto each particle. For example, the image of a snowflake in a snowstorm. In order to add the image, go to
Particles → Sprite Wizard, and find your picture. You can use sequences of images if you like.
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:
Blobby shapes – This rendering method creates metaballs: each particle is a sphere, but when it gets close to another sphere they blend together nicely. This is very useful for fluid simulations, as it creates a globular kind of effect.
Cloud – Very similar to blobby surface but blurred or cloudy, to appear like smoke.
Tubes – Particles appear as tubes, with a start radius, end radius, and tail size. Kind of like 3D streaks.
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:
Drag – Slows particles down, depending on their speed.
Gravity – Accelerates particles in a particular direction (downwards by default (right)).
Newton – A "true" gravitational field: attracts the particles towards it. You can make them orbit it if you try.
Radial – Similar to newton.
Turbulence – Adds some pseudo-random motion to the particles, akin to Brownian motion. Very useful, but often takes a while to get the settings right.
Uniform – Similar to gravity.
Volume Axis – These are weird. The only way to really figure out what they do is to have a play around with them. From the documentation: "With clever use of this type of field, you can create effects such as particles flowing around obstacles, solar flares, explosions, tornadoes, and rocket exhaust."
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).
Having done this, try to simulate snowfall using the following file as a sprite:
Try it yourself first, but if you don't know where to start, here are a few hints:
surface emitter to emit particles over a large area uniformly
Use a turbulence field to make them wobble a bit on the way down
If some start going upwards, use a gravity field to pull them downwards
If some start going too quickly, use a drag field to slow them down
Save this scene: we'll come back to it later.
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:
In order to batch render it, first open up a terminal window. Now copy this file to your home directory:
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
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:
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:
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:
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:
(the numbers refer, respectively, to start frame, end frame, and step number)
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.
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.
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.