BLOG

VRay HDRI Compositing
Date: 04-04-13 9:59AM | Category: Tutorials - 3D

For this tutorial, we're going to go over the process of compositing a CG model into an existing photograph, using VRay HDRI lighting.

The techniques we'll be discussing are using a Linear workflow (Gamma 2.2), lighting the scene with our HDR map, utilizing ground plane reflections from your backplate photo, and adjusting some settings for the shadows.

First, let's go over what we need to shoot for our scene. We need a spherical HDR photo, using either the mirror ball or fisheye panoramic techniques. Obviously the fisheye technique is much more involved, but yields better results in terms of the overall quality. For this tutorial, we'll using a mirror ball HDR I shot over the weekend.

Once that's been captured, we need to shoot some backplate photos that we'll actually be compositing our model into. Remember if you're using a mirror ball, take the photos from a similar angle that the HDR photo was taken from (basically we just want to stay on the same 180 range that the HDR was captured from, so don't move to the opposite side of the mirrored ball.) *Also, pay special attention to the camera settings used in this photo: the focal length, aperture, ISO and shutter speed settings will help us later as we attempt to replicate this camera in 3ds Max. Lastly, it's wise to shoot a backplate where the camera is relatively level in terms of the roll (imagine if the camera was a steering wheel, you'd want that to have a minimum rotation.) Eventually we're going to have to manually position our camera in 3d space, and that type of rotation can be more difficult to get right.

For this tutorial, I'll be using some freebies so everyone can follow along:

HDRI and Backplates

Iron Man Helmet

I'll be compositing the Iron Man helmet into this photograph:

Now we have our assetts, so let's start working in 3dsMax.

Our first step will be to adjust a few settings to work with a Linear workflow. Essentially this means setting a few options in Max to use Gamma 2.2 lighting (more accurate to real-world lighting). I won't go into the theory of why we do this, but read this article if you'd like to learn more about exactly how & why this works. So go to Customize > Preferences > Gamma and LUT. Check Enable Gamma/LUT Correction, change Gamma to 2.2, check both the Material and Colors options, and change the Input Gamma to 2.2.

Then, let's create our Vray Light that will utilize our HDR map. Click anywhere in the viewport, and then set the light to Type: Dome. Adjust the Multiplier down to 1, and check Invisible. Let's move the light to the origin as well.

Now scroll down in the light panel, and click the "None" button under Use Texture. Select VrayHDRI, then open the material editor and drag that map into it so we can edit it. Click Browse and locate our HDR, then once it's loaded, change the Mapping Type to Mirrored Ball. Now adjust the Horiz. Rotation to 180 as a start. This will give us a lighting solution from the exact position our camera was when we took the HDR photo. Depending on how much we moved around for the actual backplate shot, we may need to adjust the Horiz. and Vert. settings to attempt to match that angle.

Now let's confirm that our initial lighting solution is working by doing a quick test render. Create a floor plane and a cylinder at the origin and let's adjust some VRay render settings.

Bring up the Render Setup, and let's change the renderer to VRay. Go to Assign Renderer (very bottom) and change Production to Vray Adv. Now go to the V-Ray tab > Frame buffer and enable the built-in Frame Buffer. Under Image Sampler let's change it to Adaptive Subdivision (faster rendering). Then move to the Adaptive subdivsion image sampler section and change the Max. rate to 3, and the Clr thresh to .005.

Move to the Indirect Illumination tab and turn that On. Leave Irradiance Map, but change the Secondary Bounces to Light Cache. Under Irradiance Map, change the settings to Medium (which we'll use while we're testing our lighting) and check Show calc. phase. Next, let's go into Light Cache uncheck Store direct light, and check Show calc. phase.

Now let's go into the Settings tab, and change the DMC sampler Noise Threshold amount to .005.

