Chapter 16. Maya Fluids

Maya Fluids is a suite of tools designed to create a number of fluid-based effects. The tools available in Fluids consist of containers and emitters, which are designed to simulate gaseous effects like clouds, smoke, flames, explosions, galactic nebulae, and so on, as well as dynamic geometry deformers and shaders, which can be used to simulate rolling ocean waves, ripples in ponds, and wakes created by boats.

In this chapter you will learn to:

  • Use fluid containers

  • Create a reaction

  • Render fluid containers

  • Use fluids with nParticles

  • Create a pond

  • Create an ocean

Use Fluid Containers

Fluid containers can be thought of as mini scenes within a Maya scene. Fluid containers are best used for gaseous and plasma effects like clouds, flames, and explosions. The effect itself can exist only within the container. Fluids can be generated inside the container using an emitter or by painting the fluid inside the container. Dynamic forces then act on the fluid within the container to create the effect.

There are two types of containers: 2D and 3D. They work the same way. Two-dimensional containers are flat planes that generally calculate faster than 3D containers, which are cubical volumes. If you do not need an object to fly through a fluid effect or if the camera angle does not change in relation to the fluid, you might want to try a 2D container instead of the 3D container, which can take a much longer time to calculate and render. Two-dimensional containers are also a great way to generate an image sequence that can be used as a texture on a surface.

Use 2D Containers

In this first exercise, you'll work with fluid basics to create a simple but interesting effect using 2D containers. When you set up a container, you can choose to add an emitter that generates the fluid within the container, or you can place the fluid inside the container using the Artisan Brush interface. You'll start your experimentation using the latter method. Later in the chapter, as you work with 3D containers, you'll use emitters.

  1. Create a new scene in Maya. Switch to the Dynamics menu set.

  2. Choose Fluid Effects

    Use 2D Containers

    The simple plane is the 2D container. If you play the scene, nothing happens because currently there are no fluids within the container. In the Outliner you'll see a new node named fluid1. The fluid1 object, like many Maya objects, consists of a transform node (named fluid1) and a shape node (fluidShape1).

  3. Select fluid1 and choose Fluid Effects

    Use 2D Containers
  4. Open the Tool options, and make sure Paintable Attributes is set to Density and Value is set to 1. Paint a few strokes on the container.

  5. Clumps of green dots appear if you are in wireframe mode. Press the 5 key on the keyboard to switch to shaded mode. The clumps appear as soft, blurry blobs (see Figure 16.1).

  6. Set the timeline to 200. Rewind and play the scene. The fuzzy blobs rise and distort like small clouds. They mix together and appear trapped by the edges of the container.

    Use the Artisan Brush to paint areas of density in the 2D fluid container.

    Figure 16.1. Use the Artisan Brush to paint areas of density in the 2D fluid container.

    The properties that govern how the fluid exists within the container and how it behaves are controlled using the settings on the fluidShape1 node. When you painted in the container using the Paint Fluid tools, you painted the density of the fluid. By creating areas of density, you position the fluid in an otherwise empty container.

    Before you start to edit the other properties of the fluid (such as Buoyancy, Temperature, and Color), you can create a much more interesting effect using some of the controls available in the Paint Fluids tool. You can use a file texture to determine the density of the fluid within the container, which is a great way to create an unusual effect.

  7. Rewind the scene. In the options for the Artisan Brush, set Value to 0 and click the Flood button. This clears the container of any existing fluid density.

  8. Set Value back to 1. Scroll down in the options and expand the Attribute Maps rollout. Expand Import and click the Import button.

  9. The File Import dialog box opens. Browse your computer and find the JollyRoger.tif file located in the chapter16sourceimages folder on the DVD. Select this file and click Import.

    When you import the file you'll see a very blocky skull and crossbones appear in the container. The blocky quality of the image is because the resolution of the fluid container is very low, so the resolution of the image is not displayed correctly.

  10. In the Outliner, select the fluid1 node and open the Attribute Editor.

    The resolution for the 2D container is represented by two fields corresponding to the X and Y dimensions of the container. The original JollyRoger.tif texture is 1024′1024. You can raise the resolution of the fluid container to match; however, the higher the resolution, the longer it takes Maya to calculate the simulation.

    One advantage of 2D containers over 3D containers is that 2D containers can tolerate a much higher Resolution setting than 3D containers. Depending on the effect you are trying to create, this fact may influence your choice of one over the other. Three-dimensional containers are explored further later in the chapter.

  11. Set the two Resolution fields to 512 × 512. When you do this, the image still appears blocky. To fix this you can re-import the image.

  12. Switch to the Tool Options box, and click the Import button in the Attribute Maps

    Playing Fluid Simulations
  13. After a few seconds the image updates. Now you can see much more detail in the fluid density.

  14. Rewind and play the scene. The Jolly Roger starts to break apart and rise to the top of the container (see Figure 16.2, left image).

  15. Save the scene as jollyRoger_v01.ma. To see a version of the scene, open the jollyRoger_v01.ma scene from the chapter16scenes directory on the DVD.

Fluid containers are subdivided into a grid. Each subdivision is known as a voxel. When Maya calculates fluids, it looks at each voxel and how the fluid particles in one voxel affect the particles in the next voxel. As you increase the resolution of a fluid container, you increase the number of voxels and the number of calculations Maya has to perform in the simulation. When setting the resolution of a 2D container, you can use much higher values than with a 3D container. If you make a 3D container with a resolution of 512 in each dimension (X, Y, and Z), you'll find that Maya grinds to a halt unless your machine is very powerful and has a lot of memory. You'll gain a deeper appreciation for the Resolution setting later in the chapter.

A file texture image of the Jolly Roger determines the density of the fluid. The image becomes clearer when you increase the resolution of the container. When you play the animation, the image distorts over time like smoke.

Figure 16.2. A file texture image of the Jolly Roger determines the density of the fluid. The image becomes clearer when you increase the resolution of the container. When you play the animation, the image distorts over time like smoke.

Use Fields with Fluids

