Below are two images we'll be using to learn from. I've gone ahead and drawn in our lines of perspective to determine where the vanishing points are along the horizon. We will need to know where the horizon is so that we can properly set up our cameras in max.


Setting up Max
Lets start with the image of my front yard and sidewalk.
First thing we need to do, is set up our photo as a background in both our rendering and our viewport. To do this, open the material editor and put a bitmap in the diffuse slot of a new material. Make sure to change the coordinates to "Environment" and the type to "Screen." Now open the Environment window found under the "Rendering" menu across the top of the max UI. At the top where it says "background" select the bitmap we assigned in the material editor. Now we need to put that same photo as a background in our viewport. From the "views" menu along the top of the UI choose "viewport background." Check the box labeled "Use environment background." Also make sure to check the box labeled "display background."
Now create a target camera. Ok...remember your training. We were able to determine in the pervious section how high off the ground the camera was by looking at common objects in the scene. We can also guess that since I'm about 6' tall...that the camera was about 5'-6" off the ground. So lets move our camera up to 5-6". Max has done us a favor and built in a horizon that will display in the camera viewport. To turn it on select the camera and in the modify panel near the top is a check box labeled "Show Horizon." Now if you move the cameras target up and down you will be able to visually line up the cameras horizon with the horizon of our background photo. Now create a plane object and scale it so that its really long and extends out towards the horizon a LONG way. We will used this as a guide to make sure our perspective is right.
VERY IMPORTANT TIP...
You need to make sure your max camera is using the same lens as the camera that the photograph was taken with. If you don't have this right it will never line up correctly. Most cameras have either a 50mm lens or 35mm lens. Mine had a 50mm lens. So make sure your max camera is set the same.

You may have noticed that the lines of my plane object don't exactly line up with the photo. This is because cameras in max do not have a curved lens like real world cameras. Without some kind of plugin or post effect you cannot get this exact. So just make it as close as you can. The wider the real world camera lens was, the more optical distortion you get (like fish eye cameras). In this example the distortion is very mild and will go un-noticed, however, in animations it may become more noticeable.
Now we can start placing our objects into the scene using the plane we created as our ground plane. Make sure to scale your 3d objects appropriately like we discussed in the first part of this tutorial.

