CGI Intro

In this lab you will create and render a CGI 3D scene. The CGI tools used in this lab are only installed in R105.

RIB files

Download RIB cube and have a look at it in your preferred editor. The file describes one frame of CGI in RenderMan format. Although the syntax is different, you will see that all the operations are similar to those in OpenGL.

RIB is a common file format used in CGI. Simple files like this one can be written by hand, but they are most often generated as the output of a 3D modelling & animation app such as Maya. (Often they are called RenderMan files, because Pixar developed RIB as the file format for their RenderMan rendering package.)

For this course we will use the open source Pixie renderer to generate images.

CGI rendering can easily generate dozens or hundreds of images which would fill up your disk quota. You should not do this lab within your home directory. Instead, create a temporary work area with something like

$ cd /tmp
$ mkdir frames
$ cd frames
Copy the cube.rib file into this work area and create the one output frame with
$ rndr cube.rib
When it completes, you will have a new file cube.tiff. Have a look at it with an image viewing program. (TIFF is a 2D raster file format, not 3D.)

Shaders

RenderMan shading is fully programmable. (Although the RIB files themselves are not.) The color of the cube faces is calculated by the plastic shader, the source code for which is in /usr/local/share/Pixie/shaders/plastic.sl. Have a look at the code.

Ka, Kd, Ks, roughness are roughly equivalent to the OpenGL material ambient, diffuse, specular and specular shininess. I is the viewing direction, N the surface normal. Cs, Ci are the surface and output RGB colors, Os, Oi the surface and output opacity (alpha). Compare this code to the OpenGL lighting algorithm described in the textbook.

In the shaders dir you will also see that there is a .sdr file for every .sl. The RenderMan shading language is (mostly) portable between renderers, but for efficiency reasons shaders are compiled for each implementation.

For an example of the much more complicated shading that is possible with programmable systems, download this wood surface shader into your working area. Compile it for use by Pixie with

$ sdrc wood2.sl
Edit cube.rib and replace the plastic shader by this new wood2. Render the cube again and view the new cube.tiff.

Have a look at the wood2.sl source code. Traditionally, a texture like this would be a digital photograph or painted by an artist. Here, though, the wood is a procedural texture, with each texel being generated only as needed by program code.

A Complete CGI Shot

Download make-ball.py into your working area. Have a look at the code in your preferred editor.

make-ball.py simulates a bouncing ball and describes the geometry through the Ri library, RenderMan interface. There are no event handlers or callbacks in the code, just a loop that generates frames as fast as possible. Instead of drawing 3D graphics, the Ri library generates RIB commands. It's possible to create RIB files using just Java println or C printf, but the Ri library is more convenient and does some useful error checking.

1. Generate a short 2 second sequence with

$ python make-ball.py 2 > ball.rib

Have a look at the generated ball.rib file. Note that while the RenderMan shading language has if statements and loops, the RIB file format doesn't, so every frame has to be listed.

2. Render the shot with

$ rndr -p ball.rib

This will take around five minutes to complete. When finished, you will have fifty TIFF files in your work area.

You can preview the shot with

$ animate ball*.tiff

animate is part of ImageMagick, a collection of command line image manipulation tools. It just draws the image files to the screen one after the other.

3. Assemble the frames into the final output file with

$ convert -monitor ball*.tiff ball.mpg

This will also take several minutes to complete. convert is another of the ImageMagick tools.

You now have an MPEG file. You can view it with

$ ffplay ball.mpg
on the R105 PCs, or with any other movie player application that understands the format, such as QuickTime Movie Player on a Macintosh.