Fluids can be controlled using dynamic fields such as Turbulence, Drag, and Vortex. In this section, you'll distort the image of the Jolly Roger using Radial fields.

  1. Continue with the scene from the previous section or open the jollyRoger_v01.ma scene from the chapter16scenes folder on the DVD.

    As demonstrated in the previous section, when you play the scene, the image immediately starts to rise to the top of the container like a gas that is lighter than air. In this exercise you want the image to remain motionless until a dynamic field is applied to the fluid. To do this you'll need to change the Buoyancy property of the fluid.

  2. In the Outliner, select the fluidShape1 node and open the Attribute Editor.

  3. Scroll down to the Content Details rollout, and expand the Density section. Set Buoyancy to 0.

  4. Rewind and play the animation. The image of the Jolly Roger should remain motionless.

  5. Stop the animation and rewind. Select fluidShape1 and choose Fields

    Use Fields with Fluids

    If you need to connect a field to a fluid after it has been created, you can use the Dynamic Relationships Editor. This editor is discussed in Chapter 13.

  6. Select the Radial field and open its Attribute Editor. Enter the following settings:

    • Magnitude = 200

    • Attenuation = 0

    • Max Distance = 1 (Use Max Distance should be on by default.)

  7. On frame 1 of the animation, set the Translate Z of the Radial field to 5 and set a keyframe.

  8. Set the Timeline to frame 50. Set the Translate Z of the Radial field to −5 and set another keyframe.

  9. Rewind and play the animation (or create a playblast). As the Radial field passes through the container, it pushes the fluid outward like a cannonball moving through smoke (see Figure 16.3).

  10. Add two more Radial fields to the container with the same settings. Position them so they pass through the image at different locations and at different frames on the keyboard.

  11. Create a playblast of the scene. Watch it forward and backward in FCheck.

  12. Save the scene as jollyRoger_v02.ma. To see a version of the scene, open the jollyRoger_v02.ma scene from the chapter16scenes directory on the DVD.

Now that you have had a little experience working with containers, the next section explores some of the settings more deeply as you create an effect using 3D fluid containers and emitters.

The Radial field pushes the smoke as it moves through the field.

Figure 16.3. The Radial field pushes the smoke as it moves through the field.

Fluid Examples

Maya comes with a number of Fluids examples located in the Visor. To use one of these examples, choose Fluid Effects

Fluid Examples
The Visor contains numerous Fluids examples.

Figure 16.4. The Visor contains numerous Fluids examples.

Use 3D Containers

Three-dimensional Fluids containers work just like 2D containers except they have depth as well as width and height. This does mean that they are computationally much more expensive. If you double the resolution in X and Y for a 2D container, the number of voxels increases by a factor of 4 (2 × 2); if you double the resolution of a 3D container, the number of voxels increases by a factor of 8 (2 × 2 × 2). A good practice for working with 3D containers is to start at a low resolution, such as 20 × 20 × 20, and increase the resolution gradually as you develop the effect.

  1. Start a new Maya scene and switch to the Dynamics menu set.

  2. Choose Fluid Effects

    Use 3D Containers

    You'll see the 3D container appear in the scene. On the bottom of the container you'll see a small grid. The size of the squares in the grid indicates the resolution (in X and Z) of the container.

  3. Select the fluidShape1 node in the Outliner, and open its Attribute Editor. Expand the Display section under the fluidShape1 tab. Set Boundary Draw to Reduced. This shows the voxel grid along the X, Y, and Z axes (see Figure 16.5). The grid is not drawn on the parts of the container closest to the camera, so it's easier to see what's going on in the container.

The voxel resolution of the 3D container is displayed as a grid on the sides of the container.

Figure 16.5. The voxel resolution of the 3D container is displayed as a grid on the sides of the container.

At the top of the Attribute Editor for the fluidShape1 node, you'll see the Resolution and Size fields for each of the three axes. These two settings are proportionally related. If you create a container with a Size of 10, 40, 10, then you should keep the Resolution values proportionally the same; for example, use 20, 80, 20 or 5, 10, 5. Otherwise, the voxels appear stretched along one axis, giving a stretched look to the fluid simulation (there are some instances where this may be desirable; for example, when creating the elongated glow of the aurora borealis).

You can use the Scale tool to resize the fluid container, but it's a better idea to use the Size setting in the fluid's shape node. This Size setting affects how dynamic properties (such as Mass and Gravity) are calculated within the fluid. Using the Scale tool does not affect these calculations, so increasing the scale of the fluid using the Scale tool may not give you the results you want. It depends on what you're trying to accomplish, of course. If you look at the Blast.ma example in the Visor, the explosion effect is actually created by animating the Scale X, Y, and Z channels of the fluid container.

Create a Reaction

There's no better way to gain an understanding of how fluids work than by directly designing an effect. In this section you'll learn how emitters and fluid settings work together to create flame and smoke. You can actually simulate a reaction within the 3D container as if it were a miniature chemistry lab.

Fluid Emitters

There are a number of ways to add contents to a fluid container. In the previous section you saw how to paint density directly into a container. You can also use an emitter to inject contents (such as density) into a container over time. Fluid emitters are very similar to particle emitters in that you can use an omni emitter, which is a single point in space, a volume, a curve, or a surface. The main difference between particle emitters and fluid emitters is that a fluid emitter has to be within the bounds of the fluid container to emit.

The contents that you can inject into a container by a fluid emitter are density, fuel, and temperature. You can use an emitter to inject any combination of the three. The settings on the fluid container's shape node determine how these contents behave within the container. You can use more than one emitter within a container and can create reactions by the interaction of anything within the container. For instance, you can use one emitter to add fuel and another to add temperature. The contents of two separate fluid containers can't interact.

