Home · Lab · Tracking & Matchmove

TR5 Lens distortion: undistort, then redistort only the CG

Straighten the lens, then send the CG through the same lens as the plate

Tracking & Matchmove · ~9 min · Free

1 The idea

Every lens distorts: straight lines bend more the closer they are to the frame edge. CG rendered from a camera with no lens fits the plate in the centre but slides at the edges.

Set Picture to Grid chart (same lens) and move k until the line bend is close to 0. Then go back to the plate, set CG path to Redistort CG with your k and play the shot. Compare the edge-cone readout with the centre one: with no lens, the edge cones are off by up to about 12 px and the centre cone by about 0.6 px.

plate → undistort (track only) · CG → redistort → over untouched plate

2 Hands-on

Task: solve the lens so the line bend is at most 0.5 px, then redistort the CG so the edge cones are off by no more than 1 px over the shot.

Watch the grid lines near the frame edge against the dashed straight reference line, not the centre. Turn on View undistorted to see what k does, then judge by the edge cones while the shot plays.

SkyVFX Lab · TR5interactive · 1001

3 Deep dive

Why only the edges slide

A lens bends the picture little in the centre and more towards the edges. The CG camera has no lens, so it lines things up with the plate in the middle of frame, but the offset grows towards the edges, and as the camera moves, things crossing the frame appear to slide.

So if the centre sticks and the edges slide, don’t re-track yet: check the lens first.

Always check the frame edges; a good centre alone proves nothing.

The right order

Undistort the plate for tracking and 3D only. Apply the resulting camera or corner pin to the CG, redistort only the CG, then Merge it over the untouched plate.

When you have a grid shot through the same lens, solve from the grid. The solve also estimates the lens centre, which in real lenses is usually off the frame centre.

  1. 1Solve lens from grid
  2. 2Undistort plate (track only)
  3. 3Track / solve
  4. 4Render CG + overscan
  5. 5Redistort CG only
  6. 6Merge over original plate

Why not redistort the whole plate

Undistorting the whole plate, comping, then redistorting everything filters the plate twice for no reason. Deliver the original plate with no resampling at all.

Each LensDistortion is a resample of its own, so keep the plate out of the undistort/redistort chain and filter only the CG.

ChainFiltering
plate → undistort → CornerPinThe plate is resampled at least once: fine for tracking, never for delivery
CG → CornerPin → redistortOnly the CG is resampled
original plate → MergeThe plate isn’t filtered at all

Overscan for the redistort

A redistort pulls pixels in from outside the frame. If the CG is rendered exactly to frame, thin black slivers appear at the edges afterwards, so render the CG, or set the ScanlineRender, with overscan.

If you add a Crop to trim the bbox, it must not cut those overscan pixels away.

Look at the frame edges after the redistort with the gain pushed: thin black slivers show up.

The lens is part of the solve

Focal length, distortion and camera rotation are one solution. Don’t change one of them on its own; for another lens, re-solve.

Keep a master LensDistortion node in a backdrop and copy it where needed, so an accidental edit doesn’t spread through the script.

4 In real work

In Nuke

  1. LensDistortion on the grid: Analysis tab → Detect, fix bad edge points or add lines by hand with the Line Drawing Tools, then Solve.
  2. Copy the LensDistortion, set it to undistort and use it on the plate for tracking and the camera solve only.
  3. ScanlineRender with the solved camera, with overscan set.
  4. Copy the LensDistortion set to redistort onto the CG only, or output an STMap and apply it to the CG with an STMap node.
  5. Merge (over) the CG onto the plate that was never undistorted.
  6. Check: a Merge (difference) of comp against plate must be 0 outside the element.

Common mistakes → the fix

  • ✗ Undistorting the plate and delivering the undistorted plate✓ Use the undistorted picture only for tracking and solving; deliver the original plate.
  • ✗ Redistorting the whole comp instead of only the CG✓ Redistort only the CG, then Merge it over the untouched plate.
  • ✗ No overscan on the CG render, so black edges appear after the redistort✓ Render the CG, or set ScanlineRender, with overscan, and don’t let a Crop cut it off.
  • ✗ Checking only the centre of frame and calling it stuck✓ Play the shot and always look at the frame edges.
  • ✗ Changing the focal or distortion by hand after the solve✓ Treat them as one solution; re-solve if they must change.

Before you send the shot

  • The undistorted grid looks straight across the frame, corners included.
  • In motion, CG at the frame edges doesn’t slide, not just in the centre.
  • The redistort is on the CG only and the plate was never undistorted.
  • No black slivers at the frame edges after the redistort.
  • Comp vs plate difference is 0 outside the element.
  • Every lens node is a copy of the master LensDistortion.

5 Check yourself

One question to check yourself

The centre cone sticks to the ground, but the cones at the left and right edges slide. What is the likely cause?

What you learned

🔒 Answer the question above and this card opens

More questions

1. Why must CG that will be redistorted be rendered with overscan?

2. Which chain is right for putting CG onto a plate with lens distortion?

Where the numbers come from: A 48-frame handheld shot (640×360) rendered in Blender (Cycles) through our desert set, with a green screen on a pole and a drone flying across. Frame 1 is the still plate’s camera. Every true position comes from the scene’s own 3D (truth.json, dist.f32). Computed in your browser. The distortion is a teaching lens we applied ourselves (one radial term, k = 0.06, scaled so the corners stay inside the render); real lenses need the solver’s own model. The “no lens” CG uses a camera whose focal absorbed the lens’s central magnification, as a solve without a lens model would (a teaching approximation). The cones’ true positions come from the camera of our own rendered scene.