Wednesday, October 16, 2013

Virtual Tea

So you have been tasked to create a virtual asset and match it to a real life still. That sounds down right impossible, I know, but it's not! It's not too complicated a process, you just need to get your render passes right. I used Maya for this, so I will explain the process in that program. Feel free to use any program you are comfortable with. Here are a few steps that will help you. 

First, you need a still to match your item to. I used a tea cup and saucer. Set up your object in an interesting set up and take lots of pictures. Lots. You want interesting compositions with clear pure white and pure black areas so as to show the most variance in value. Make sure your shadows are clean and visible, don't make this too hard on yourself. Here are some of my sets


Here is the still I chose to work with:


The shadow is not too clean, but the object is a nice size and the lighting is pretty straight forward. It is a little blurry and you don't want that on your still. I am a trained professional, so its ok. 

Next you need two more photographs of that same setup. One with a block and one with a chrome ball. The block picture will help determine the axis positions in your 3D modeling software. The chrome ball will give you accurate reflections and an environment map to get final gather lighting from. Here are mine:



Make sure the corner of the block is facing straight to the camera. This is crucial to match your virtual camera to the real one. If the camera positions don't match, your composition will never look believable. 

Start modeling your object. Take reference images from top, bottom and side views to make sure it is the correct dimensions all over. Once you are happy with your model you can begin on creating the camera. 



 Create a new camera, your RenderCam. In its attributes, create an image plane in the Environment tab and use the photograph of your object with the cube. This will ensure your camera is always looking at the image you are trying to match and movement will be relative. Next create a cube and change the pivot to the corner that faces your camera. Put that corner at the origin point. Now zoom in, out, rotate the camera and move it around until the cube matches the block in the photograph as perfectly as possible. 


Next try to match your modeled object to the original one in the picture. Do not move the camera anymore! Make sure your object sits on the grid. That grid represents your ground in the photograph and the object should be on it; not through it or above it, on it. 


So far so good! Now it's time to start on the lights. First thing is to determine the direction. Put a spotlight in the scene and turn raytrace shadows on. Move the spotlight around and try to match the angle, length and intensity of the shadows. It wont be perfect with just one light, but this is our starting point. Once your shadows work well, then start thinking about the lights. Does the spotlight work well as a key light? Maybe an area would work better? Add some fill lights to color and soften the shadows and add some bounce light.


Next you add your textures and modify your materials so that they look right. Blinn is the best place to start from. You can get rid of the cube in the scene now and move your cup to where you will want it to be in the final image. 


Next are your render layers. You can get a really nice render out of Maya in a single pass, but then you wont be able to fine tune the image once you take it into a compositing program. These are the layers you will need:

Diffuse
This layer needs your object and all the lights. Create a layer override in the material to turn the Specular all the way down to 0. 


Specular
Same as Diffuse layer, but instead use the layer override to turn Diffuse down to 0.


Shadow
Include your object, the lights and a ground plane. You can set this layer to the Shadow preset from Maya. 



Reflection
Include your object, a copy of the object in the original position in the image and a sphere. The sphere should contain the entire scene and have the image you got from the chrome ball projected as an environment map. Use the ball unfold. Set your render to final gather and turn of all other lights. Use layer override in your object's material attributes to turn Diffuse  to 0, and Specular and Reflectivity to 1.  Make sure the copy object is not renderable, but visible in reflections. 




Occlusion
Include your object and ground plane. Set the layer attributes to the default Occlusion preset. You should separate this into 2 passes, one for the object occlusion and one for the ground occlusion. This is not necessary, but it will make it easier to fine tune in the compositing. 




Fill
Include your object and the environment sphere. Set render to use final gather. 



  Once you have all these layers you can take it into compositing. For this, I used NukeX. 


First, merge the Fill layer onto the Diffuse layer with screen mode. 

Merge the Reflection layer onto the Specular layer also with screen mode. 

Merge the Fill/Diffuse onto the Spec/Reflec again with screen. 

Add the object's Occlusion layer as a mask. To do this, first connect the layer to a Shuffle node and place all RGB on alpha, and Alpha on red. Then connect that to an Invert node and connect that to the mask channel of a Color Correct node to which the last Merge is connected. This is so that you can change the gain/color on the actual image rather than on the Occlusion layer, where it would do nothing. Lower the Gain in the Color Correct to what looks good. 

Add the Ground Occlusion layer to the Original Image in the same way you added the Object Occlusion layer. Then Merge The previous Color Correct to the newer Color Correct as an over. 

Connect the Diffuse node to a Premult node and attach this to the current Merge node as a Mask. This will help with the dark edges from the CG render. 

Lastly add the Shadow layer as mask with the method you used before. Change the gain to match the shadows of the original. Change the color too, it will help. 

Those are the basic steps to composite your CG model into a real life still. Depending on your object, you may need other masks, such as for reflectivity, and you will also need to add correct depth of field, which is not covered here. Tweak your values until it looks good. Mine looks ok, still needs some work, ane the handle is modeled wrong, but I know the steps to fix it.