In this example, you'll use an animated surface to emit temperature into a container that will appear as a flame. The simplest way to create flames or explosions is to add temperature. However, as you'll see later on, more interesting effects result when fuel and density are combined with temperature.

  1. Open the reaction_v01.ma scene from the chapter16/scenes directory on the DVD.

  2. This scene contains a spiral curve. Play the animation. You'll see a tube animate along the length of the curve.

    The surface was created by converting an animated Paint Effects stroke into a NURBS surface. The surface is named emitterSurface (see Figure 16.6).

  3. Switch to the Dynamics menu set, and choose Fluid Effects

    Fluid Emitters
  4. Select fluid1 in the Outliner and open its Attribute Editor. Switch to the fluidShape1 tab. Set the Resolution fields to 20, 40, 20. Set Size to 20, 40, 20.

  5. Select fluid1 and use the Move tool to reposition it so that the animated spiral is near the bottom of the container. Set the Translate Y of fluid1 to 19.

  6. In the Outliner, select the emitterSurface and Ctrl+click fluid1. Choose Fluid Effects

    Fluid Emitters
  7. In Emit From Object Options window, choose Edit

    Fluid Emitters
    An animated tube is created by converting a Paint Effects stroke into a NURBS surface.

    Figure 16.6. An animated tube is created by converting a Paint Effects stroke into a NURBS surface.

    The options for the fluid emitter

    Figure 16.7. The options for the fluid emitter

  8. Set Density Rate (/Voxel/Sec) to 0. Set Heat Rate (/Voxel/Sec) to 5. Set Fuel Rate (/Voxel/Sec) to 0 (see Figure 16.7). This emitter emits only temperature (heat) into the container, nothing else.

  9. Click Apply And Close to create the emitter.

    In the Outliner you'll see that the emitter node is parented to the emitterSurface node. If you play the animation, you'll see no change. You need to edit the fluid container itself so that it can properly display the temperature emitted by the surface.

  10. Select the fluid container (fluid1) and open the Attribute Editor to the fluidShape1 tab.

  11. In the Contents Method section, set Temperature to Dynamic Grid.

    There are several options for adding temperature (as well as velocity, density, or fuel) to a 3D container. These are Static Grid, Dynamic Grid, and Gradient. If you don't need to calculate a particular content, you can set these to Off.

    Static Grid is used for elements of the simulation that are placed within the container using the Paint tool or emitters. The values created for these elements are not changed by the simulation. For example, if you wanted to create a simple cloud, you could set Density to Static Grid, paint the cloud in the container, and then animate the container moving across the sky.

    Dynamic Grid is used when the element and its values will change over time as a result of the simulation. Most of the examples in this section use dynamic grids.

    Gradients create a static range of values between 0 and 1. The values affect the simulation but are not changed by it. For example, a container can be set so that the velocity at one end is higher than the velocity at the other end, which causes the fluid to move steadily faster as it approaches the higher range of values in the gradient. When you choose the Gradient option, a menu becomes available that allows you to determine the direction of the gradient.

  12. Scroll down to the Shading section. Set Transparency to a very light gray color, almost white. In the Color section, click on the color swatch and choose a black color.

  13. The Incandescence ramp is already set to Temperature. By setting Color to black, you'll be able to see how the colors of the ramp represent the temperature of the fluid.

  14. In the Opacity section, set Opacity Input to Temperature.

  15. Expand the Display section and set the Shaded Display option to As Render.

  16. Press the 6 key to switch to shaded mode. Rewind and play the animation. The animation will play more slowly, but you'll see some yellow flames start to rise from the emitter surface (see Figure 16.8).

  17. Save the scene as reaction_v02.ma. To see a version of the scene, open the reaction_v02.ma scene from the chapter16scenes folder on the DVD.

When you play the animation, yellow frames rise from the animated surface.

Figure 16.8. When you play the animation, yellow frames rise from the animated surface.

Add Velocity

Velocity is used to push fluids around within a container. You can add velocity as a constant force to push fluids in a particular direction, or you can use an emitter. The Swirl setting adds rolling and swirling motion to the contents of a container. In the current example, the flames are already rising to the top of the container because of the Buoyancy setting, so you'll use Velocity to add swirl.

  1. Continue with the scene from the previous section or open the reaction_v02.ma scene from the chapter16scenes folder on the DVD.

    Before editing the simulation, you can improve the detail of the fluid by increasing the resolution. Be aware that this will slow down the playback of the simulation. You may want to create playblasts occasionally as you work so that you can see the fluid play in real time.

  2. Open the Attribute Editor to the fluidShape1 tab, and set Resolution to 40, 80, 40.

  3. In the Contents Method section, make sure Velocity is set to Dynamic Grid. Expand the Contents Details rollout and the Velocity subsection. Raise Swirl to 10.

  4. Rewind and play the animation. The fluid looks more like a swirl; however, the fluid does not last very long before disappearing. Expand Temperature and set Temperature Scale to 3. Stop the animation at frame 80.

    Temperature Scale is a global control for increasing the overall temperature of the container. This increases the size of the flame and keeps it around a little longer.

  5. Scroll down to the Shading section. Move the orange color marker to the left slightly, and move the yellow color marker also slightly to the left. The left side of the Incandescence ramp is used to color lower temperatures; the right side colors higher temperatures.

  6. Click on the right side of the Incandescence ramp to add another color marker. Set the color of the new marker to a light bluish-white.

  7. Set Input Bias to 0.4. This moves the bias of the incandescence so that more of the fluid receives more color.

  8. Edit the Opacity ramp by adding points to the curve. Just like the Incandescence ramp, the left side of the curve controls opacity based on lower temperatures, while the right side controls the opacity of higher temperatures.

    You can experiment with this ramp to shape the way the flames look (see Figure 16.9).

  9. Save the scene as reaction_v03.ma. To see a version of the scene, open the reaction_v03.ma scene from the chapter16scenes directory on the DVD.

The flame is colored and shaped using the Incandescence and Opacity ramps based on temperature.

Figure 16.9. The flame is colored and shaped using the Incandescence and Opacity ramps based on temperature.

Add Fuel

