Color Calculations

A color in mental ray is typically given in the RGB color space as a triple of R, G, B floating-point values. All internal calculations are performed in this space. In principle, a color is not restricted to the unit cube in RGB space, and physically plausible rendering algorithms may exceed the visible RGB spectrum easily. The standard alpha channel, normally carried in the fourth A component of a color value, is used to determine transparency. Its value is ranging from 0, for fully transparent, to 1 for fully opaque. By convention, mental ray and most shaders exchange colors in pre-multiplied form, which means that the RGB components are scaled by the A component.

All color values computed during the rendering process inside mental ray are passed with full floating-point precision, including shaders. But, when it comes to final storage of color values in frame buffers or image files, the color values may need to be modified and downsized to fit into the limited precision or capacity of the target output. This is the case when storing colors as pixel values of fixed 8-bit or 16-bit precision, sometimes referred to as LDR or low dynamic range colors. Such output requires quantization and clipping of the floating-point values. mental ray offers a number of additional options to enhance the quality of such output, like desaturation, dithering, and gamma encoding, as well as special features like pre-multiplication of colors saved with associated alpha as RGBA, to simplify image compositing.

mental ray supports three different color clip modes that control how pre-multiplied colors are clipped before storing in the frame buffer:

ensures that R, G, and B never exceed A by increasing alpha if necessary while preserving RGB.
makes the same guarantee, but reduces R, G, and B accordingly to preserve the alpha channel.
applies no color clipping whatsoever.

In any of these cases, the result is clipped into the [0...1] range for all non-floating-point frame buffers.

Desaturation may be enabled as an advanced method of color clipping and basic tone mapping. It tries to maintain intensity as much as possible, but shifts the color hue towards the white axis of the RGB color cube. The alpha channel will always be truncated. This mode may be selected with a render option or on the command line of the standalone mental ray.

Dithering is another technique to enhance the visual quality of the final image by reducing quantization artifacts like color banding. It intentionally applies noise to color values in order to spread out the truncation errors, giving the illusion of higher color precision to the human eye. It can be controlled with a render option or on the mental ray command line.

Gamma handling is provided by mental ray to account for non-linear color encoding in input images, like textures, and output images using traditional low-dynamic range image formats. Gamma encoding may be enabled globally that applies to all quantized color pixels (ie. if the output frame buffer is not floating-point or RGBE). In this case, the reverse gamma operation, or gamma decoding, is performed on all low-dynamic range input textures, thus enabling an overall linear color pipeline when using low-dynamic range image files. The default gamma factor is 1.0 which turns global gamma handling off. The use of color profiles allows more selective gamma manipulations per texture or per frame buffer.

For advanced applications and modern workflows, mental ray supports to store floating-point color data, often referred to as HDR or high dynamic range data, directly into frame buffers and capable image file formats like HDR, TIFF, or OpenEXR. In such cases, quantization and clipping is not needed and precision can be preserved. Therefore, color clipping, desaturation, and gamma encoding are not applied to those frame buffers even if enabled. Instead, these operations are left to the post-processing or viewing application.

As a special case, mental ray also supports the RGBE color data format, which is a compressed representation of HDR data that can fit into standard 8-bit image formats but is still preserving the dynamic range of color values. It stores a RGB color as three 8-bit mantissas in the RGB channels, plus a single 8-bit exponent in the alpha channel, taking the place of transparency information. The exponent is shared between the RGB components. This format allows to encode values ranging from 0 to 1038. As a consequence, any of the regular 8-bit color image formats may be used to store RGBE encoded images. This combines the storage efficiency of 8-bit RGB with the ability to store values greater than 1.0. Note, that common image viewers may not be able to decode and display such content.

Color Profiles

mental ray supports color profiles. The following color profiles are predefined:

name description
micsSRGB, micsHDTV sRGB, no gamma correction
micsSRGBg sRGB, with gamma correction
micsHDTVg Rec. 709 (HDTV), with gamma correction
micsNTSC NTSC, no gamma correction
micsSharpRGB A wide gamut color space
micsLineRGB R: 700nm, G: 550nm, B: 432nm
micsBoxRGB R: 575-730nm, G: 500-575nm, B: 380-500nm
micsCIEXYZ CIE XYZ (1931, 2 degree), output only
micsCIELab perceptionally uniform CIE L*a*b*, output only
micsCIELuv perceptionally uniform CIE L*u*v*, output only
micsSpectrum spectral rendering, needs special shaders, rendering only
micsSimpleCMY simple printer output with D50 white point
micsSimpleCMYK simple printer output with D50 white point

Color profiles are enabled by giving a profile in the options block

options "opt"
     colorprofile "profile_name"
end options

The above color profile determines the rendering color space. The use of color profiles implies a floating point color frame buffer. Colors in the frame buffer are stored in an internal color space, that is, the colors of the rendering color space are transformed to internal color space before they are written to the color frame buffer. The CIE color profiles are in general unsuitable for rendering purposes, but they may be used for output purposes. The sRGB and HDTV color spaces differ only in their gamma values. Ideally gamma correction is performed by the viewing device. However, if the output image format has a resolution of less than twelve bits per color channel, then banding artifacts may result. For this reason it may be desirable to perform the gamma correction before the image is written out. Therefore mental ray offers the gamma corrected profiles "micsSRGBg" and "micsHDTVg" as well as the not gamma corrected "micsSRGB" with its alias "micsHDTV".

Color parameters of shaders may also be flagged with a color profile. The application of such a transformation cannot be automated, since which color arguments of a shader should be transformed to render color space depends on the inner workings of the involved shader. As a rule of thumb, color parameters describing material properties should not be transformed, while color parameters describing light properties should be transformed. If a color parameter is not flagged with a color profile, then it is assumed to be given in render color space.

Copyright © 1986, 2013 NVIDIA Corporation