Quick And Dirty: Rendering On Multiple CPUs

by Mike Kost


Povray has some amazing abilities, but it's CPU intensive to use them all. Once you turn on media with scattering, anti-aliasing, and radiosity, be prepared to hibernate while waiting for your rendering is finished. If you have extra CPU's laying around, either as a dual-processor machine or an extra computer off in a corner, you have a chance at spliting up the work and finishing sooner. Unfortunately, Povray doesn't make it was easy as it could be. This Quick and Dirty tutorial shows how to split up and reassemble rendering jobs using Povray 3.6 and a Linux command line.

Quick Reading

Some light reading to break in the topic:

Povray and Spliting Up Jobs

Povray includes some wonderful command line switches that let you partition the portion of the screen to be rendered.

Start Row: Start rendering the image on row n
End Row: Stop rendering the image on row n

Note that the first row is 1. Some place the first row at 0, but not Povray, so be forewarned.

Using these command line switches, it is possible to instruct Povray to render only the top half of an image or only the bottom half of an image. Obviously, if the top and bottom halves are rendered separately, we can put the files together and voila! Unfortunately it's not this easy.

Povray and Output Files

Preferred file formats like .png is compressed file formats and very picky about how information is stored. When Povray finishes rendering a partial image, it stops outputting pixel information - if the .png or .jpg requires more information, it's out of luck. This results in file error when attempting to load the partial images in image viewing software.

To get around this, lets look at the uncompressed TGA file. The uncompressed TGA file has an 18-byte header and then raw pixels. The 19th byte is the first rendered pixel and the last byte in the file is the last rendered pixel[1]. This is something we can work with on the command line.

To get Povray to output to uncompressed TGA, we need another command line switch.

Output File Type: Store the rendered image using uncompressed TGA

Now, lets get rendering.

Splitting Up And Rendering

Now, on to rendering our partial segments. As an example file, I've borrowed the scene from my last tutorial. You can find the files here: example_scene.pov, object.inc.zip.

Now, on to rendering. For the example, I'll produce a 320x240 image. It'll be broken up into 2 renderings: the first will do rows 1 - 120 and the second will do rows 121 - 240.

First, to render the top half to a .tga, I'll call povray like so:
povray +W320 +H240 +SR1 +ER120 +FT +Oexample_scene_top example_scene.pov

When the example_scene_top.tga file is read into Gimp, it looks like this:

Top of the scene

Next, to render the second half to a .tga file, I'll call povray like so:
povray +W320 +H240 +SR121 +ER240 +FT +Oexample_scene_bottom example_scene.pov

When the example_scene_bottom.tga is read into Gimp, it looks like this:

Bottom half of image

We now have two portions of an image to put together.

Merging The Images

To merge the images together, we need to take the top image and tack the pixel data from the bottom image onto it. We can do this with a quick series of Linux commands:

cp example_scene_top.tga example_scene.tga

Copy to preserve the original - just in case
tail -c +19 example_scene_bottom.tga >> example_scene.tga

This takes all the bytes after and including byte 19 from example_scene_bottom.tga and appends them on the end of example_scene.tga

Now that the scene has been merged, our image looks like this:

Complete, Reassembled Scene

We've got our completed image. Woohoo!

Want To Know More?

Several other individuals have written on the topic of multi-cpu rendering: Notes and Disclaimers [1] - I know that this is technically not true. Pixels are usually 16-24 bits, but what I wrote sounds a whole lot better than "the first byte of the first rendered pixel" and "the last byte of the last rendered pixel"

Last edited: 09/25/04

Copyright (C) 2004 Mike Kost