Simulate a time echo with a recursive render


If you think you need recursive rendering, i.e., rendering a frame that uses the last rendered frame as input, in order to, for example, speed up rendering processes and times, perhaps this script can help you.

Here's a problem I faced some time ago: I was trying to do a small effect, a kind of time echo, but over a large number of frames.

In short, I wanted to create a kind of light trail of a moving object. The trail was to remain fixed on the screen while slowly being created as the object moved.

I thought of using a "time echo" node with a very wide frame range (it had to cover the entire shot, which by the way had a high number of frames) and it actually was working.

With everything set up, I faced the first problem: rendering was extremely slow. Then I thought that such an effect was nothing more than the merge (over) of two frames: the last frame just rendered and the current one (obviously after a bit of prep to achieve what I wanted).

In this way, the rendering would be much faster because you didn't have to calculate the merge of a high number of frames but only two.

Second problem: I could not render by hand frame by frame and Nuke wouldn’t reload the Read node in real-time while rendering, so you would get a big error after the first frame.

So I thought of using a script that would render one frame (e.g., frame 1001) for me, reload the read node, and render frame 1002, which was computed as the merge of frame 1001 and the current frame 1002. Then I was to render frame 1003 which in turn was the merge of frame 1002 plus the current one, 1003. And so on...

Obviously, in order for the previous and current frames to be merged, I had to enter a time offset at the read node with time offset (frames) = 1 so that the previous frame would be read.

The script I used is this:


for frame in range(frame_start, frame_end):
      nuke.execute("Write",frame,frame,1)
      for node in nuke.allNodes('Read'):
            node.knob("reload").execute()


This script simply cycles over a range of frames (start to end) and for each one launches the rendering of the individual frame. It then updates all read nodes with the "reload" knob automatically and then moves on to the next frame.

I thought this script might be as useful to someone as it was to me, so although trivial, I wanted to share it.

I hope to save you a few precious seconds with this and look forward to seeing you in the next Pixel Wizard!