1 The idea
The P pass stores each pixel’s 3D position in R G B (X Y Z), in scene units (metres in our Blender render). A matte built from the distance to a point in 3D selects by real distance, not by where things sit on screen, so things that touch on screen at different depths separate cleanly, and the matte stays in the same place in the world when the camera moves.
The sparks float 1.0 m above the sand. The cyan line marks everything within 2 m of them: the sand underneath and the robot’s near side. Try the “2D circle (screen)” first and watch the leak readout, then switch to the “3D sphere (P pass)”: click the sand under the sparks (orange cross), lift the centre and set the radius. The “P (XYZ→RGB)” view shows the positions as colour.
matte = 1 − smoothstep(r·(1 − f), r, |P − centre|)2 Hands-on
Task: matte the sparks’ reach, everything within 2 m of them: cover at least 85% of it while no more than 10% of the matte leaks beyond 2.4 m.
Hint: grow the 2D circle and watch the leak: a circle that covers 85% still leaks at least 63%, because near sand and ground much farther away sit side by side on screen. In 3D, click the cross, lift the centre to the sparks’ height, then set the radius.
3 Deep dive
Screen position vs 3D position
A roto or a 2D circle only knows where a pixel sits on screen. Near the sparks, sand a few metres away sits right next to ground much farther back, so any circle big enough to cover the sparks’ reach takes far ground with it. In this scene any 2D circle that covers 85% still leaks at least 63%.
In the P pass every pixel knows its real distance to the sparks, so a sphere centred on them picks only what is truly within reach, the sand underneath and the robot’s near side, and leaves the far ground alone even where it touches on screen.
When two parts overlap on screen at different depths, think P before you draw roto.
Building a sphere matte
Sample P on the sand under the sparks and add their height on the up axis to get the centre (X, Y, Z) in metres. Every pixel then measures the distance from its own P to that point: closer than the radius gives a high matte value, which fades to 0 over the falloff.
Edge pixels of a filtered P mix foreground and background positions, and unpremultiplying does not unmix them, so erode or edge-extend the matte before you use it.
- 1Shuffle P into rgb
- 2Sample P under the sparks + lift
- 3Distance to centre
- 4Radius + falloff
- 5Erode the edge
- 6Grade through the matte
P, Pref or roto
A P matte is fixed in the world: when the camera moves, the matte stays on the same spot, so it can replace tracked roto for grades. But a moving object travels through it.
Pref is the position in the rest pose, so a matte or noise built from Pref sticks to the surface of an object that moves or deforms.
| Matte source | What it holds | How the matte behaves |
|---|---|---|
| 2D roto | Screen position | Needs tracking; can’t split parts that overlap on screen |
| P | World position | Stays put in the scene; moving objects pass through it |
| Pref | Rest-pose position | Sticks to the surface of a moving or deforming object |
P is data, not colour
Read P raw, with no colour transform. P has negative values, so any Grade used to scale an axis needs black clamp off, or the negative positions vanish and half the matte goes empty.
Blender’s P is Z-up, while Nuke’s tools expect Y-up, so the axes must be remapped before you feed those tools.
Before trusting a P pass, sample a flat patch of ground: the up axis should read the same value across it.
4 In real work
In Nuke
- Read: load the EXR as raw data (no colour transform), then Shuffle2 pulls P (or Pref) into rgb.
- PositionToPoints2: set P_channel (and N_channel) to view P as a point cloud, check the axes and find the sparks in 3D.
- Expression: alpha from the distance between rgb (P) and the centre, divided by the radius and inverted.
- Erode: pull the matte edge in slightly, because P edge pixels are mixed.
- Clamp: keep the alpha within 0–1.
- Grade: use the matte as the mask for the grade on the comp (any Grade on P itself needs black clamp off).
Common mistakes → the fix
- ✗ Drawing 2D roto to split parts that overlap on screen at different depths✓ Use a P matte, which selects by 3D distance.
- ✗ Leaving black clamp on in a Grade on P✓ Turn black clamp off; P has negative values.
- ✗ Using P on a deforming character, so the matte slides off the surface✓ Use Pref so the matte sticks to the surface.
- ✗ Feeding Blender’s P straight into Y-up tools✓ Remap the axes first, then check a flat patch of ground has a constant up value.
- ✗ Expecting clean P matte edges, or hoping unpremult fixes them✓ Erode or edge-extend the matte; edge pixels are mixed.
Before you send the shot
- P is read raw as data, with no colour transform.
- No Grade on P has black clamp on.
- P axes checked: a flat patch of ground has a constant up value.
- The matte stays on the same spot in the world for the whole shot; Pref if the object moves or deforms.
- In the matte view, nothing leaks onto far ground and there is no bright rim.
5 Check yourself
Why does a 2D circle big enough to cover the sparks’ reach leak onto other things, while a 3D sphere from the P pass doesn’t?
🔒 Answer the question above and this card opens
1. The robot walks and swings its arm. You want a matte that stays on the hand’s surface. What do you use?
2. You add a Grade on P to stretch the matte along an axis, and half the matte disappears. What is the likely cause?
Where the numbers come from: Every picture is a Blender 5.2 Cycles render of our own desert and robot (tools/assets/passes_cg.py), computed in your browser. Blender’s P pass is in world metres, Z up (the plate’s P and the robot’s P). The target (2 m from the sparks) comes from the same render’s P; the 2–2.4 m shell counts as neither cover nor leak. The warm grade is a teaching effect, and the sphere’s fall-off is a teaching smoothstep; Nuke tools may shape it differently.