Converting Pworld to Pref In Nuke

How to create a position pass that sticks to your animated geometry…

Converting Pworld to Pref In Nuke

How to create a position pass that sticks to your animated geometry…

In this article, I’ll show you how to create a reference/object position pass using world position in Nuke, which you can use to create position mattes that stick to animated and deforming geometry

A position matte (highlighted in cyan) that sticks to an object which is translating, rotating, and scaling. 

Pworld Vs. Pref

Position data is incredibly useful for grading CG renders (among other things). 

With it, you can create procedural mattes and avoid tons of unnecessary roto.

For static objects, the common world position pass (often called Pworld or just P) works really well for generating position mattes. However, as soon as an object is animated, the world position pass falls short. Any position mattes you create with it will not stick to the animated object. 

That’s because the world position pass is centred around the world origin, and any animated objects will move through the coordinates. So in the position pass, the same parts of the animated object will receive different position values on each frame. 

An object moving through the (static) world coordinates. 

Any position matte gizmo, which by design creates a matte based on the values in the position pass, therefore can’t create a matte which sticks to the animated object using the world position. 

However, the gizmo can create a matte that sticks to the object – if we instead use another type of position pass which is centred on the object itself, the reference/object position pass (often called Pref or Pobject). 

The coordinates in this pass follow the animated object: 

Coordinates wrapped around the object and sticking to it. 

Working Around Nuke’s Limited Position Options

As far as I’m aware, Nuke doesn’t offer any direct ways of generating a reference position pass – only a world position pass. 

But, as always, with a bit of ingenuity we can make one. 

The idea is to create a world position pass, output it in UV space, framehold it to lock the coordinates, and apply it back as a texture to our animated geometry.

This requires the geometry to have UVs.

The coordinates will then stick to the object, and we can use them to create position mattes which will also stick to the object. 

The setup. 

First, you’ll need to grab your animated geometry and your camera, and connect them up to a ScanlineRender node. 

In the Shader tab of the ScanlineRender1 node, tick output vectors and choose a layer to output the position data to. Below, I chose to create a new layer and name it P

Outputting a world position pass using the ScanlineRender1 node. 

To do the same, click on the dropdown menu next to surface point, select new, name your layer P, click on the rgba button, and then hit OK

Creating a position layer. 

The ScanlineRender1 node will now output world position data in the P layer. Let’s turn that into a texture: 

In the ScanlineRender tab of the ScanlineRender1 node, set the projection mode to uv

Setting the projection mode to uv in the ScanlineRender1 node. 

Next, shuffle out the position pass (which is now in UV space) using a Shuffle node. 

Make sure to set the alpha to white in the Shuffle1 node! You’ll need a solid alpha in order to apply the position data back onto the geometry correctly. (That is, to use the full, unaltered position values).

The Shuffle1 settings. 

Next, pick a frame where the animated geometry is visible in the frame and FrameHold the world position texture. 

Then, apply this frameheld texture back onto the animated geometry using an ApplyMaterial node. 

Output the textured geometry through a new ScanlineRender node with the projection mode set to render camera, using the same camera as before. 

Now, you’ll have a reference position pass in the rgb channels. 

Add your favourite position matte gizmo at the end, and colour pick away! 

I hope you found this tutorial useful. For more Nuke tips & tricks, see Nuke.