next up previous contents
Next: Using BMRT as a Up: Blue Moon Rendering Tools Previous: Shaders and Textures

Subsections

Miscellaneous Tools

Writing RIB with libribout

You may wish to write a C or C++ program which makes calls to the procedural interface, resulting in the output of RIB. The resulting RIB may be piped directly to another process (such as a previewer), or redirected to a file for later rendering. The library libribout.a does this. This library provides a `C' language binding for the RenderMan Procedural Interface.

The libribout.a library has all its public routines use the C language binding, but its implementation contains C++ code, so it is important to either use a C++ compiler to link with it, or else to manually include the standard C++ libraries.

If your program is written in C++, you can link libribout.a in the usual way. The following example shows how to link with this library on a typical Unix machine:

        CC myprog.c -o myprog -lribout -lm

If your program is written in ordinary C, then you could compile with C, then link with C++:

        cc -c myprog.c 
        CC myprog.o -o myprog -lribout -lm

On an SGI, it's apparently important to include -lC on the linkage line, to ensure that the C++ standard library is linked properly.

In any case, this will result in an executable, myprog, which outputs RIB requests to standard output. This may be redirected to a specific RIB file as follows:

        myprog > myfile.rib

Remember that the RiBegin statement usually only takes the argument RI_NULL:

        RiBegin (RI_NULL);

The default of sending RIB to stdout can be overridden by providing a filename to the RiBegin statement in your program. For example, suppose your program contains the following statement instead:

        RiBegin ("myfile.rib");

In this case, the RIB requests corresponding to the Ri procedure calls will be sent to the file "myfile.rib" rather than to standard output. In addition, if the filename you specify starts with the `|' character, the library will open a pipe to the program specified after the `|' symbol. For example, RiBegin ("|rgl"); will cause the RIB you produce to be piped directly to a running rgl process without creating an intermediate RIB file.

Remember to tell the C compiler where the ri.h and libribout.a files are, or it won't be able to find them.

On most platforms, BMRT is also distributed with a dynamic library, libribout.so (or perhaps libribout.so.2.3.6). This library performs the same function as libribout.so, but is a dynamic library, which means that it is shared by all programs that link against it, rather than being separately copied into every resulting executable needs the library. Please consult the manual pages to your C compiler, or your local system administrator, for the fine points of using dynamic libraries.

Parsing Shader Arguments

Pixar's PhotoRealistic RenderMan implementation provides a linkable library which allows a developer to read a compiled shader file (.slo) to determine what type of shader it is and what parameter names and defaults belong to that shader. Since Pixar's .slo format is different from BMRT's .slc format, similar functionality is provided to parse the .slc files. The C language header file for these is slc.h. This file should be fairly self-documenting, and certainly anybody with experience using Pixar's libsloargs.a library ought to have an easy time using it.

These routines are all contained in libribout.a, so you should link your software against libribout.a if you are outputting RIB or parsing shader arguments or both.

However, if you want to parse BMRT shader arguments but use some other RIB client library (such as PRMan's librib.a), then there is an additional library you can use, libslcargs.a, which contains only the routines for .slc file parsing, but none of the symbols which are also expected to be in a RIB client library.

Simple Image Compositing with composite

Starting with release 2.3.6, BMRT includes a program to perform elementary image compositing operations. If you render your images with alpha channels (i.e. "rgba"), then coverage information will be stored with every pixel in the image. For the purposes of composite, RGB images without alpha channels will be assumed to have an alpha of 1.0 at every pixel.

composite may be run as follows:


composite file1 over file2 -o output
composite file1 in file2 -o output
composite file1 out file2 -o output
composite file1 atop file2 -o output
composite file1 xor file2 -o output

Composite images file1 and file2 using one of the standard image compositing operators described in (Porter & Duff, "Digital Image Compositing", Proceedings of SIGGRAPH '84, pp. 253-259), storing the composited image in file output.


composite file1 plus file2 -o output
composite file1 minus file2 -o output

Add or subtract two files, storing the results in file output. Pixels are clamped to [0,maxval], where maxval==255 for 8 bit images, maxval==65535 for 16 bit images.


composite file1 scale float -o output
composite file1 dissolve float -o output
composite file1 opaque float -o output

These three unary operators take a floating point number, rather than a filename, as their second operand. They all scale the channels of the image, but in slightly different ways. The scale operator multiples the RGB channels, but leaves the alpha alone - i.e. it can brighten or darken an image without changing its transparency. The dissolve operator scales the alpha along with the RGB. Finally, the opaque operator will scale only the alpha channel.

Hint for beginners: you probably want over.

Setting default options and attributes

Remember that both of BMRT's renderers (rendrib and rgl) read from a file called .rendribrc both in the local directory where it is run, and also in your home directory. This file can be plain RIB, which means that if you want to set any defaults (default resolution, shader search path, texture cache size, etc.) you can just put the Option or Attribute lines in this file in your home directory.

farm: Poor Man's Render Farm

Many people ask how they can divide rendering of a single frame among several processors or machines. Starting with BMRT 2.4, the Perl script farm accomplishes this task, in a relatively rudimentary way.

How to use farm

1.
Set the environment variable BMRT_FARM to be a blank-separated list of the names of machines which can be used as render servers. Machines with multiple processors should be listed multiple times. For example, if you have a machine named "fred" with two processors, and one named "wilma" with one processor, then run:

setenv BMRT_FARM "fred fred wilma"

if you use csh. If you use sh, try:

export BMRT_FARM="fred fred wilma"

2.
Make sure that rendrib is in the default path of each remote machine, and that mkmosaic is in the path on the local machine.
3.
Run farm: farm myfile.rib

What farm does

First, farm will look at your RIB file to figure out the resolution and the name of the TIFF file that it will render. It will choose an appropriate number of subwindows to render.

One by one, it will send the frame to machines on your BMRT_FARM list, using the -crop and -of flags to make rendrib render particular crop windows. Machines whose load averages are too high will automatically refuse the frames.

When farm sees that all the subsections are finished (each will leave a little file indicating that it's done), it will assemble all the pieces using the mkmosaic program, and clean up all the cruft files.

Important farm restrictions

1.
Because farm relies on rsh, you can only use it on UNIX (or UNIX-like) operating systems.
2.
You can't use farm to render to the display (the -d flag). It must be rendering to a TIFF file.
3.
Don't try using any other rendrib command line flags. Request all image options (like radiosity options) in the RIB file with Option and Attribute statements.
4.
Hitting Control-C to interrupt farm will kill only farm, but will leave the individual crop windows rendering on the remote machines. Beware.


next up previous contents
Next: Using BMRT as a Up: Blue Moon Rendering Tools Previous: Shaders and Textures
Larry Gritz
2000-04-14