The STMap in NUKE is a simple but powerful node that handles texture warping this way: For each pixel in the output image, it looks at the corresponding pixel of the STMap and uses its red and green values as x/y coordinates respectively to pull the right pixel from the source image.

Given that your 3D renderer can output texture UVs, you can use these to modify or replace textures on a 3D rendered image.

Step 1
Pull in the texture you want to apply and the UV render. I’d also recommend creating an RGBA render of the image you’re working with so you can check to make sure your texture ends up in the same position. Also, you can pull the alpha channel from the RGBA render, which comes in handy.

The UV image should be in linear colour space, so make sure to use the correct setting in the Read node's ColorSpace tab. Otherwise your texture will end up distorted.

Step 2
Simply add an STMap node and hook the texture to its "src" pipe and the UVs to its "stmap" pipe. You will have to tell NUKE which channels to use for the UVs. In the case of my example, I need to set the "UV channel" knob to "rgb" since that is the layer where my UVs are located.

In my UV render, the UVs are actually located in the green and blue channel while the STMap by uses red and green of the control layer, so I need to insert a Shuffle node to copy the blue channel into the red.

You could of course shuffle blue and green (or whatever channels carry your UV data) into u and v channels respectively as well and use the UV layer as the control map in the STMap node. Whichever way, in the end it doesn't matter where the relevant pixel data lives as long as you set up your nodes properly.
Step 3:
Now simply pull the alpha channel from the original 3D render, pre-multiply the result and you're all set.
Alternative: IDistort vs. STMap

If you want to use an IDistort instead of the STMap you will need to use a colour expression node to modify the UV data slightly because IDistort pulls pixels from a position relative to the output pixel (i.e. 5 pixels from the left of the target pixel) whereas STMap uses absolute coordinates that are normalized (0,0 being the lower left and 1,1 the upper right corner of the image respectively).

Copy the UVs into the main stream of your texture and drop the following into a ColorExpression node to adjust the UV data:
u*width-x
v*height-y

I'm using "u" and "v" in this case because I copied the data into the u and v channels. If your data is located in other channels you will have to use the respective channel names. With the modified UV data you can append an IDistort node, set it to the correct channels and it should give you the same results as the STMap (although the filtering will be slightly different).

If the UVs go beyond the value of "1" you will have to insert another ColorExpression to make them repeat their normalized values (i.e. 1.5 = 0.5, 2.7 = 0.7, etc.) If you don't do this, you will see black holes in your result. One way is to use the fmod function.

Insert the following ColorExpression to adjust the UV render pass. Remember, in my example the UVs come in as green and blue channels:

Frank Rueter is a visual effects artist and compositor specializing in environment creation and TCL-based customization of NUKE. He has held VFX Supervisor, Compositing Lead, and TD roles on films including 'King Kong,' 'Flags of our Fathers,' 'Van Helsing,' 'I Robot,' 'The Lord of the Rings: Return of the King,' and others. You can reach him at frank@beingfrank.info.