Part 5: Photorealistic Rendering with rendrib
revised 26 Jan 1999
Larry I. Gritz
lg@bmrt.org
The rendrib program is a high-quality renderer incorporating the techniques of ray tracing and radiosity to make (potentially) very realistic images. This renderer supports not only the required features of the RenderMan Interface, but also many of the more advanced Optional Capabilities, such as: ray tracing, radiosity, solid modeling, depth of field, motion blur, area light sources, texture mapping, environment mapping, displacements, volume and imager shading, and support of the RenderMan Shading Language.
The format for invoking rendrib is as follows:
rendrib [options] myfile.rib
Usually, this will result in one or more TIFF image files to be written to disk. If the RIB file specified framebuffer display (as opposed to file), or you override with the -d flag, the resulting image will be displayed as a window on your screen. When the rendering is complete, rendrib will pause. Hitting the ESC key will terminate. Alternately, if you hit the 'w' key, the image in the window will be written to a file (using the filename specified in the RIB file's Display command).
Format
or
PixelSamples
statements, then the values specified by
these statements will be used to determine the image resolution and
sampling rate for your image. If these statements are not in the RIB
files, the default values will be used (640x480 pixels and 2x2
sampling, respectively). You can change the defaults by using the
-res
and -samples
command line arguments.
Each take two arguments giving the x and y resolution or sampling
rates. For example, if you want your image to be rendered at 320x240
resolution with only 1 sample per pixel, you can invoke
rendrib in the following way:
rendrib -res 320 240 -samples 1 1 myfile.rib
Note that if the RIB file contains a Format
or
PixelSamples
statement which explicitly specifies the
image resolution, then the -res
or -samples
options will be ignored and the image will be rendered using the
values in the RIB file.
An alternative to setting a fixed number of samples per pixel is to use variance-based sampling. This method samples highly only in regions with high variance. To invoke this option, you can either put the PixelVariance directive in your RIB file, or use the -var command line option. This option takes three arguments: the desired maximum variance, the minimum number of samples per pixel, and the maximum number of samples per pixel. Here is an example:
rendrib -res 320 240 -var 0.01 4 32 myfile.ribNote that this example set the maximum variance in a pixel to 0.01, which totally overrides the
PixelSamples
directive or
-samples
option. In this example, all pixels will have
at least 4, and at most 32 samples. For most effective variance-based
sampling, you need to properly set the minimum and maximum numbers of
samples per pixel. This is explained in the "implementation-specific
Options" section of this chapter.
You can specify only a crop window to be rendered using the -crop option. It takes four arguments which are the same as the arguments to the CropWindow RIB directive. This can be used to render only a portion of an image. The default is to render the entire image. Here is an example:
rendrib -res 320 240 -crop 0.25 0.6 0.5 1 myfile.rib
By default, rendrib creates image files, and the only text output that rendrib creates is a periodic update of the current scanline which is being rendered and a notice when the rendering is complete. Errors are of course output if there are problems with the RIB file. There are two command line switches which can increase the amount of feedback which rendrib provides.
The -v
option (which stands for verbose) takes no
arguments. Its result is to inform you of all RIB files which are
read and all shaders which are loaded. For example:
rendrib -v myfile.rib
The -stats
option will print rendering statistics
after the image is completed. Statistics include data such as total
number of rays cast, percentage of shadow rays which were occluded,
memory usage, and so on. For example:
rendrib -stats myfile.rib
You can combine the -v
and -stats
options
if you want.
Sometimes you may only want to render a subset of frames from a
multi-frame RIB file. You can do this by using the
-frames
command line option. This option takes two
integer arguments: the first and last frame numbers to display. For
example,
rendrib -frames 10 10 myfile.rib
This example will render only frame number 10 from this RIB file. If you are going to use this option, it is recommended that your frames be numbered sequentially starting with 0 or 1.
By default, rendrib calculates images using the rendering technique of ray tracing. Ray tracing alone does no energy balancing of the scene. In other words, it does not account for interreflected light. However, rendrib supports radiosity, which is a method for performing these calculations. You can instruct rendrib to perform a radiosity pass prior to the ray tracing by using the -radio command line switch. This command is followed by a single numerical argument, which is the number of radiosity steps to perform. For example, the following command causes rendrib to perform 50 radiosity steps prior to forming its image:
rendrib -radio 50 myfile.ribIf the energy is balanced in fewer steps than you specify, rendrib will skip the remaining steps (saving time). Depending on your scene, the radiosity calculations can take a long time, but they are independent of the final resolution of your image.
By default, rendrib calculates the visibility between geometric elements by casting a minimum of one ray between the two elements. You can increase this number to get better accuracy (but at a big decrease in speed) by using the -rsamples option. This option takes a single integer argument. The minimum number of rays used to determine visibility will be the square of this argument. For example, the following command will perform a radiosity pass of 100 steps, using a minimum of 4 sample rays per visibility calculation:
rendrib -radio 100 -rsamples 2 myfile.rib
Several implementation-specific options and attributes alter the way in which radiosity is calculated. These are discussed in the following sections.
By default, any fully rendered frames are sent to a TIFF image file. However, you can override this and render directly to the display using the -d command line option. This option only works some platforms. Here is an example:
rendrib -d -res 256 256 -samples 1 1 myfile.ribYou can specify an optional integer argument to the -d switch, which causes the scanlines to be interleaved, giving you a kind of progressive refinement display. For example,
rendrib -d 8 -res 256 256 -samples 1 1 myfile.rib
will display every 8th scanline first (making a very quick, but blocky image), then compute every 4th scanline, then every 2nd, and so on, until you get the final image. This is extremely useful if you want to quickly see a rough version of the scene.
You can also specify the position of the window on your display using the -pos option. For example, to ensure that your window's upper left corner falls on pixel (300, 200), try:
rendrib -d 8 -pos 300 200 myfile.rib
When you submit a RIB file for rendering, the image files will have filenames as specified in the RIB file with the Display directive. If a file already exists with the same name, the original file will be overwritten with the new image. Sometimes you may want to avoid this. Using the -safe command line option will abort rendering of any frame which would overwrite an existing disk file. This is mostly useful if you are rendering many frames in a sequence, and do not want to overwrite any frames already rendered. Here is an example:
rendrib -safe -frames 100 200 myfile.ribThis example will render a block of 100 frames from the RIB file, but will skip over any frames which happen to already have been rendered.
Try this out for amusement:
rendrib -ascii myfile.rib
This will produce an ASCII (yes, exactly what you think) representation of your scene to the terminal window!
Option name paramsWhere name is the option name, and params is a list of token/value pairs which correspond to this option. Remember that options apply to an entire rendered frame, while attributes apply to specific pieces of geometry. Implementation-specific attributes are discussed in the following subsection. The various nonstandard options are listed below.
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 of the options discussed below, you can just put the Option or Attribute lines in this file in your home directory.
Option "render" "minsamples" [8] "maxsamples" [64]This sets the minimum and maximum number of samples per pixel, for scenes when the pixel variance metric is used. This only works if the RIB file contains a PixelVariance statement, but not a
PixelSamples
statement. These numbers are both integers.
Option "render" "max_raylevel" [4]This sets the maximum number of recursive rays that will be cast between reflectors and refractors. This has no effect if there are no truly reflective or refractive objects in the scene (in other words, shaders which use the trace() function). This number is an integer.
Option "render" "minshadowbias" [0.01]The "minshadowbias" option is the minimum distance that one object has to be in order to shadow another object. This keeps objects from self-shadowing themselves. If there are serious problems with self-shadowing, this number can be increased. You may need to decrease this number if the scale of your objects is such that 0.01 is on the order of the size of your objects. In general, however, you will probably never need to use this option if you don't notice self-shadowing artifacts in your images.
Option "render" "prmanspecular" [1]Pixar's PRMan does not use the SL specular() function as listed in the RI standard. BMRT uses the standard function, which results in specular highlights looking very different in the two renderers. This option, which takes an integer, causes BMRT's specular function to behave much more like PRMan's with a value of 1, and uses the specular function from the standard when given a value of 0. The default used to be zero (standard), but starting with BMRT 2.3.4, the default is 1 (PRMan). Use this option with a value of 0 in order to revert to the old (RI standard) behavior.
Option "radiosity" "steps"In addition to using the -radio command line option to rendrib, you can specify the number of radiosity steps with this option. Setting steps to 0 indicates that radiosity should not be used. Nonzero indicates that radiosity should be used (with the given number of steps) even if the -radio command line switch is not given to rendrib.
Option "radiosity" "minpatchsamples"Just like the -rsamples command line option to rendrib, this option lets you set the minimum number of samples per patch to determine radiosity form factors. Actually, the minimum total number of samples per patch is this number squared (since it is this number in each direction). In some cases, the render will decide to use more samples, but this is the minimum.
Option "searchpath" "texture" "/usr/local/textures" Option "searchpath" "shader" "/u0/lg/shaders" Option "searchpath" "archive" "path1:path2:path3"
Option "runtime" "verbosity" verbThis option controls the same output as the
-v
and
-stats
command line options. The verb parameter is a
string which controls the level of verbosity. Possible values, in
order of increasing output detail, are: "silent", "normal", "stats",
"debug".
Option "limits" "texturememory" [k]This option controls sets a texture cache size to k, which is an integer, measured in Kbytes. The renderer will try to keep no more than this amount of memory tied up with textures. Setting it low keeps memory consumption down if you use many textures. But setting it too low may cause thrashing if it just can't keep enough in cache. The default is 1000 (i.e. 1 Mbytes). The texture cache is only used for tiled textures, i.e. those made with the mkmip program. For regular scanline TIFF files, texture memory can grow very large.
Option "limits" "geommemory" [k]Analogous to the texturememory option, this sets a limit to the amount of memory used to hold the diced pieces of NURBS, bicubics, and displaced geometry. It is an integer, giving a measurement in Kbytes. The default is 40000 (i.e. 40 Mbytes). This can keep your memory consumption down for large scenes, but setting it too low may cause you to continually be throwing out and regenerating your NURBS or displaced surfaces.
Option "limits" "derivmemory" [k]A certain amount of memory is needed to allow rendrib's Shading Language interpreter to correctly compute derivatives. Very occasionally, you may need to increase this number (generally only if you have absolutely humongous shaders with many texture or other derivative calls). The argument is an integer, giving a measurement in Kbytes. The default is 2 (i.e. 2048 bytes). If your frames are not crashing mysteriously in the shaders, don't screw with this number!
Attribute name paramsWhere name is the attribute name, and params is a list of token/value pairs which correspond to this attribute. Remember that options apply to an entire rendered frame, while attributes apply to specific pieces of geometry. The various nonstandard attributes are listed below.
Attribute "radiosity" "averagecolor" [color]By default, the radiosity renderer assumes that the diffuse reflectivity of a surface is the default color value (set by Color) times the Kd value sent to the shader for that surface. For the lighting calculations to be accurate, the reflective color should be the average color of the patch. For surfaces with a solid color, this is fine. However, some surface shaders create surfaces whose average colors have nothing to do with the color set by the Color directive. In this case, you should explicitly set the average color using the attribute above. You may have to guess what the average color is for a particular surface.
Attribute "radiosity" "emissioncolor" [color]All surfaces which are not light sources (Lightsource or AreaLightsource) are assumed to be reflectors only (i.e. they do not glow). If you want a piece of geometry to actually emit radiative energy into the environment, you can either declare it as an AreaLightSource, or you could declare it as regular geometry but give it an emission color (see above). The tradeoffs are discussed further in the radiosity section of this chapter.
Attribute "radiosity" "patchsize" ps "elemsize" es "minsize" msThis attribute tells rendrib how finely to mesh the environment for radiosity calculations. The statement above instructs to chop all geometry into patches no larger than ps units on a side. Each patch is then diced into elements no larger than es units on a side. As a result of analyzing the radiosity gradients, elements may be diced even finer, but a particular element will not be diced if its longest edge is shorter than ms units. The smaller these numbers, the longer the radiosity calculation will take (but it will be more accurate). This attribute can be used to set these numbers on a surface-by-surface basis (i.e. different surfaces in the scene may have different dicing rates). The units ps, es, and ms represent are measured in the current (i.e. local) coordinate system in effect at the time of this Attribute statement.
Attribute "radiosity" "zonal" zonalvalThis attribute controls which radiosity calculations are performed on surfaces. This can be set on a surface-by-surface basis. Possible values for zonalval are shown below, in order of increasing computational cost:
Attribute "render" "visibility" bitmaskThis attribute controls which rays may "see" an object. The bitmask parameter is an integer, which is the sum of:
Attribute "render" "casts_shadows" shadowvalThis attribute controls how surfaces shadow other surfaces. Possible values for shadowval are shown below, in order of increasing computational cost:
Attribute "render" "truedisplacement" [onoff]Takes an integer argument, which if nonzero will make this primitive be diced and displaced using its displacement shader (if any). Only a displacement shader can move the diced geometry -- altering "P" in a surface shader will not move the surface, only the normals. Using a displacement shader without this attribute also only results in the normals being modified, but not the surface. Be sure to set displacement bounds if you displace! Please see the section on "limitations of rendrib" for details on the limitations placed on true displacements.
Attribute "displacementbound" "coordinatesystem" [space] "sphere" [rad]For truly displaced surfaces, specifies the amount that its bounding box should grow to account for the displacement. The box is grown rad (a float) units in all directions, expressed in the coordinate system space (a string). This works just like the nonstandard option of the same name in PRMan.
Attribute "render" "patch_maxlevel" [maxlevel] "patch_minlevel" [minlevel]Takes an integer argument giving the maximum (or minimum) subdivision level for bicubic and NURBS patches. These patches are subdivided based on the screen size of the patch and their curvature. This attribute will split the patches into at least (minlevel x minlevel) and at most (maxlevel x maxlevel) subpatches. The default is min=1, max=256. In general, you shouldn't ever need to change this, but occasionally you may need to set a specific subdivision rate for some reason.
Attribute "render" "patch_multiplier" [float]Takes an float argument giving a multiplier for the dicing rate that BMRT computes for displaced surfaces and for certain curved surfaces which are subdivided. The default is 1.0. Smaller values will make the scene render faster and using less memory, but may produce a more faceted appearance to certain curved surfaces. Larger values will make more accurate surfaces, but will take longer and more memory to render. The default is probably just right for 99% of scenes, but occasionally you may need to tweak this.
Attribute "light" "shadows" "on" Attribute "light" "shadows" "off"Turns the automatic ray cast shadow calculations on or off on a light-by-light basis. This attribute can be used for any LightSource or AreaLightSource which is declared. For example, the following RIB fragment declares a point light source which casts shadows:
Attribute "light" "shadows" "on" LightSource "pointlight" 1 "from" [ 0 10 0 ]
Attribute "light" "nsamples" [n]Sets the number of times to sample a particular light source to n, an integer (default = 1). This is only useful for an area light which is being undersampled -- i.e. its soft shadows are too noisy. By increasing the number of samples, you can reduce the noise by increasing sampling of this one light, independently of overall PixelSamples.
In order to more fully support the ray tracing features of BMRT, a few nonstandard functions have been added to BMRT's Shading Language. The next chapter describes how to use the Shading Language Compiler.
Note that these functions are not supported by PRMan's SL compiler. However, using the "ray server", PRMan's functionality can be extended to support these functions by using BMRT to compute them.
color trace (point from, vector dir)
from
in the direction of
vector dir
. The return value is the incoming light
from that direction.
color visibility (point p1, p2)
An example use of this function would be to make an explicit shadow check in a light source shader, rather than to mark lights as casting shadows in the RIB stream (as described in the previous section on nonstandard attributes). For example:
light shadowpointlight (float intensity = 1; color lightcolor = 1; point from = point "shader" (0,0,0); float raytraceshadow = 1;) { illuminate (from) { Cl = intensity * lightcolor / (L . L); if (raytraceshadow != 0) Cl *= visibility (Ps, from); } }
float rayhittest (point from, vector dir, output point Ph, output vector Nh)
from
looking in direction
dir
. If no geometry is hit by the ray probe, the return
value will be very large (1e38). If geometry is encountered, the
position and normal of the geometry hit will be stored in
Ph
and Nh
, respectively, and the return
value will be the distance to the geometry.
float fulltrace (point pos, vector dir, output color hitcolor, output float hitdist, output point Phit, output vector Nhit, output point Pmiss, output point Rmiss)
pos
in the direction dir
.
If any object is hit by the ray, then hitdist
will be
set to the distance of the nearest object hit by the ray,
Phit
and Nhit
will be set to the position
and surface normal of that nearest object at the intersection point,
and hitcolor
will be set to the light color arriving from
the ray (just like the return value of trace
).
If no object is hit by the ray, then hitdist will be set to 1.0e30, hitcolor will bet set to (0,0,0).
In either case, in the course of tracing, if any ray
(including subsequent rays traced through glass, for example) ever
misses all objects entirely, then Pmiss
and Rmiss
will be set to the position and direction of the deepest ray that
failed to hit any objects, and the return value of this function will
be the depth of the ray which missed. If no ray misses (i.e. some ray
eventually hits a nonreflective, nonrefractive object), then the
return value of this function will be zero. An example use of this
functionality would be to combine ray tracing of near objects with
an environment map of far objects:
missdepth = fulltrace (P, R, C, d, Phit, Nhit, Pmiss, Rmiss);
if (missdepth > 0)
C += environment ("foo.env", Rmiss) / missdepth;
The code fragment above traces a ray (for example, through glass). If the ray emerging from the far side of the glass misses all objects, it adds in a contribution from an environment map, scaled such that the more layers of glass it went through, the dimmer it will be.
float isshadowray ()
float raylevel ()
The purpose of the RenderMan standard is to allow one to specify the description of a scene without having to worry about how to render it. Thus, no mention is made in the standard of any particular rendering method. A particular implementation of the standard may support any one (or many) of the following: wireframe; flat shaded, Gouraud shaded, or Phong shaded z-buffered polygons; A-buffer; REYES; ray tracing; radiosity; or any other rendering method. Since this renderer stems largely from my own research in the area of illumination, it incorporates many of the latest advances in global illumination and rendering technology.
The default rendering method used by this renderer is ray tracing. Of course, if you only use standard surfaces and light sources, the results will not be very dramatic. But the shaders which use the trace() function can cast reflection and refraction rays. Light sources which cast ray-traced shadows can be added automatically, even from area light sources. However, ray tracing will still determine illumination only via direct paths from light sources to surfaces being shaded. No knowledge of interreflection between objects is available to the ray tracer.
That's where radiosity come into the picture. Radiosity will help to capture effects such as indirect illumination, soft shadows, and color bleeding. To render the scene using radiosity, just type:
rendrib -radio n myfile.ribThe parameter n is a number giving the maximum number of radiosity steps to perform. A typical number might be 50. Higher values of n will yield more accurate illumination solutions, but will also take much longer to compute. If the solution to the illumination equations converges in fewer steps, the program will simply terminate early, and not perform the additional steps. After the radiosity calculation ends, ray tracing will be used to form an image. This method of using radiosity followed by ray tracing is known as "two-pass" rendering. There are several advantages to the two-pass method:
If you want to use these features, you will need to make a few slight modifications to your RIB files, outlined below:
LightSource "bouncer"
The "bouncer" light source is actually a program which calculates these additional light paths for specular-to-diffuse illumination. In addition, any objects which you wish to act as specular reflectors, regardless of their shader type need to have the following additional attribute declared before the geometry is instanced:
Attribute "radiosity" "specularcolor" [ color ]
When rendering with radiosity, there are two ways to make area light sources. One way is to use the AreaLightSource directive, explicitly making area light sources. The second way is to declare regular geometry, but setting an emission color:
Attribute "radiosity" "emissioncolor" [color],The difference is subtle. Both ways will make these patches shoot light into their environment. However, only the geometry declared with AreaLightSource will be resampled again on the second pass. This results in more accurate shadows and nicer illumination, but at the expense of much longer rendering time on the second pass.
Please note that rendering full color frames can take a really long time! High quality rendering, especially ray tracing, is notoriously slow. Try a couple test frames first, to make sure you have everything right before you compute many frames. Multiply the time it takes for each frame by the total number of frames you need. If your total rendering time is prohibitive (say, 5 months), you'd better change something!
A good rule of thumb is that each frame in a 1 minute animation should take between 15 and 45 minutes to render on a typical machine in your computation arsenal. If your frames take less than 15 minutes each to render, you can probably afford to go ahead and use more features, more complex textures, higher sampling, or whatever. If your frames take much more than 45 minutes (and certainly if they take longer than an hour), you should really try to use some of the optimization methods outlined below. If you are computing only a single image, of course you can allow as much time as you want.
Don't bother praying or panicking: I have it on good authority that neither does much to increase rendering throughput. Some optimization hints are listed below. Obvious, effective, easy optimizations are listed first. Trickier or subtler optimizations are listed last.
Use low resolution when you can. You may want to do test frames at 320 x 240 resolution or lower. Remember that video resolution is only about 640 x 480 pixels. It's pointless to render at higher resolution if you intend to record onto videotape, since any higher resolution will be lost in the scan conversion.
Usually, 2x2 sampling is perfectly adequate to antialias geometric edges for video images. Higher than 3x3 does not usually give noticeable improvements for geometric edges. Motion blur, depth of field, and area light shadow penumbra tend to take lots of samples to antialias. There's not much you can do about that if you insist on using these effects.
If the source of your aliasing is blurry reflections or refractions from shaders which use the trace() function, you should consult the documentation for those shaders. There may be ways to increase the sampling rate for that surface only without increasing the sampling rate for the entire image (you can do this for my "shiny" and "glass" shaders).
Higher sampling rates should never be used to eliminate aliasing in shaders. Well written shaders should be smart enough to analytically antialias themselves by frequency clamping or other trickery. It's considered bad style to write shaders which alias badly enough to require high sampling at the image level.
Similarly, most objects can be treated as completely opaque (this assumption speeds rendering time). Some objects do not need to cast shadows at all (for example, floors or walls in a room). See the "nonstandard attributes" section of this chapter for information on giving the renderer shadowing hints.
Distribution of rays results in noise. The fewer samples per pixel, the higher the noise. So if you want to keep sampling rates low and reduce noise in the image, you should: avoid using the "blur'' parameter in the "shiny'' and "glass'' surfaces; do not use depth of field; use nonphysical lights ("pointlight'', "distantlight'', etc.) instead of physical and area lights.
The following list should delineate any implementation-specific limitations and incompatibilities with the published RenderMan standard.
True displacements are somewhat limited: (1) it only works for displacement shaders, not surface shaders; (2) it uses lots of memory, and also takes more time to render; (3) you cannot use "message passing" between the displacement and surface shaders; (4) you must remember to set displacement bounds; (5) you may get odd self-shadowing of surfaces during radiosity calculations if you use too small a shadow bias.
As I write this, the BMRT and Pixar's PhotoRealistic RenderMan ((R) Pixar) (sometimes called PRMan) are the only two widely available implementations of RenderMan. While rendrib uses ray tracing and radiosity, PRMan uses a scanline method called REYES. Though both renderers should take nearly the same input, the difference in their underlying methods necessarily results in different subsets of the RenderMan standard supported by the two programs. This section lists some of the incompatibilities of the two programs. These differences should not be construed as bugs in either program, but are mostly natural limitations of the two rendering methods. This list is for the user who uses both programs, or wishes to use one program to render output meant for the other.
This document last updated 26 Jan 1999 by lg@bmrt.org
All BMRT components are Copyright 1990-1998 by Larry I. Gritz. All rights reserved.
The RenderMan Interface Procedures and RIB Protocol are: Copyright 1988, 1989, Pixar. All rights reserved. RenderMan is a registered trademark of Pixar.