Once you have a flame in your container, you can create a dramatic reaction by adding fuel. As with velocity, density, and temperature, you can add fuel using an emitter, or by painting fuel with Artisan, or by using a gradient. In this exercise you'll use a second emitter to add fuel.

  1. Continue with the scene from the previous section or open the reaction_v03.ma scene from the chapter16scenes directory on the DVD.

  2. Select fluid1 and choose Fluid Effects

    Add Fuel
  3. Click Apply And Close to create the emitter. The emitter appears as a sphere at the center of fluid1.

  4. In the Outliner, expand fluid1 and select fluidEmitter2. Use the Move tool to move the emitter down closer to the bottom of fluid1. Set its Translate Y to −16.

    You can think of the fuel emitter as a gas leak inside the container. As the temperature and the fuel come within close proximity of each other, a reaction takes place. The fuel burns until the fuel is exhausted or the temperature is lowered. Since the fuel is injected into the container, the flame keeps burning. If you play the scene at this point, no reaction will take place. You must set the fuel to Dynamic Grid in the fluid shape node before the temperature can react with the fuel in the emitter.

  5. Open the fluidShape1 node in the Attribute Editor, and set Fuel in the Contents Method section to Dynamic Grid.

  6. Scroll down to the Contents Details section and expand Fuel. Use the following settings:

    • Reaction Speed: 1

    • Ignition Temperature: 0.1

    • Max Temperature: 100

    • Heat Released: 100

    • Light Released: 1

  7. Rewind and create a playblast of the scene.

    The emitter surface acts like a fuse—when the temperature it emits gets close to the fuel emitter a reaction takes place, and suddenly a plume of flame and gas rises dramatically from the center. You'll also notice that after the initial reaction the fuel coming from the emitter continues to burn. This is because a small piece of the emitter surface continues to emit heat below the fuel emitter.

    Reaction Speed determines how fast the reaction takes place once the heat ignites the fuel. Higher values produce faster reactions.

    Ignition Temperature sets the minimum temperature required to ignite the fuel. If you want to create a reaction that occurs regardless of temperature, set this value to a negative number such as −0.1.

    Heat Released causes the reaction to add more temperature to the fluid container.

    Light Released adds value to the current Incandescent value of the fluid, which causes the fluid to glow brightly when rendered.

    You'll notice that as the simulation plays, the flame and smoke appear trapped within the walls of the 3D container. This is because, by default, containers have boundaries on all sides. You can remove these boundaries to let the contents escape. Be aware that as the contents leave the container they will disappear, since fluid simulations cannot exist outside the fluid container (2D or 3D).

  8. Select the fluid1 node and open its Attribute Editor. In the Container Properties section at the top of the fluidShape1 tab, set the Boundary Y option to −Y Side. This means that there is a boundary on the bottom of the container but not on the top (see Figure 16.10).

  9. Create another playblast of the simulation. The explosion is no longer trapped at the top of the container.

  10. Save the scene as reaction_v04.ma. To see a version of the scene, open the reaction_v04.ma scene from the chapter16scenes directory on the DVD.

Boundaries keep the simulation within the container (left image). When you set the Y boundary to −Y Side, the explosion can escape out the top (right image).

Figure 16.10. Boundaries keep the simulation within the container (left image). When you set the Y boundary to −Y Side, the explosion can escape out the top (right image).

Render Fluid Containers

Fluid simulations can be rendered using Maya Software or mental ray, and they will be identical for the most part. Since fluids have an incandescent value, they can be used as light-emitting objects when rendering with Final Gathering. If you want the fluid to appear in reflections and refractions, you need to turn on the Visible In Reflections and Visible In Refractions options in the Render Stats section of the fluid's shape node.

This section demonstrates some ways in which the detail and the shading of fluids can be improved when rendered.

Texturing Fluids

You can add more detail to a fluid simulation by increasing the resolution of the fluid container; however, this makes playback of the scene slower as well as increases render times. Fluids have a set of built-in procedural texturing options that can help add more detail to the fluid without the need to change the resolution of the fluid container.

  1. Continue with the scene from the previous section or open the reaction_v04.ma scene from the chapter16scenes directory on the DVD.

  2. Play the scene to about frame 200 and stop the animation.

  3. Open the Render Settings window and set the Renderer to mental ray. In the Quality tab, set Quality Preset to Production.

  4. Open the Render View window, and create a render from the perspective camera. Store the render in the Render View window.

  5. Select fluid1 and open the Attribute Editor to the fluidShape1 tab. In the Shading section, set Dropoff Shape to Y Gradient and Edge Dropoff to 0.1.

    Dropoff Shape fades the edges of the simulation as the contents approach the edge of the container. Choosing Y Gradient means that the top of the simulation fades out as it leaves the top of the container. The Edge Dropoff value sets the range of the fading effect.

  6. Scroll down and expand the Textures section. Turn on Texture Opacity and Texture Incandescence. Notice that the cloud appears to have more detail even in the perspective view.

  7. By default, Texture Type should be set to Perlin Noise. You can also choose Billow, Volume Wave, Wispy, or Space Time. Perlin Noise is good for creating random detail in the cloud.

    The settings for Perlin Noise are very similar to the settings found in the 3D noise texture that you create in the Hypershade.

  8. Set Frequency to 4 to add more detail.

  9. Create a test render and compare this with the previously saved render.

    The fluid now looks as though it is more detailed. This can help to add a sense that the fluid simulation is much larger.

    Render the simulation using mental ray (left image). Adding a Perlin Noise texture adds detail to the simulation without changing the fluid resolution (right image).

    Figure 16.11. Render the simulation using mental ray (left image). Adding a Perlin Noise texture adds detail to the simulation without changing the fluid resolution (right image).

  10. You can animate the texture using the Texture Time attribute. In the field next to Texture Time type = time*0.1;. This creates an expression where the texture is animated based on the current time of the animation.

  11. Save the scene as reaction_v05.ma. To see a version of the scene, open the reaction_v05.ma scene from the chapter16scenes directory on the DVD.

Glowing Fluids

