©Anton Podvalny

Table of Contents

Introduction


"Gamma correction" is actually a data compression technique that relies on the non-linearity of our human visual system. It uses the limited number of bits to encode more dark levels where we are more sensitive to intensity changes while bright levels are more sparse. This is why floating point output formats don't need it as FP numbers are exponentially encoded by definition.

In order for V-Ray to perform mathematically correct calculations, input and output color data should be linear. The results should only be converted to a non-linear color space (such as sRGB) for display. This is called linear workflow.

By default the VFB (V-Ray Frame Buffer) has its sRGB option enabled, so you will see the original linear image with sRGB applied as a post-process. The files you save from the VFB or with VRayRenderer::VFB::saveImage() will be linear like the actual data if saved in a floating point format such as EXR or VRIMG. On the other hand, most 8/16-bit integer formats implicitly save their data gamma-encoded (e.g. JPEG applies ~2.2 gamma for color encoding. Applications that read JPEG handle that and display the data in the required color space, gamma-encoded or decoded linear). Saving to such integer file formats with saveImage() or from the VFB button also bakes any color corrections done in the VFB, including the sRGB conversion. So these files will look exactly like you see them in the VFB. This does not apply to EXR and VRIMG.

There is a good article on linear workflow (LWF) on CGArena.

Parameters


The plugin that controls color mapping is called SettingsColorMapping. It has the following parameters:

  • type - Type of color mapping. One of the following:

    • 0 - Linear
    • 1 - Exponential
    • 2 - HSV Exponential
    • 3 - Intensity exponential
    • 4 - Gamma correction
    • 5 - Intensity gamma correction
    • 6 - Reinhard
  • affect_background - True if color mapping should affect the background.

  • dark_mult - Specifies the multiplier applied to dark colors when type is set to Linear multiply, Exponential, HSV exponential, or Intensity exponential. The default value is 1.0.
  • bright_mult - Specifies the multiplier applied to bright colors when type is set to Linear multiply, Exponential, HSV exponential, or Intensity exponential. The default value is 1.0.
  • gamma - Controls the gamma correction for the output image regardless of the color mapping mode. For example, to correct the image for a 2.2-gamma display, set this parameter to 2.2.
  • subpixel_mapping - Controls whether color mapping will be applied to the final image pixels or to the individual sub-pixel samples. In older versions of V-Ray, this option was always assumed to be enabled. However it is disabled by default in newer versions as this produces more correct renderings.
  • clamp_output - When enabled, colors will be clamped after color mapping. This will make the result physically inaccurate due to loss of energy. In some situations this may be undesirable. For example, if you wish to antialias HDR parts of the image as well, turn clamping off.
  • clamp_level - The level at which colors will be clamped if clamping is on.
  • adaptation_only - Specifies whether color mapping and gamma are applied to the image:

    • 0 - both color mapping and gamma are applied - Both color mapping and gamma are burned into the final image.
    • 1 - nothing is applied - Neither color mapping nor gamma are burned into the final image. However, V-Ray will proceed with all its calculations as though color mapping and gamma are applied (e.g. the noise levels will be corrected accordingly). This can be useful, for example, if you know that you will apply some color correction to the image later on, but wish to keep the rendering itself in linear space for compositing purposes.
    • 2 - only color mapping is applied - Only color mapping is burned into the final image and not gamma correction. This is the recommended option. V-Ray will still proceed to sample the image as though both color mapping and gamma are applied, but will only apply the color correction (Linear, Reinhard, etc.) to the final result.
  • linearWorkflow - This option is deprecated and should not be set in new scenes. It is intended to be used only for quickly converting old scenes which are not set up with proper linear workflow in mind. This option is not a replacement for a proper linear workflow - see below. When this is enabled, V-Ray will automatically apply the inverse of the Gamma correction that is set in the gamma parameter to all BRDFVRayMtl materials in your scene.

  • exposure - Additional image exposure as color. Different values can be applied to each color channel.
The Clamp output option, when enabled, will have an effect regardless of the value of the Adaptation only option.

Recommended settings


The proper workflow for texture file assets is to control color mapping via BitmapBuffer or RawBitmapBuffer. They have a few parameters for converting the image file colors - transfer_function, rgb_color_space, gamma.

The most important one is transfer_function (also aliased as color_space for backward compatibility). It supports the following values:

  • 0 - linear
  • 1 - gamma corrected (the default)
  • 2 - sRGB
  • 3 - auto

Most integer formats (bmp, png, jpeg, tiff) will require setting transfer_function=2.

The gamma parameter is used only when transfer_function=1. Setting both transfer_function=1 and gamma=0.4545 will give similar (but not identical) result to setting transfer_function=2.

rgb_color_space is а string parameter signifying the linear RGB color space of the texture. Possible values are:

  • "raw" (default, no conversion)
  • "lin_srgb" for sRGB
  • "acescg" for ACEScg

If the OCIO environment variable is set or if the SettingsUnitsInfo::ocio_config_file parameter is set, the value can be any color space available in the OCIO config. This conversion is applied after the transfer function. The parameter transfer_function must be set, or else texture filtering will NOT work correctly.

The parameter linearWorkflow is intended only for compatibility with old vrscene files and should not be set to 1, despite its misleading name.

These settings are also set by the VRayRenderer.setImprovedDefaultSettings() method (along with others):

SettingsColorMapping.type=6             // 6=Reinhard mapping (plugin default is 0=linear)
SettingsColorMapping.gamma=2.2          // close to sRGB (plugin default is 1.0); 2.2 will improve sampling of dark areas even if adaptation_only != 0
SettingsColorMapping.adaptation_only=2  // 2=only apply color mapping (plugin default is 0=apply both color mapping and gamma)
SettingsColorMapping.linearWorkflow=0   // NOTE: this option exists only for legacy scenes

Examples


Color Mapping Types

This example demonstrates the differences between some of the color mapping types.

The Sibenik Cathedral model was created by Marko Dabrovic (http://www.rna.hr) and was one of the models for the CGTechniques Radiosity competition.

As visible in the above images, the Linear multiply mapping method clamps bright colors to white, causing bright parts of the image to appear "burnt out". Both the Exponential and HSV exponential types avoid this problem. While Exponential tends to wash out the colors and desaturate them, HSV exponential preserves the color hue and saturation.

 

  • No labels
Was this helpful?