Well...Its not fancy, but I'm just trying to get the ideas across.
TIP...
Objects that you want in your composite to appear partially buried in the ground should be pulled down into our ground plane. I've pulled the sphere down a little so that later it will look like its sitting in the grass.
MATTE MATERIALS
Matte materials are materials that do not render, but will receive shadows, reflections, and most importantly will occlude objects (hide parts we don't want to render).
In the material editor click the "standard" button and choose "Matte/Shadow" from the list. The default settings are what we want, though I recommend that you pay close attention to the "Opaque alpha" check box and the "affect alpha" check box. First assign the default matte material to your ground plane and render. In the render window along the top are buttons. Immediately to the right of the RGB buttons is a black/white button. This displays your alpha channel. Notice that the ground plane does not show up. This is what we want. If you go back and check that "Opaque alpha" box in the material the ground plane will show up in the alpha. Most of the time you will not want an opaque alpha.
MATCHING LIGHTING
Its always easiest if you were actually there when the picture was taken. That way you'll remember more about where the sun was and how the shadows were falling. As far as sun placement goes, your kinda on your own to figure it out. By looking at the shadows of the cars and the street sign we can make a pretty accurate guess where the sun was. I took this photo at around 11am, I believe, so the sun was pretty high. Notice that the shadows of the cars are pretty short. If we look at the street sign we can see the sun was at a slight angle off from perpendicular to the sidewalk. Use as many clues as you can. It will require some test renders to see if your in the ball park.
TIP...
If you want, you can quickly create a cylinder and position it at the same location as the sign. Make it narrow like the signs pole and roughly the same height. Now you can set up your lighting trying to move your sun light so that the real shadow of the sign and the rendered one line up.
Its up to you what type of shadow you use. Raytraced, Shadow map or area shadows will all work just fine. Area shadows are the most realistic, but you have to have a good grasp of real world lighting to get a realistic match. I'm using a shadow mapped shadow for this example. It is important to make your shadows as much like a raytraced light as you can, later on in post we can blur the shadows more if we want them softer, but we can't sharpen them up. Why not use a raytraced light??? Two reasons, speed and sometimes ugly things happen to your shadow pass with raytraced shadows. Once you've got the sun in the right spot go back to the matte material and turn off "affect alpha" in the shadow portion of the shader. We don't want the shadow to show up when we render this pass because we will be making a separate shadow pass later on. I always give my sun a slightly yellow tint.

Now we need to match the diffuse light from the sky. This part is a little tricky, and how you approach this depends on what layers you want to have later on, and if you plan on using GI. For this example I will show you how to set up your renders to make use of ambient occlusion using a GI renderer. This method is not a true ambient occlusion like the kind used in the film industry. This version is a cheat that is very similar.
Most GI renders come with a skylight option which creates a sort of sphere of light around your entire scene. While this is a perfectly good way to light a normal render, this does not work well if you plan on using ambient occlusion. The reason its not good is because it will create shadows, and all we want is the diffuse light alone. We will have a separate shadow pass later on and we don't want to double up shadows.
Create an omni light anywhere in the scene and make it "ambient only" and a light blue sky color. Ambient lighting is typically bad to use when rendering cause it will rob you of detail when using bump maps. However, brazil users will be happy to know that they have a way of preserving this detail when they render there ambient occlusion pass. If your not using brazil you can still use the ambient light because even though the bump maps will get flattened out in shadow areas, its pretty minor. All renderers that have a skylight feature suffer from this problem anyways so your not alone. The problem occurs because light is hitting the objects surface equally from all directions which flattens out any bump detail.

I've thrown a bump map on the first teapot to show how the bump detail gets lost in the shadow areas. The effects are pretty negligible though. I've also turned off "affect alpha" in the matte material which is why the shadows are gone. Don't forget to do this.
Creating layers
Now its time to finally start rendering out our different passes. You can decide how many and which ones you want to render out based on how much control your looking for. For this example we will be breaking the layers down to the following...
Ambient occlusion, shadow, specular, key light and ambient light.
To get these layers its as simple as just isolating what you need for each one.
SHADOW & SPECULAR
Shadow and specular passes can easily be created using max's built in render elements found in the render dialog window. Open the render elements rollout and choose "add." From the list choose "shadow" and "specular." After you render two more render windows will open showing these extra passes. The shadow pass should be completely black. However, if you check the alpha you should see a completely black render except for the shadows which show up white. The specular pass should also be all black except for where specular highlights occur.

Shadow pass above. Specular pass below.

When you save these layers the file type you choose is very important. I always use Targas with the following settings.

The bits-per-pixel has to be set at 32 so that the alpha information is saved within that single file. Compressing is not necessary but will keep your file sizes smaller and it doesn't really have that big an effect on the image quality. Pre-multiplied alpha means that when you bring that layer into your compositing software the alpha information will automatically mask out only the areas you want for that layer.
KEY LIGHT & AMBIENT LIGHT
To render out your key and ambient passes is very easy. For your ambient pass just turn off your sun light and render. Should look like this.

Your key light pass is just your sun light with no ambient light. Should look like this.

Remember to turn off specular for your key light because we've already made a separate specular pass. We don't want to double up anything we've already done once before.
AMBIENT OCCLUSION
For this example I'm going to use Brazil R/S just because of one of its really handy features. The ambient occlusion pass can be made with any GI renderer that has the ability to create skylight. As far as I know, all renders for max can do this. I will assume that you know how to use whatever GI renderer your using and won't go into any real detail about how to set up each one. You basically want something like this.

Make all your materials white with no specularity. You may want to save this as a separate file since your be changing materials and you can't UNDO that. Turn on skylight for your renderer and make its color white. You don't need any light bounces, in fact, the less you use the better. Your going to want a large range in value so that you have more room later to work with. Non-Brazil users will not have the bump mapping show up on their objects just as I mentioned before.
Brazil users do not have to change the materials on their objects. If your using brazil find the "render pass control" rollout. Turn it on and then choose "white plaster" from the "global material replacement" pull down. This will automatically put a white material on all your objects and lucky you...It will preserve the bump map information from the original textures.
Now that you have the layers you need you can start compositing.