Fluid simulations can benefit from using shader glow. This creates the impression that the bright parts of the fluid are emitting light in the scene.

  1. Continue with the scene from the previous section or open the reaction_v05.ma scene from the chapter16scenes directory on the DVD.

  2. Rewind and play the scene to about frame 200.

  3. Select fluid1 and open the Attribute Editor to the fluidShape1 tab. In the Shading section, set Glow Intensity to 0.1.

    The Glow Intensity attribute works exactly like the Glow Intensity slider found in the Special Effects section of standard Maya shaders. This boosts the incandescent values of the fluid as a post-render effect, making the fluid appear to glow. Just like all glow effects in the scene, the quality of the glow is controlled using the shader glow node found in the Hypershade. When rendering a sequence using a glow, you should always turn off the Auto Exposure setting in the shader glow node to eliminate flickering that may occur when the animation is rendered.

  4. Open the Hypershade, select shaderGlow1, and open its Attribute Editor.

  5. Turn off Auto Exposure.

    Whenever Auto Exposure is disabled, the glows become much more intense in the render. To fix this you can adjust the Glow Intensity value in the Glow Attributes section of the shader glow node.

  6. In the Common Shader Glow Attributes area, set Threshold to 0.1. In the Glow Attributes section, set Glow Intensity to 0.05 (Figure 16.12).

    The Threshold setting sets the minimum value required to create a glow effect in the final image. In other words, if Threshold is 0, then the glow is applied to all the visible pixels in the image, although black pixels do not produce much of a glow. When you raise Threshold to a value such as 0.1, then very dim pixels will not glow; only pixels above the Threshold value will glow in the final render. The higher the Threshold value, the less glow you'll see, and the glow itself will be localized to the brighter areas of the image.

  7. Create a test render to see the fluid with the glow applied.

  8. Save the scene as reaction_v06.ma. To see a version of the scene, open the reaction_v06.ma scene from the chapter16scenes directory on the DVD.

Edit the Shader Glow settings to reduce flickering and overexposure in the render.

Figure 16.12. Edit the Shader Glow settings to reduce flickering and overexposure in the render.

Lighting Fluids

Fluids can react to lighting in the scene, and you can apply self-shadowing to increase the realism. As an example of how to light fluids, a scene with simple clouds has been created for you to experiment with.

  1. Open the simpleCloud_v01.ma scene from the chapter16scenes directory on the DVD.

  2. Play the animation to frame 100. A simple cloud appears in the center of the scene.

    The scene contains a fluid container, an emitter, a plane, and a light. The scene is already set to render using mental ray at production quality.

  3. Open the Render View window, and render the scene from the perspective camera. A puffy white cloud appears in the render. Store the render in the Render View window (Figure 16.13, left image).

  4. Select the fluid1 node, and open the Attribute Editor to the fluidShape1 tab. Scroll down to the Lighting section at the bottom of the editor.

    The Lighting section contains two settings: Self Shadow and Real Lights. When Real Lights is off, the fluids are lit from a built-in directional light. The three fields indicate the direction the light is pointing in X, Y, and Z. Rendering with Real Lights off tends to be much faster than rendering with Real Lights on, even when the real light is a directional light.

  5. Turn on Self Shadowing. You'll see that the cloud now has dark areas at the bottom in the perspective view. The Shadow Opacity slider controls the darkness of the shadows. Create a test render, and store the render in the Render View window (Figure 16.13, middle image).

  6. Select the directional light and open its Attribute Editor. Under Shadows, turn on Use Ray Trace Shadows.

  7. Select fluid1, and in the Lighting section under the fluidShape1 tab turn off Self Shadows. Turn on Real Lights.

  8. In the Render Stats section, make sure Casts and Receive Shadows are on.

  9. Create another test render from the perspective camera (Figure 16.13, right image).

When rendering using Real Lights, the fluid casts shadows onto other objects as well as itself. When rendering using real shadow casting lights, make sure that Self Shadow is disabled to avoid calculating the shadows twice. You can see that rendering with Real Lights does take significantly longer than using the built-in lighting and shadowing. Take this into consideration when rendering fluid simulations.

Render the cloud with built-in lights (left image). Enable Self Shadows (center image). Then render the cloud using a directional light that casts ray trace shadows (right image).

Figure 16.13. Render the cloud with built-in lights (left image). Enable Self Shadows (center image). Then render the cloud using a directional light that casts ray trace shadows (right image).

Fluids and nParticles

Fluids and nParticles use separate dynamic systems but they can be made to work together indirectly to create effects. A fluid system can be used to influence the movement of nParticles, like a field.

Add Sparks to a Flame

In this section, you'll create sparks using nParticles. The motion of the sparks will be controlled using a flame within a 3D container. To keep things simple you'll use one of the flame examples in the Visor.

  1. Create a new scene in Maya. Choose Window

    Add Sparks to a Flame
  2. Right-click the Flame.ma example, and choose Import Maya File Flame.ma. This imports the 3D container, emitter, and all of its settings into the scene.

  3. Select the flame container and open its Attribute Editor to the flameShape tab. In the display options, set Shaded Display to Temperature. This does not affect how the flame looks when rendered, but it makes it easier to see the simulation in the perspective view.

  4. Press the 6 key to switch to shaded view. Set the timeline to 800 and play the scene. You'll see the flame simulation play at the center of the 3D container (see Figure 16.14).

  5. Switch the menu set to nDynamics. Choose nParticles

    Add Sparks to a Flame
  6. Choose nParticles

    Add Sparks to a Flame
  7. Select the emitter, and use the Move tool to position the emitter at the base of the flame.

  8. When you play the scene, the nParticles fall out of the emitter. Select nParticle1 in the Outliner, open its Attribute Editor, and switch to the Nucleus1 tab. Set Gravity in the Gravity And Wind section to 0.

  9. In the Outliner, select nParticle1 and Ctrl+click on the flame shape. Choose Fields

    Add Sparks to a Flame
  10. Rewind and play the scene. You'll see the nParticles that are closest to the center of the flame shoot out of the top of the simulation. This may be easier to see if you set the Display option in the flameShape tab back to As Render.

    Once the nParticles leave the fluid container, they continue to move at a constant rate. You can edit the settings on the nParticle shape node to make the movement more interesting.

    Import the flame example into the scene. A flame burns at the center of the container when you play the scene.

    Figure 16.14. Import the flame example into the scene. A flame burns at the center of the container when you play the scene.

  11. Select nParticle1, and open its Attribute Editor to the nParticleShape1 tab. In the Lifespan section, set Lifespan Mode to Random Range. Set Lifespan to 2 and Lifespan Random to 1. As explained in Chapter 13, this means that the nParticles have a lifespan between 1 and 3 seconds.

  12. In the Dynamic Properties section, set Drag to 0.3. This causes the nParticles to slow down as they move away from the flame.

  13. Rewind and play the animation.

    The nParticles follow the movement of the flame fairly well, but they stop outside the fluid container, which looks rather odd. You can use the opacity settings to make slower-moving particles fade out and disappear, which really helps them to look like sparks.

  14. Scroll down and expand the Shading rollout. Set Opacity Scale Input to Speed. Click on the ramp to add a new point. Edit the ramp so it looks like Figure 16.15. This causes slower-moving particles to become completely transparent.

  15. In the Color section, set Color Input to Speed. Edit the Color ramp so that the left side is black, the center is orange, and the right side is yellow.

  16. In the Shading section, set Particle Render Type to Streak. Set Tail Size to 0.2, Tail Fade to −1, and Opacity to 0.5.

  17. Rewind and play the animation. You should have some nice-looking sparks that fly upward with the motion of the flame. If the scene is rendered using mental ray, the sparks and the flame appear together (Figure 16.16).

  18. Save the scene as sparkingFlame.ma. To see a version of the scene, open the sparkingFlame.ma file from the chapter16scenes directory on the DVD.

