Sub topic 12
Lens shift and passepartout
This chapter assumes you can add a camera and make it the active scene camera. It also assumes you know that focal length and sensor size set the field of view, and that render resolution sets the aspect ratio. The Python snippets use the same bpy calls as earlier chapters.
Lens shift changes which part of the camera's view lands in the frame. Passepartout is a display aid that darkens everything outside the frame. They are covered together because you usually use both when you refine a framing.
What lens shift does
Normally the sensor sits centered behind the lens. The camera sees a symmetric cone, and the frame is its center. Lens shift slides the sensor sideways or up and down while the lens and the camera direction stay fixed. The frame then covers an off-center slice of what the lens sees.
The camera does not rotate, so the view direction is unchanged. Only the crop moves. Two results follow from this:
- Parallel lines in the world that are parallel to the sensor plane stay parallel in the image. Tilting the camera makes them converge.
- Perspective does not change. Objects keep the same relative sizes and spacing, because the camera position has not moved.
You can think of shift as rendering a larger image than you need and cropping it, without the cost of rendering the extra pixels.
The shift properties and their units
Blender stores shift on the camera data as shift_x and shift_y. In the Properties editor they are in Camera > Lens > Shift X and Shift Y. Both are unitless and run from -10 to 10.
The unit is the larger dimension of the frame. At 1920×1080, a shift of 1.0 moves the view by 1920 pixels in either direction. A vertical shift of 1.0 does not move it by 1080 pixels. A shift of 0.5 in Y moves the frame up by half the frame width, which is 960 pixels and almost a full frame height.
This surprises many people, because they expect vertical shift to be relative to the height. The rule that holds for every aspect ratio is:
pixel offset = shift * max(resolution_x, resolution_y)Positive shift_x moves the frame to the right. Positive shift_y moves it up. The subject therefore moves the opposite way in the image: a positive shift_y pushes the subject down in the frame.
The conversion is exact when Sensor Fit is Auto, and the longest-side rule holds for that setting. If you force Horizontal or Vertical fit, the shift is measured against that chosen dimension. Check the fit before you compute pixel offsets.
Why shift beats tilting for buildings
Photographers know this as the problem of converging verticals. You stand in front of a tall building and point the camera upward so the roof fits. The camera is now tilted, so the vertical edges lean toward each other at the top.
You can avoid this by keeping the camera level and shifting the lens up. The sensor plane stays vertical, so vertical edges stay vertical, and the roof comes into frame.
The following script builds a level camera and uses shift to lift the frame by a quarter of the image height:
import math
import bpy
scene = bpy.context.scene
scene.render.resolution_x = 1920
scene.render.resolution_y = 1080
cam_data = bpy.data.cameras.new("ArchCam")
cam_data.lens = 24
cam_data.sensor_fit = 'AUTO'
cam_obj = bpy.data.objects.new("ArchCam", cam_data)
scene.collection.objects.link(cam_obj)
cam_obj.location = (0.0, -12.0, 1.6) # roughly eye height
cam_obj.rotation_euler = (math.radians(90), 0.0, 0.0) # level, looking along +Y
# 0.25 * 1080 px = 270 px; 270 / 1920 = 0.140625
cam_data.shift_y = 0.140625
scene.camera = cam_objA camera rotated 90° on X is level. It looks along the world +Y axis with its up direction along +Z. Any tilt away from 90° brings convergence back.
Computing a shift from pixels
Because the unit is the longest side, it is easier to decide on a pixel offset and convert it. This helper does the conversion for the current scene:
import bpy
def shift_for_pixels(scene, dx=0, dy=0):
"""Return (shift_x, shift_y) that moves the frame by dx, dy pixels."""
longest = max(scene.render.resolution_x, scene.render.resolution_y)
return dx / longest, dy / longest
scene = bpy.context.scene
cam_data = bpy.data.objects["ArchCam"].data
cam_data.shift_x, cam_data.shift_y = shift_for_pixels(scene, dx=0, dy=270)
print(cam_data.shift_x, cam_data.shift_y)Resolution percentage is left out on purpose. It scales the rendered pixel count but does not change the framing, so the ratio is the same at 50% as at 100%.
Shift with other camera features
- Track To constraint: The constraint rotates the camera toward the target, so the subject is centered, and shift then moves the frame off that center. The two work against each other if you want a level camera. For architecture, skip Track To and set the rotation by hand.
- Orthographic cameras: Shift also works here. It moves the frame by the same fraction of the longest side, measured in the camera's orthographic scale.
- Panoramic cameras: Support depends on the render engine and panorama type, so test it before you rely on it.
- Animation: Both properties can be keyframed, which gives a slow reveal that looks different from a tilt. The camera does not rotate, so there is no change in perspective during the move.
- Depth of field: Shift does not move the focus plane. A focus object still decides the focus distance, so the shifted frame can contain the subject while the focus stays correct.
Passepartout
A passepartout is the opaque border of a picture mount. In Blender it is an overlay in camera view. It darkens the area outside the camera frame so you can see exactly what will render. The setting is on the camera data under Viewport Display > Passepartout, and it has an opacity control.
It has no effect on the render. It exists only to help you judge framing in the viewport. It also makes the surroundings visible, which is useful when you need to place objects just outside the frame, such as a light or a flag that must stay out of shot.
import bpy
cam_data = bpy.data.objects["ArchCam"].data
cam_data.show_passepartout = True
cam_data.passepartout_alpha = 0.85 # 0 = no dimming, 1 = fully opaque
cam_data.show_composition_thirds = TrueAt alpha 1.0 you see nothing outside the frame, which helps when you want to concentrate on the composition. At low alpha you keep a view of the scene around the frame. A value near 0.5 is a good starting point. Blender's default is 0.5.
The overlay appears only when you look through the camera with an active scene camera, and only if overlays are enabled in the viewport. If you cannot see it, check these three things in order:
- The viewport is in camera view (numpad 0).
- Overlays are switched on in the viewport header.
- The camera's Passepartout box is ticked and its alpha is above 0.
Working with shift and passepartout together
Shift changes what is inside the frame. Passepartout shows where the frame ends. A practical routine for a framing is:
- Place the camera and set the focal length. Keep it level if the scene has strong vertical lines.
- Turn on passepartout and the thirds overlay, and enter camera view.
- Adjust Shift X and Shift Y until the subject sits where you want it.
- If the framing is still not right, move the camera. Shift cannot replace a position change, because it does not alter perspective.
| Goal | Tool | Changes perspective? |
|---|---|---|
| Move the subject within the frame, keeping verticals straight | Lens shift | No |
| Aim at a subject and re-center it | Rotate the camera or use Track To | Yes, parallel lines converge |
| Change how large the subject appears | Focal length or camera distance | Distance changes it, focal length does not |
| See what is outside the frame | Passepartout | No, it is display only |
Common errors
- Large values by mistake: Shift is measured in frame widths, so 1 or 2 pushes the subject far out of frame. Typical values are between -0.5 and 0.5.
- Forgetting that the direction is inverted: Positive Y shift raises the frame and lowers the subject.
- Correcting a tilted camera with shift: Shift is no help if the camera has a visible tilt. Level it first.
- Assuming passepartout affects the render: It does not. A dark border in the viewport will not appear in the output.
- Mixing up shift and offset in post: Shift is applied in the camera, so reflections, shadows and depth of field respond to the shifted view. A crop in post only trims pixels.
Exercise
A scene renders at 2000×1000. You want the subject to appear 200 pixels higher in the image while keeping the camera level. What Shift Y value do you set, and in which direction does it go?
Show answer
The unit is the longest side, 2000 pixels. The subject must move up, so the frame must move down, which means a negative shift: 200 / 2000 = 0.1, so Shift Y = -0.1. A positive Shift Y raises the frame and lowers the subject.
Exercise
You tilt a camera upward to fit a skyscraper, and the sides of the building lean together. Name one change that keeps the whole building in frame without the lean, and say what you must do to the camera rotation first.
Show answer
Set the camera rotation to exactly level (90 degrees on X), then raise Shift Y until the top of the building is inside the frame. The level camera keeps the sensor plane vertical, so vertical edges stay parallel.