That should do it for the V-Ray settings, so lets create a V-Ray Physical Camera for our render. In the settings panel, confirm that Use Exposure is checked, and adjust the f-number to something around 2.0. Using the settings from our camera mentioned above, let's also change the ISO to 100 and the shutter speed to 60.

Now click the render button and we should see a nice (albeit very simple) rendering of our cylinder. At this point it probably looks dark, but that's where the Gamma 2.2 shift comes in. Click the sRGB button in the VRay Frame Buffer (along the bottom-left). This will preview the image in Gamma 2.2 and should look much better.

Alright, so our HDR lighting is working so let's move onto the backplate stuff. First we need to match our camera to the backplate photo in terms of the position/orientation.

Go to the Vray Camera viewport (typically the bottom right) and go to Views > Viewport Background. Browse for our backplate photo and make sure to check Match Bitmap in the Aspect Ratio. This should display the backplate photo in our viewport and now we need to manually match the exact angle of our photo. This is where the focal length of our camera settings from earlier will come into play. Select the VRay camera and input the focal length into the focal length (mm) setting, in this case the photo was taken at 50mm.  Now lets create a Box that sits in the middle of our scene which will assist the camera matching. Switch to wireframe and adjust the position and orientation of the VRay camera until all our perspective lines match the backplate photo. This can be a tedious process, but keep working until ALL 3 axis' are lined up.

Once our camera has been positioned correctly, we'll build a simple mesh that will serve as a 3D replica of our backplate for reflections and shadows. For many situations this will be as simple as a flat plane that will produce reflections from the ground, however if your scene includes some additional details, it's a good idea to build them as well. For example, let's say we've photographed a parking lot with a curb closeby. We'll want to extrude the plane up to include the curb so that our shadows wrap up and around it accurately. As long as the camera matches the scene, this should be a simple process. For this tutorial, we'll just add a simple plane right under our mesh.

Now we need to apply the backplate photo as a texture, projected directly from our camera. This is accomplished using the Camera Map Per Pixel material, which is precisely what it's made for. In the Material Editor create a new VRayLightMtl (more on this later). Click the Color button and add Camera Map Per Pixel as our sub-material. Click the Camera button and select your camera from the scene. Then click the Texture button and select your backplate photo.  Now apply this texture to your ground plane mesh, but before we render it we need to adjust a few settings. First, we created a VRayLightMtl as our initial map. This is because we don't want this mesh to actually be affected by the lighting in our scene, we want this texture to render exactly as it does in the original photo. So go back up a level to the VrayLightMtl and check Compensate Camera exposure. Then right-click your ground plane, go to V-Ray properties and uncheck Receive GI. Also, we don't want this mesh to actually render out, it's just providing reflections and catching shadows so check Matte Object, set Alpha contribution to -1.0, and then check Shadows and Affect alpha.

Now let's render again and our CG object should really look integrated into the scene.

We're almost there, but the last issue we need to address is the shadows. A general notion in the world of HDR lighting is that it's only a 85-90% solution. There will almost always be a need to manually tweak some lighting details and shadows are usually one of them.  For the most part, HDR's lack the contrast and dynamic range to produce hard, crisp shadows. There's a technique described here, which involves duplicating your HDR materials, and adjusting the Multiplier and Gamma values to produce hard shadows. However, this also involves duplicating your camera, and adjusting those settings so before you know it you have an entirely new scene just to attempt to render hard shadows. So my workflow involves just creating a Vray Sun, and positioning it until you get shadows that match your scene. (*Remember, to control the hardness of shadows in V-Ray, just adjust the size of the light, the smaller it is, the harder the shadows will be.)

That's about it :). At this point we can go ahead and crank up our Irradiance Map to High, and start rendering. (Remember we'll need to render the shadows separately since we're using an artificial light to generate them.)

Here's the final composite after bringing everything into Photoshop (which involved bringing up the Gamma to 2.2, and adjusting the shadow colors to a slightly blueish hue.)

And here's the final scene in 3dsMax 2009 format.