Edit the Opacity Scale edit curve so slower-moving particles disappear.

Figure 16.15. Edit the Opacity Scale edit curve so slower-moving particles disappear.

When you render the scene with mental ray, the sparks and the flame appear to interact.

Figure 16.16. When you render the scene with mental ray, the sparks and the flame appear to interact.

Create a Pond

A pond is a special type of 2D fluid container that uses a Height field and a Spring Mesh solver to convert the 2D fluid container into a 3D surface. Ponds, as the name suggests, are suitable for simulating the surface of small bodies of water.

The Spring Mesh solver is one of the two solvers used by fluid effects. Up until this point you have been using the Navier-Stokes solver, which is a more accurate and computationally intense solver. The Spring Mesh solver is simpler, similar to dynamic springs used with soft body dynamics.

All of this sounds fairly complicated. However, most of the tricky parts of the effect are handled by Maya behind the scenes. Creating and using the pond effect is actually quite simple.

Set Up the Pond

In this example you'll use the pond effect to create the milky surface of a bowl of cereal, like something you might see in a commercial.

  1. Open the bowl_v01.ma scene from the chapter16scenes directory on the DVD. This scene contains a simple NURBS bowl, a polygon spoon, and a piece of cereal made from a NURBS torus.

  2. Switch to the Dynamics menu set, and choose Fluid Effects

    Set Up the Pond
  3. Select Pond1 and open its Attribute Editor to the PondShape1 node. Scroll down to the Surface section and expand these attributes.

    The pond is set to a Surface render. All the previous examples in this chapter used a Volume render. Volume renders create clouds and flames. Surface renders generate a mesh. The Hard Surface option creates a mesh with hard edges useful for creating liquids such as water or milk. The Soft Surface option creates a surface with a fuzzy edge. This can be useful for certain types of clouds that require detailed self-shadowing effects. If you are creating thick clouds like what you might see in a nuclear blast, and you're not satisfied with the results you get with Volume render, you may want to try using a Surface render with the Soft Surface option.

  4. Scroll down to the shading options and expand the Opacity section.

    This attribute actually controls the height of the pond surface, which, admittedly, seems a little strange. The surface of the pond is displaced by the outAlpha channel value of the pondShape. The outAlpha value is controlled by the Opacity curve.

  5. To move the field up or down you can adjust the points of the curve on the left or right side, or you can use the Input Bias slider (Figure 16.17).

    At the moment the opacity settings cause the surface of the pond to remain at the middle of the container, which should work just fine for this example. Adding points to the curve will not distort the surface. To do that you can use the Textures section.

  6. Scroll down to the Textures section and activate the Texture Opacity option. Set Texture Type to Billow.

    Use the Opacity edit curve to position the height of the pond surface.

    Figure 16.17. Use the Opacity edit curve to position the height of the pond surface.

    The Textures settings distort the surface of the pond. By adjusting the settings for the texture, you can create a lumpy surface on the pond, which might work well for creating mud or slime (see Figure 16.18).

  7. In the Textures options, turn off Texture Opacity so that the surface is smooth again. In the Color section, edit the ramp so that the color of the surface is white. Edit the Incandescence ramp so that the incandescence is black (see Figure 16.19).

    Applying a texture to the opacity of the fluid distorts the surface of the pond.

    Figure 16.18. Applying a texture to the opacity of the fluid distorts the surface of the pond.

    Edit the Color and Incandescence ramps so that the surface is white but does not emit light.

    Figure 16.19. Edit the Color and Incandescence ramps so that the surface is white but does not emit light.

    Right now the milk surface extends beyond the edges of the bowl. Later on you'll fix this using a texture, but for now you can leave it the way it is.

  8. Save the scene as bowl_v02.ma. To see a version of the scene, open the bowl_v02.ma scene from the chapter16scenes directory on the DVD.

Create a Wake

To make the simulation of the cereal bowl a bit more exciting, you can add ripples using a wake.

  1. Continue with the scene from the previous section or open the bowl_v02.ma scene from the chapter16scenes directory on the DVD.

  2. Set the timeline to 500. Select the spoon in the Outliner, and keyframe its Translate and Rotate channels.

  3. Create an animation of the spoon moving back and forth rapidly inside the bowl as if it is stirring the milk. Try animating the spoon moving in and out of the surface of the milk as well.

  4. Select Pond1 in the Outliner. Choose Fluid Effects

    Create a Wake
  5. In the Outliner, you'll see a new PondWakeEmitter1 node, and a volume emitter appears in the pond. Select and hide Pond1 (Ctrl+h) and position the emitter around the end of the spoon. Scale and rotate the emitter so that it surrounds the end of the spoon.

  6. Parent the PondWakeEmitter1 node to the spoon (see Figure 16.20).

  7. Select and unhide Pond1 (Ctrl+H on a PC; Shift+H on a Mac)

    Position PondWakeEmitter1 around the end of the spoon. In the Outliner parent it to the spoon.

    Figure 16.20. Position PondWakeEmitter1 around the end of the spoon. In the Outliner parent it to the spoon.

  8. Rewind and play the animation. The pond responds to the wake, although the motion is rather violent.

  9. Select PondWakeEmitter1 and open its Attribute Editor. In the Fluid Attributes section, set Density Rate (/Voxel/Sec) to −1. Negative values cause the wake to push down on the surface; positive values cause the wake to push up.

  10. Select the Pond1 node, and open its Attribute Editor to PondShape1. In the Dynamic Simulation section, set Damp to 0.08 and Viscosity to 1.

  11. Rewind and play the animation to see the spoon stir the milk (see Figure 16.21).

    You can simulate various types of fluids by increasing the Damp and Viscosity settings. If you wanted to animate whipping cream turning from liquid to a stiffer substance, you could animate the Damp value using keyframes.

  12. Save the scene as bowl_v03.ma. To see a version of the scene, open the bowl_v03.ma scene from the chapter16scenes directory on the DVD.

