Vous êtes sur la page 1sur 4



> Maya & Mental Ray Volume Scattering (Ray Marching)

In this tutorial we are going to use mental ray and Maya to produce the image below.

The method to generate this image is called volume scattering, or ray marching. This can be seen in real life when light beams hit dusty
or smokey volumes of air. For example light beams coming through a window into a dusty room, or the beams of lights at a concert, as
they pass through the smokey atmosphere. The light hits the dust or smoke particles, and is scattered in various directions.
The reason this is also called ray marching is because of the way mental ray calculates these images. In a given volume, mental ray
calculates how many dust particles are encountered by each ray as it travels through the room. Each sample is taken at various points
along the ray at either regular intervals, adding more samples in between when two samples are drastically different, or use variable
spacing, dependant on the various factors, such as the distance of the ray from the light source.
Well, enough background, let's get on with the tutorial.
What we will need is at least three things: a light source, a room filled with smoke, and a camera. The occluding objects are just to make
it look nicer :)

Ok, so first things first, set up a scene with a large polygon cube and the spheres inside. Position a spot light as shown in the picture,
and your basic scene is set up. It's worth increasing the subdivisions of the larger spheres, to prevent flat edges.

The bounding box is what will contain our ray marching volume. We could attach the "fog" to the camera, but that would increase the
render times severely, so we limit it to a specified volume.
Now, let's set up the materials. Create a new Lambert material and a Blinn. Rename the materials if you want, and assign the Lambert to
the bounding box, and the Blinn to all the spheres. It doesn't really matter what you use for the bounding box, as we aren't going to render
the bounding box. We've assigned the Blinn to the spheres to give them the shiny appearance.
Ok, open the attributes of the Lambert shader and click on Show Output Connections (see below)

on how to enable mental ray custom nodes.

The transmat node doesn't have any settings, so let's just skip ahead to the parti_volume node settings. Set Color to the colour you want
the fog to be. I have chosen a light blue colour in the example (R:0.566, G:0.705, B:0.902). Set Extinction to 0.001 and Min_step_len to
0.03 and Max_step_len to 0.2. Leave the rest as default.
If you want to know what all the other settings do, just look it up in the Maya manual by searching for parti_volume. Otherwise I'd just be
repeating everything from it.
Next we need to edit the light settings. We need to make it a physical light, and set the Exponent down to 1. See the image below.
By increasing the Exponent value, the light rays die quicker. Try experimenting with this value a little. For the physical_light node, set the
settings as follows: For the colour, select any light colour, I have chosen a turquoise with the settings (H:180, S:1, V:70000). The reason
the V value is so large, is because that generates enough brightness to pass through the volume. If you turn this down too much, you
won't be able to see anything. Set the cone to 500 and the Cos_exp to 1. The large cone angle will make sure the light shaft will cover the
entire scene. In the spot light attributes, I have the set the cone angle to about 120.
Now we need to attach the light message to the parti_volume light input. You can either do this via the connection editor

or you can use this MEL command:

connectAttr -f spotLight1.message parti_volume1.lights[0];

Just replace the names of the nodes with whatever they are called in your scene.

Now if you hit render (with mental ray enabled) you should get the image above. Update for Maya 7.0

I've finally gotten round to try this effect for Maya 7.0 as I have received a number of emails asking why the method above doesn't work for
Maya 7. Well, I had a quick play and there's only one major difference. You can follow the rest of the tutorial and just adjust things slightly
to fit in with the new layouts and settings. So, here we go, the main difference is in setting up the mental ray shaders. Here's a
screenshot of the settings:
What it is is that we need to add the parti_volume_photon shader aswell now. Now, although I have left the transmat shader there,
according to the manual we don't need it anymore:

" mental ray 3.3 and later do not require the transmat and transmat_photon shaders; they allow leaving the material shaders to remain
undefined to stop the object from interacting with visible rays. Such an object is called a hull object because it acts as a hull for a volume,
but is not visible itself. "

So if you like, you can omit that.

I must also add that the values of the settings are also slightly different to the old tutorial. I'm not going to give you the whole detail here as
you probably want to fine tune your scene anyways, but a good starting point is:

For the parti_volume shader and parti_volume_photon:

Scatter: what ever colour you choose. I started with 0.05 0.05 0.05 (RGB values)
Extinction: 0.05

for the parti_volume_photon only:

min steplen 0.5
max steplen 5
(Steplen changes the resolution of the fog)

The rest you can copy from the old tute. Obviously play around with the settings until you find something you like.

As for the light, same again, but thistime turn the photon intensity down and the V value of the light's colour. For some reason these
values are a lot more sensitive since Maya 5.