Monday, June 4, 2012

Custom Image Plane and Correct Aspect Ratio

When i read this post on cgTalk i remembered a tool i wrote some time ago for a friend that needed a custom mesh based image plane. So i dug out the script and made a little tool from it. 


The setup is fully node based (no expressions, fully interactive) and calculates the corners of the image plane from camera aperture and focal length. Locators are placed at these calculated positions. The scaling of the image plane is then calculated from the distance between these locators.
There's an attribute on the camera shape called "Image Plane Distance" which lets you - as the name implies - adjust the plane's distance from the camera. Another attribute ("Use Film Offset") lets you define whether the image plane should be offset with the cameras film offset. A shader with connected file texture is also automatically created (and assigned) to the image plane as well as a display layer.

For the system to work, the camera's Film Aspect Ratio (the aspect ratio of the aperture) must match the Device Aspect Ratio (the with/height ratio of the rendered image). When creating a custom image plane, the tool will automatically adjust the cameras aperture for matching aspect ratios. To ensure that your framing is maintained, the aperture can only be adjusted in certain ways depending on your setting for the Film Resolution Gate (Film Fit). 

Here are the rules for adjusting the aperture and maintaining the framing:

// FILL
// adjustment depends on difference between device aspect ratio and film aspect ratio
   // if film aspect ratio > device aspect ratio --> adjust horizontal aperture
   // if film aspect ratio < device aspect ratio --> adjust vertical aperture
 
// HORIZONTAL
  // adjust vertical aperture
 
// VERTICAL
  // adjust horizontal aperture

// OVERSCAN
// adjustment depends on difference between device aspect ratio and film aspect ratio
   // if film aspect ratio > device aspect ratio --> adjust vertical aperture
   // if film aspect ratio < device aspect ratio --> adjust horizontal aperture

You can also use the script to only adjust the cameras film aspect ratio (without creating the image plane). It's advisable to do this before exporting your camera (e.g. to Nuke or Fusion) to ensure the camera will match the footage.

You can download the tool HERE.

Known issues:
This system only works for square pixels because it does not take the Pixel Aspect Ratio into account. It would be possible to integrate, but i never render anything but square pixels.

3 comments:

  1. great script.
    do you know a way to tell maya to adjust the device aspect ratio automatic when creating a new camera?

    ReplyDelete
  2. the aperture of a newly created camera is determined through an optionVar which is defined in the userPrefs.mel (..\Documents\maya\2012-x64\prefs\..)
    from the top of my head i don't know a way to set this value at creation. but you could create a shelf button, containing the create camera command as well as a call to the RS_correctAspectRatio procedure from my script.

    ReplyDelete
  3. so assuming that the procedure is sourced, the MEL for the shelf button could look something like this:

    // create camera
    $myCam = `camera`;
    // skip the next two lines if you just want a single node cam
    objectMoveCommand;
    cameraMakeNode 2 "";
    // correct aspect ratio for new camera
    RS_correctAspectRatio({$myCam[0]});

    ReplyDelete