Parent the emitter to the animated spoon to create the effect of the spoon stirring the milk.

Figure 16.21. Parent the emitter to the animated spoon to create the effect of the spoon stirring the milk.

Use Boats

Boats are simply locators that ride on the surface of the pond. An object can be parented to the locator to make it look as though the object is floating on the surface.

  1. Continue with the scene from the previous section or open the bowl_v03.ma from the chapter16scenes directory on the DVD.

  2. In the Outliner, select Pond1 and choose Fluid Effects

    Use Boats
  3. In the Outliner, select cereal1 and parent it to Locator1. You can do this by MMB-dragging cereal1 on top of Locator1.

  4. Expand Locator1 in the Outliner and select cereal1. In the Channel Box, set cereal1's Translate X, Y, and Z values to 0. This places cereal1 at the same location as Locator1.

  5. Rewind and play the animation. You'll see the cereal bob up and down with the surface of the milk.

  6. Select Locator1. You'll see that, in the Channel Box, the Translate Y, Rotate X, and Rotate Z channels are all colored purple, indicating that they are controlled by an expression.

  7. Set Translate X to −4.5 and Translate Z to −1. If you want to animate the cereal moving around, you can keyframe these channels.

  8. Open the Attribute Editor for Locator1, and switch to the locatorShape1 tab. Expand the Extra Attributes section. This section contains a number of sliders that can be used to control the motion of the locator.

  9. Set Buoyancy to 0.4. Lowering this value makes the cereal sink a little in the fluid, and it also appears to bob a bit slower, making it look heavier.

  10. Set Start Rot X to 90. This causes the boat to start out on its side at the beginning of the animation. It will roll over to right itself. To control the speed at which it rolls, set the Roll value to 0.2. The Start Y and Start Rot Z attributes create the same effect on a different axis. Pitch controls the speed at which the boat rights itself on the Z axis.

  11. Set Boat Length to 2 and Boat Width to 1 to match the size of the cereal. By matching the size of the cereal, the simulation should be more accurate (see Figure 16.22).

    Since the cereal geometry is parented to the locator, you can animate its local rotation as well if you need to make the cereal rotate in a specific fashion.

  12. Save the scene as bowl_v04.ma. To see a version of the scene, open the bowl_v04.ma scene from the chapter16scenes folder on the DVD.

Adjusting the settings in the Extra Attributes section of the locator's shape node allows you to change the behavior of the cereal floating on the surface.

Figure 16.22. Adjusting the settings in the Extra Attributes section of the locator's shape node allows you to change the behavior of the cereal floating on the surface.

Convert Fluids to Polygons

To solve the problem of the milk surface extending past the edges of the bowl, you can convert the pond into a polygon object and then use the transparency of a shader to hide the protruding edges of the milk surface.

  1. Continue with the scene from the previous section or open the bowl_v04.ma scene from the chapter16scenes folder on the DVD.

  2. Select Pond1 in the Outliner, and choose Modify

    Convert Fluids to Polygons
  3. Select Pond1 and hide it (Ctrl+h).

  4. Create and assign a Blinn material to Milk. Make the color of the Blinn white. Name the shader milkShader.

  5. Rewind and play the animation. You'll see that the milk surface is animated based on the fluid settings, but the playback speed is much slower.

  6. Open the Hypershade window and select milkShader. Open its Attribute Editor.

  7. Click on the checkered box next to Transparency to open the Create Render Node window. In the 2D Textures section, make sure As Projection is checked at the top (Figure 16.23).

    The milk surface does not have UV coordinates. You can create UV coordinates, but this is a little risky. As the surface moves, the UV coordinates could slide around. It's safer to simply project the transparency texture onto the surface using a projection node, which does not require UV coordinates.

  8. Click Ramp to create a new ramp texture.

    Create a texture as a projection for the transparency of the milk surface.

    Figure 16.23. Create a texture as a projection for the transparency of the milk surface.

  9. In the Outliner, you'll see a new place3DTexture1 node. Select this node and set its Rotate X channel to −90 so that it projects down from above the surface.

  10. Open the Attribute Editor for place3DTexture1, and click the Fit To Group BBox button. This sizes the projection to match the surface (see Figure 16.24).

  11. Open the Hypershade and switch to the Textures tab. Click on ramp1 and open its Attribute Editor.

  12. In the Attribute Editor for Ramp1, set Ramp Type to Circular Ramp and Interpolation to None.

  13. Edit the ramp so that there are two color markers: one at the bottom and one in the middle. The color marker at the bottom should be black, and the one in the middle should be white.

  14. Create a test render of the scene. You'll notice that the edges of the surface are still visible. This is because the Specularity channel of the Blinn texture is reflecting light on both the opaque and transparent parts of the surface.

  15. Open the Hypershade window and graph the milkShader in the Work Area. In the Create Maya Nodes column, scroll down to the General Utilities section, and create a Reverse Node.

  16. In the Hypershade, connect the output of projection1 into the input of reverse1. Connect the output of reverse1 into the specular color of the milkShader (see Figure 16.25).

    Size the Projection node to match the milk surface.

    Figure 16.24. Size the Projection node to match the milk surface.

    Use a reverse node to connect the inverted colors of the ramp to the specular color of the milkShader.

    Figure 16.25. Use a reverse node to connect the inverted colors of the ramp to the specular color of the milkShader.

    By using a reverse node, you can invert the colors of ramp1 and use it to color the Specularity channel of the milkShader. This allows the milk surface to still appear reflective and wet, but it prevents the edges that extend beyond the bowl from reflecting light, thus making them invisible in the render. Figure 16.26 shows the milk surface rendered using mental ray.

  17. Save the scene as bowl_v05.ma. To see a finished version of the scene, open the bowl_v05.ma scene from the chapter16scenes folder on the DVD.

