Join Aaron F. Ross for an in-depth discussion in this video Writing a creation expression to vary color, part of Maya: Particle and Fire Effects (2011).
In this chapter on rendering particles, we will be adding color and glow and other visual attributes to the particles so that they'll be more interesting to look at. Currently in the wireframe view you'll see that they are just drawn in the standard wireframe colors. If I press the 5 key on my keyboard, I can see a shaded display and currently these particles are just showing up in gray in a shaded display. The first step is for me to assign color to the particles themselves and then I can connect that color to a shader, which will in turn render in software, in this case in mental ray.
The first step is to select these rocket particles and to give them a color and then the other particles will inherit the color from the rockets. So this is pretty clever I think. I have got the rocket particle selected and I'll hit Ctrl+A to go to the attributes and then in the Shape node in the Per Particle (Array) Attribute section, I need to add a color attribute and it's going to be a per particle color attribute, because I want each particle to have a separate and distinct color.
To do that I'll scroll down and under Add Dynamic Attributes I will click Color. And you'll see I get a choice, Add Per Object or Add Per Particle, and again, I want a per particle attribute. When I click Add Attribute, once again I should see a new attribute appear in a Per Particle (Array) Attribute section and it says RGB PP. It's a very important particle attribute. It's red, green, blue, of course. Red, green, blue per particle. Probably the most common particle attribute that you'll work with for color is RGB PP.
With RGB PP added now I can put some input into that field. I will right-click and choose Creation Expression. rocketParticleShape.rgbPP. I will select that and middle-mouse drag it down into the expression area and this will have a random function applied to it, just as we did for radiusPP to control the size of the particles. But color is different from radius in that it has three values: a red, a green, and a blue value.
In the language of Maya, a vector attribute is one that holds three values. For example, RGB, red, green and blue, and I want a random value for each one of those. I will set rgbPP equal to something, but in order to tell Maya that this is going to be a vector attribute I have to use the correct syntax, and that is in this case two left angle brackets, or two less than signs. But here it doesn't indicate less than. It's just a syntactical indicator that what's to follow is a vector attribute.
I will start with rand and then of course, once again I have to have a beginning and an end value or a low and high value for the random range. So I will indicate that with a parenthesis. Values for colors in Maya range from 0 to 1. So if I want the full range of red, I would put in the 0,1, and a closed parenthesis. So that's the red part of the vector attribute. I will put a comma after that to indicate okay, now we are moved on to the green element.
In fact, I can just copy this. Ctrl+C, paste it in, and paste it in again, except at the end here I don't need that comma. Erase that with the Backspace key and close the vector attribute with two right facing angle brackets or two greater than symbols. So this is the syntax for a vector attribute. I'll close that with a semicolon. Now just as we saw before with radiusPP, once again, we have to seed these random functions.
Otherwise, each time we play the simulation back, we will get different random colors. So I will go back to the front of the expression here and I will press Enter in order to add a line above this one, and once again it's a seed function. As input to that seed, I am just going to use the particles id. I will select the name of the ParticlesShape node and Ctrl+C to copy that, Ctrl+V to paste it, and once again the attribute I want is particleId with a capital I and a lower case d. Closed parenthesis and semicolon.
So there is the expression to randomize the colors. Now this is going to produce the full range of possible colors, so it may not be that interesting to look at. But once we get the mechanics of all of our expressions working, then we can come back in here and adjust these values to get more aesthetic colors. I'll click Create and look carefully to make sure I don't get any errors. Very good. I will rewind. Let me deselect everything so that we can actually see those colors. I have to be in a shaded view to see the colors. But you will see now that these particles actually have color on them.
I can make them larger so you can see it a little bit better by just going into the attributes and increasing the Radius. So now you can clearly see that each one of those rocket particles has a unique color and it will repeat those same colors each time it plays, so that we don't get any unexpected shifts in color. Cool! So next we will use an expression to transfer that color to the other particles in this system.
- Laying out the scene
- Sketching particles on a Live object
- Connecting particles to Fields such as Gravity
- Emitting particles from particles
- Varying particle shader attributes
- Modeling and shading for the Particle Instancer
- Importing and instancing geometry onto particles
- Randomizing particle rotation with Creation and Runtime Expressions
- Adding Turbulence
- Rendering depth of field with mental ray
- Creating 3D Fluid containers
- Emitting dynamic fluid attributes from an object
- Animating a dynamic fluid
- Using a fluid for atmosphere
- Modulating light intensity with a noise expression