This is going to be great fun. A blog post and a tutorial all wrapped up into one.
So, as many people know, I’m in love with volumetric lighting. So much so that the first script I wrote in MEL was for a simple volumetric lighting setup. I’ve used a couple different approaches to get this effect in Maya, but my favorite is Mental Ray’s parti_volume shader.
This weekend, in preparation for SIGGRAPH, I’ve been revisiting scripting to give my demo reel a little boost. Before diving right into a Python script that I’ve been wanting to develop for a few years now, I decided to whet my appetite with some MEL. I opened up my old volumetric lighting script and immediately cringed. Staring right at me were all the blatant errors and bad practices that I had managed to sweep under the rug when I just wanted to be “finished” with it the first time. Time to clean that up.
Besides re-writing some of the old stuff I added a bunch of things that, for lack of a better term, actually makes the script useful. The first version of my volume lighting script really only set up the shader/lighting network and increased some render settings to their bare minimum needed value. Some of the script defaults and new functions allow for the setup workflow to go much more smoothly.
In addition, it gives you all the normal controls in the parti_volume shader so you don’t have to go digging around in the shading network to actually do things. This includes a few presets so that the average user who either is new to lighting or doesn’t work much with rendering can get great results just by clicking some buttons. And for the rest of the crowd who really does care about tweaking values to get their desired look, the presets give you a good starting point to work from.
I’m not going to go into how to manually set up a parti_volume shading network. There’s plenty of tutorials out there that will teach you how to do that. If you’re interested CGNotebook.com has a great one here on how to do this. They also have another good reference page for learning what all of the controls do.
I’m here to teach you about light scattering and what these cryptic “R”, “G1”, and “G2” values mean.
“Participating media” is the term that we use to describe the little bits and pieces of stuff that float through the air around us. Whether it’s dust or moisture or smoke, you are always surrounded by tiny particles that will transmit, absorb, and scatter light (unless you happen to live in a vaccuum). You notice this effect in your house by opening the curtains or by shining a flashlight in an otherwise dark room. When it’s rainy or foggy outside, street lamps will often have a glow around them; a parting in the clouds may reveal a sharp beam of sunlight coming down. All of this can be accurately simulated in Maya using the parti_volume shader, and the good news is that all of the science has been done for you!
The bad news is that these guys who figured out a model for light scattering through participating media just assumed we were all going to know what they were talking about, and Mental Images didn’t bother to simplify the execution of this idea. This might leave you scratching your head when it comes to altering the 3 values that are most important in deciding the aesthetic quality of your volumetric lights: R, G1, and G2. Don’t worry, I’m going to explain them to you.
In this lighting model that we’re going to use, we have 3 ingredients. First, we have a ray of light. Second, we have a point of contact. Third, we have scattered light.
The image above depicts isotropic scattering, which is a fancy term for when light is evenly scattered in all directions. As you might imagine, though, not all light is scattered equally. To simulate water vapor or dust, we have to use an anisotropic scattering method. To do this, we’re going to have to touch those scary controls on our parti_volume shader: R, G1, and G2.
This is an image that I wish I had seen a long time ago. I made it after sifting through several sources that all provided half-explanations. I provide this to you with the disclaimer that it might not be a 100% correct depiction of the controls, but it explains how the values work to the best of my knowledge.
The best way to think of it is as 2 separate lobes, named G1 and G2. You will have back scattering if the value is between -1 and 0. You will have forward scattering if the value is between 0 and 1. A value of 0 will produce uniform scattering.
The G values aren’t necessarily constrained to being forward or back scattered, but it is traditionally G1 that contains a value from -1 to 0, with G2 containing a value from 0 to 1.
The R value will give weight to the different G values. A value of R=0 gives a weight of 1 to G1 and a weight of 0 to G2. As you might guess, a value of R=1 gives a weight of 0 to G1 and a weight of 1 to G2. Often, a value to the left or right of .5 will be used to favor either front or back scattering.
Whew. That wasn’t too bad, now was it? Let’s get away from those values for now, you will understand how they work with a brief history lesson and a few visuals.
A long time ago in a galaxy far, far away, British physicist Lord Rayleigh and German physicist Gustav Mie created some models to describe ways that light scatter through volumes. As luck would have it, we can use the R, G1, and G2 to re-create these effects.
Rayleigh scattering occurs when the particles in the air are slightly smaller than the wavelength of the light. We can use R=.5, G1= -0.46, and G2= 0.46 to get this in Maya.
Mie scattering occurs when the particles in the air are about the same size as the wavelength of the light. Two types of Mie scattering are used. Hazy Mie (R= 0.12, G1= -0.5 G2= 0.7) is used for sparse particle density and Murky Mie (R= 0.19, G1= -0.65 G2= 0.91) is used for dense particle density.
I hope this brief introduction to the physics of light has thoroughly annoyed and confused you. One of the functions of my volume lighting tool allows the user to select R, G1, and G2 presets based on Rayleigh and Mie scattering. My aim for this tool is to eliminate the archaic technical aspects of implementing this lighting workflow and let an artist focus solely on the task of producing aesthetically pleasing images. Stay tuned for an update on this tool, as I plan to finish it soon and then release it for public use!