Render the scene using mental ray.

Figure 16.26. Render the scene using mental ray.

Create an Ocean

The ocean fluid effect uses a surface and a special Ocean shader to create a realistic ocean surface that can behave dynamically. The Ocean shader uses an animated displacement map to create the water surface. Ocean surfaces can take a while to render, so you should take this into consideration when planning your scene.

The Ocean Shader

All of the controls needed to create the ocean are found on the ocean shader node. This node is created and applied automatically when you make an ocean. In this example, you'll create the effect of a space capsule floating on the surface of the ocean.

  1. Open the capsule_v01.ma scene from the chapter16scenes directory on the DVD. This scene has the simple space capsule model used in Chapter 13.

  2. Switch to the Dynamics menu set, and choose Fluid Effects

    The Ocean Shader

    When you create an ocean, you'll see a large NURBS surface appear. This represents the surface of the ocean. At the center is a preview plane, which gives an approximation of how the ocean will behave when the scene is played.

  3. Rewind and play the scene. You'll see the preview plane move up and down. This demonstrates the default behavior of the ocean (Figure 16.27).

  4. In the Outliner, select the node labeled Transform1, and open the Attribute Editor. Switch to the Ocean Shader tab.

    The ocean effect uses a preview plane to indicate the behavior of the ocean.

    Figure 16.27. The ocean effect uses a preview plane to indicate the behavior of the ocean.

    All the controls you need to change the way the ocean looks and behaves are found in the Ocean Shader controls. Each control is described in the Maya documentation. This section demonstrates how to use some of these controls. Many of the controls are actually self-explanatory (possibly a first for Maya).

  5. To slow down the ocean, set Wave Speed to 0.8. Observer Speed can be used to simulate the effect of the ocean moving past the camera without the need to animate the ocean or the camera. Leave this at 0.

  6. To make the ocean waves seem larger, increase Wave Length Max to 6. The wave length units are measured in meters.

    To make the ocean seem a little rougher, you can adjust the Wave Height edit curve. The Wave Height edit curve changes wave height relative to the wave length. If you edit the curve so that it slopes up to the right, then the waves with longer wavelengths will be proportionally taller than the waves with shorter wavelengths. A value of 1 means that the wave is half as tall as it is long. When you edit this curve, you can see the results in the preview plane.

    Wave Turbulence works the same way, so by making the curve slope up to the right, longer waves will have a higher turbulence frequency.

    Wave Peaking creates crests on top of areas that have more turbulence. Turbulence must be a non-zero value for wave peaking to have an effect.

  7. Experiment with different settings for the Wave Height, Wave Turbulence, and Wave Peaking edit curves (Figure 16.28). Create a test render from the perspective camera to see how these changes affect the look of the ocean.

  8. To make the capsule float in the water, select the capsule and choose Fluid Effects

    The ocean effect uses a preview plane to indicate the behavior of the ocean.
  9. In the Outliner, select Locator1 and open its Attribute Editor. In the Extra Attributes section, set Buoyancy to 0.01 and Start Y to −3.

  10. Select the capsule, and rotate it a little so that it does not bob straight up and down.

    You can shape the ocean by editing the Wave Height, Wave Turbulence, and Wave Peaking edit curves.

    Figure 16.28. You can shape the ocean by editing the Wave Height, Wave Turbulence, and Wave Peaking edit curves.

  11. Select the transform1 node, and open the Attribute Editor to the Ocean Shader tab. In the Common Material Attributes section, set Transparency to a dark gray color. This allows you to see some of the submerged parts of the capsule through the water. The oceanShader already has a refraction index of 1.3, so the water will refract light.

  12. Set Foam Emission to 0.355. This shades the peaks of the ocean with a light color, suggesting whitecaps.

  13. Create a test render of the scene from the perspective camera (see Figure 16.29).

  14. Save the scene as capsule_v02.ma. To see a finished version of the scene, open the capsule_v02.ma scene from the chapter16scenes directory on the DVD.

This is a good start to creating a realistic ocean. Take a look at some of the ocean examples in the Visor to see more advanced effects.

Render the capsule floating in the water.

Figure 16.29. Render the capsule floating in the water.

The Bottom Line

Use fluid containers

Fluid containers are used to create self-contained fluid effects. Fluid simulations use a special type of particle that is generated in the small subunits (called voxels) of a fluid container. Fluid containers can be 2D or 3D. 2D containers take less time to calculate and can be used in many cases to generate realistic fluid effects.

Master it

Create a logo animation that dissolves like ink in water.

Create a reaction

A reaction can be simulated in a 3D container by combining temperature with fuel. Surfaces can be used as emitters within a fluid container.

Master it

Create a chain reaction of explosions using the Paint Fluids tool.

Render fluid containers

Fluid containers can be rendered using Maya Software or mental ray. The fluids can react to lighting, cast shadows, and self-shadow.

Master it

Render the TurbulentFlame.ma example in the Visor so that it emits light onto nearby surfaces.

Use fluids with nParticles

Fluid simulations can interact with nParticles to create a large array of interesting effects.

Master it

nCloth objects use nParticles and springs to simulate the behavior of cloth. If fluids can affect nParticles, it stands to reason that they can also affect nCloth objects. Test this by creating a simulation where a fluid emitter pushes around an nCloth object.

Create a pond

A pond uses a 2D fluid container and the Spring Mesh solver to create a pond surface. You can float objects in the pond and use wake emitters to create ripples. The pond can be converted to a polygon mesh to allow for more advanced shading techniques.

Master it

Open the swamp.ma scene in the chapter16scenes directory, and create a pond. Add ripples to the surface.

Create an ocean

Ocean effects are created and edited using the Ocean shader. Objects can float in the ocean using locators.

Master it

Create an ocean effect that resembles stormy seas. Add the capsule geometry as a floating object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset