Keywords: main

Next: 1.22 Contours Up: 1. Functionality Previous: 1.20 Color Calculations

# 1.21 Output Shaders

mental ray can generate more than one type of image. There are up to five main frame buffers: for RGBA, depth, normal vectors, motion vectors, and labels. The depth, normal vector, motion vector, and label frame buffers store the Z coordinate, the normal vector, the motion vector, and the label of the frontmost object at each sample of the image. If multiple samples are taken for a pixel, the frame buffer value for that pixel may be either any one sample value, or a blend of all samples. The number and type of frame buffers to be rendered is controlled by `output` statements. Output statements specify what is to be done with each frame buffer. If a frame buffer is not listed by any output statement, it is not rendered (except for RGBA, which always exists). There are two types of output statements, those specifying output shaders and those specifying files to write.

There are also up to eight user-defined frame buffers2.1that can be defined with any data type, using a frame buffer statement in the options block.

Output shaders are user-written functions that can be linked at runtime that have access to every pixel in all available frame buffers after rendering. They can be used to perform operations like post-filtering or compositing.

Files to write are specified with data type, file format and file name. If the data type is omitted a default data type is used that is assumed to be the ``best'' type for the given image format. The data type implies the frame buffer type. There are special file formats for depth, vector, and label files, in addition to a variety of standard color file formats. By listing the appropriate number and type of output statements, it is possible to write multiple files. For example, both a filtered file and the unfiltered version can be written to separate files by listing three output statements: one to write the unfiltered image, one that runs an output shader that does the filtering, and finally another one to write the filtered image. Output statements are executed in sequence.

The following file formats are supported:

Symbol | File format | Supported data types
--- | --- | ---
`"rla"` | Wavefront image | `rgba`
`"pic"` | SOFTIMAGE image | `rgba`
`"alias"` | Alias Research image | `rgb`
`"rgb"` | SGI color | `rgba`
`"jpg"` | JFIF image | `rgb`
`"tif"` | compressed TIFF image | `rgba, rgba_16, rgb, rgb_16`
`"tifu"` | uncompressed TIFF image | `rgba, rgba_16, rgb, rgb_16`
`"picture"` | Dassault Systèmes PICTURE | `rgb`
`"ppm"` | Portable pixmap | `rgb`
`"targa"` | Targa image | `rgba`
`"bmp"` | MS Windows BMP bitmap | `rgba`
`"qntpal"` | Quantel/Abekas YUV image, 720x576 | `rgb`
`"qntntsc"` | Quantel/Abekas YUV image, 720x486 | `rgb`
`"ct"` | mental images color texture | `rgba, rgba_16, rgba_fp`
`"st"` | mental images alpha texture | `s, s_16`
`"nt"` | mental images normal vectors | `n`
`"mt"` | mental images motion vectors | `m`
`"zt"` | mental images depth (-Z) channel | `z`
`"tt"` | mental images tag channel | `tag`
`"bit"` | mental images bit mask | `bit`
`"Zpic"` | SOFTIMAGE depth (-Z) channel | `z`
`"map"` | for memory mapped textures | any

Each of these file formats implies a particular default data type (the first entry in column ``Supported data types''); for example, `"rgb"` implies 8-bit RGBA, and `"zt"` implies Z. The default data type may be overridden by explicitly specifying another data type, such as a 16-bit type, in the output statement, as long as it is supported and appears in the above table. mental ray will adjust its frame buffer list to compute the requested types. For example, the standard RGBA frame buffer stores 8 bits per component by default, but if any output statement references a 16-bit type, the RGBA frame buffer also switches to 16 bits.

The available data types are:

Symbol | Data type
`"rgb"` | 8-bit RGB color
`"rgb_16"` | 16-bit RGB color
`"rgba"` | 8-bit RGBA color and alpha
`"rgba_16"` | 16-bit RGBA color and alpha
`"rgba_fp"` | floating-point RGBA color and alpha
`"a"` | 8-bit alpha channel
`"a_16"` | 16-bit alpha channel
`"vta"` | vector texture derived from alpha, 2 floats per pixel
`"vts"` | vector texture derived from intensity, 2 floats per pixel
`"z"` | depth information, 1 float per pixel
`"n"` | normal vectors, 3 floats per pixel (X,Y,Z)
`"m"` | motion vectors, 3 floats per pixel (X,Y,Z)
`"tag"` | object labels, 1 32-bit unsigned integer per pixel
`"bit"` | bit mask, 1 bit per pixel
`"contour"` | contour lines

The difference between `"vta"` and `"vts"`, and between `n` and `m`, is significant only when automatic conversions are done. The file contents are identical except for the magic number in the file header.

The floating-point RGBA data type `"rgba_fp"` allows color and alpha values outside the normal range (0,...1), and no dithering is applied even if explicitly enabled. In contrast, any conversion to the 8-bit or 16-bit formats will clamp values outside this interval. Note that dithering reduces the effectivity of RLE compression.

All mental images file formats contain a header followed by simple uncompressed image data, pixel by pixel beginning in the lower left corner. Each pixel consists of one to four 8-bit, 16-bit, or 32-bit component values, in RGBA, XYZ, or UV order. The header consists of a magic number byte identifying the format, a null byte, width and height as unsigned shorts, and two unused null bytes reserved for future use. All shorts, integers, and floats are big-endian (most significant byte first).

mental ray can combine samples within a pixel in different ways. The combination of existing samples can also pad the frame buffers to ``bridge'' unsampled pixels. Interpolation of colors, depths, normals, and motion vectors means that they are averaged, while interpolation of the labels means that the maximum label is used (taking the average label is not a good idea). Interpolation of depths only takes the average of non-infinite depths, and interpolation of normals and motion vectors only takes the average of vectors different from the null vector. Interpolation is turned on by writing a ``+'' in the beginning of the output type and turned off by writing a ``-'' there. For example, to interpolate the depth samples, write ```+z`'' in the output statement. If interpolation is turned off for a frame buffer, the last sample value (color, normal, motion vector, or label) within each pixel is stored, and pixels without samples get a copy from one of the neighbor pixels. Interpolation off for depth images is an exception: rather than using the last sample depth, the min depth is used -- this can be useful for compositing. Interpolation is on by default for color frame buffers (including alpha and intensity frame buffers) and off by default for depth, normal, motion vector, and label frame buffers.

Next: 1.22 Contours Up: 1. Functionality Previous: 1.20 Color Calculations