Controlling Fog Density,
Fog is a term often used to represent a variety of natural phenomenon within a 3D renderer. In nature, fog consists of water vapor yet in Maya you may use 'fog' to also represent dust, smoke, air, smog, plasma, nebulae or even magical glows and spells. To be able to yield such a variety of effects from fog, one must have a clear understanding of the volume shader associated with it. Specifically, our focus in this discussion is 'light fog', not volume primitives or environment fog. These are related topics, yet they use different nodes and are for another discussion.
In the above image, we have a standard three-point light rig using spotlights: a high key, low fill and a couple back lights. All lights have decay set to 'linear'.
When lighting a scene which will require some degree of 'fog' (or dust, steam, etc), I will usually not begin setting up the fog effects until the lighting is virtually complete. This means that there will probably be several lights, due to the fact that all bounce light must be simulated. The lights will all have some level of decay and their intensities will have been determined. In nature, particulate matter in the air will be illuminated by all available light, but Maya does not work this way. 'Fog' is enabled on a per light basis. While this is not 'natural', it offers a lot of flexibility. Furthermore, we can create a light whose sole purpose is to create fog... meaning that the light will not illuminate scene geometry.
When light fog is enabled, a new shape node is created and assigned a volume shader. The 'fog' exists as a volume rendering of the interior of this spherical or conical shape. The first thing you should do is scale the shape, something discussed further in another tutorial.
fog enabled on high key
Fog has been enabled for the key and the spotlight has been scaled. The result is 'fog' which has some issues... it is a little bright and is composed of extremely smooth gradations. While it is possible in nature to have smoothly illuminated fog, our goal is to illustrate how we can simulate effects which are more indicative of dust or smoke.
fog with intensity and spread modified.
At this point the only change has been to the 'intensity' and 'spread' attributes in order to produce a more subdued appearance. What we will now do is change the quality of the fog's density. If you look at the volume shader assigned to the fog shape node, there are attributes to control fog color and density. While a light's color, in nature, is independent of the color of the particulate matter in the air, it is best to leave light fog color as white. What happens in nature, is that a white light through blue smoke would illuminate objects with a blue light. Fog color in Maya, however, does not change the color of the cast light. But a light's color in Maya does color the fog... therefore you need to determine the correct coloration of the fog and the light through the light's color attribute. There is an alternate approach, however, which we are not going to get into in this tutorial. Technically, in nature, if a white light is shined through blue smoke, the saturation of the light's color will increase with distance from the light. This is possible in Maya through the use of 'color curves'. I'll leave it at that.
In regards to density, however, it is often necessary to modify the appearance of the fog so that it is not so evenly gradated. This is accomplished by mapping fog density with solid 3D textures.
Solid fractal mapped to fog density
The above image shows the result of mapping a solid fractal to fog density. By animating the texture node attributes, the fog can appear to change due to turbulence, wind or other phenomenon. All 3D textures also have a 3D placement transform node that can be moved, rotated, scaled and animated to design the look or placement of the fog. In the above image, the fractal transform was scaled, its 'frequency ratio' was lowered and its 'alpha offset' was raised. Be aware that the mapped density variation will not self-shadow. Therefore, this technique should only be used to simulate thin matter.
Ambient light added
Something important to realize with fog in nature, is that it becomes a lightsource itself, once illuminated. Maya does not calculate this type of reflected light, therefore you will often need to add lightsources in order to mimic the effect fog will have on surrounding objects. In the above image, an ambient light was added with 'ambient shade' turned off and its color sampled from the rendered color of the fog. This addition helps place the character within the fog volume.
fog variations, click images for larger sizes.
It is also possible to combine multiple 3D textures to further refine the fog density. By mapping the 'alpha gain' or 'alpha offset' attributes of the density map, other textures can be used to darken or lighten areas. This is helpful to reduce unnatural noise patterns. If fine noise is required, a scaled down fractal will work, but the result will look unnatural. A scaled up fractal or cloud texture could be mapped to the 'alpha gain' to further randomize the density.
Aside from fog density, one will sometimes need to think about -where- the fog should be most dense in the scene: near the ground? inside a room but not outside the window? When fog is associated with a light in Maya, the fog will always appear in front of that light. Our use of mapped density thus far is only specific to where the light illumination is, but not to where the light is in the scene.
image of fractal fog with ramp to control height.
In the above image we have denser, patchy fog near the ground with smoother fog towards the top of the image nearer the lightsource. This is accomplished by mapping planar projected ramps to the fractal's 'alpha gain' and 'alpha offset'.
3D placement nodes selected, hypershade graph.
The placement node is scaled to the size of the scene, or at least the bounding box of the lightfog shape. Use 'smooth' interpolation on the ramp, for a more natural gradation. Alpha gain is mapped to control where the fractal noise appears, while alpha offset is mapped to control where smooth fog appears.
click to play animation
The above animation shows the result of animating a searchlight sweeping in front of a blasted wall. Light rays enter the room as shadows are cast into the fog volume.
The two ramps are mapped to fog density so that fog only exists inside the room. One ramp controls fog height (Y-axis), the other controls fog density in the Z-axis.
Be aware that volume shadow occlusion only works with depth-map shadows. This creates problems if you have transparency mapped objects. There is a workaround for this that we will explore in another tutorial.
Another rendering limitation is that you should avoid animations where the camera enters, exits or moves around within a lightfog volume when 'light color' or 'fog density' have been mapped. The results will not be accurate as the Maya light fog engine is, unfortunately, pseudo-volumetric.
click to play animation
The above animation shows the result of mapping a point light-fog's density with a solid fractal, animating the scale of the lightfog, animating the fractal and placing an animated image sequence on to the point light's color. This renders extremely fast (10 sec/frame on a dual 2Ghz box) and looks cool. In order to fly the camera through it, however, we would have to swap the lightfog with a 'volume primitive' with a high sample rate.
click to play animation
In the above Zufuhr animation, I've used light fog (blue), volume primitives (warm) and particles (glow effect) together to get the end result. Again, the advantage of volume primitives is that they hold up better if the camera is moving around/through them. They also can be illuminated by multiple scene lights. All the techniques we've discussed in regards to mapping density work well with volumes, just be aware that their disadvantage is that they take longer to render.
Clearly there are many more applications than those we have discussed. By the way, while these effects could also be accomplished via rendered particle dynamics, our aim is to utilize more render efficient techniques whenever possible. Particles offer a lot more flexibility in terms of their movement and rendered appearance. The drawback is that they take longer to set-up, take longer to render and require knowledge of Maya's dynamics engine. Its up to you to learn through experience when to use which technique based on the requirements of a shot.
Well, that's it for now.