• Welcome to SC4 Devotion Forum Archives.

Gamma Correction for Render Output

Started by SimFox, February 11, 2009, 01:28:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SimFox

It is commonly assumed that gamma correction/color mapping is only required to bring extremely bright light sources (like photometric Suns and Skys) to "normal" levels, to, sort of, dim them down. But those controls do much more than dimming. For various reasons practically all display units in use today do not show gradation of brightness in a linear fashion. Instead they have sort of a hole/dip in the midrange. To compensate for such a dip virtually all image standards (JPG, BMP, MPEG etc) include various methods to expand this midrange (brightness wise) to restore the linear appearance.  But here is a trick – standards include assumption of such a compensation and not automatic application of it. What this means is that data in image file is assumed to be non-linear. It is assumed that such a correction was applied at the source – be it Camera, or scanner.  And it is almost always that case, almost... One notable exception is a render output in many 3d software (especially older versions of it). The output data is normally linear. As a result it will be displayed in "un-natural" way. One reason for allowing such a situation is that render output is assumed to be an intermediate rather than final "product". Additional processing in image editing software is expected. Sometimes even this may not be necessary – particularly in case of studio style object renderings where lights are placed to achieve exact lighting solution that may have nothing to do with "natural" look, which isn't an objective at all. In other cases some "shortcut" solutions are devised. One of such "shortcuts" is a default lighting rig of the BAT. It compensates for otherwise totally black shadows (in part due to absence of bounced light and in part for the linear nature of render) by having special lights that set not to generate shadows and as such be all penetrating.



Of course default rig is ancient (in 3d terms) technology that has tons of short comings and limitations and results it produces are very bad unless you building is a simple box. But as CPU power and software develops it was natural to move to more natural Sun+Sky solutions. However here is a catch. This move wasn't always coupled with introduction of Gamma correction. As a result output of such rigs although vastly improved over old one, continues to have one serious weakness. Shadows tend to be very intense and unnaturally fall off into almost complete blackness in the narrower recesses, or otherwise shaded from both sun and sky, spots.

Applying gamma correction to the render output would restore natural look (as eye would see it in the real life situation) by artificially skewing limited dynamic range of final image (of course in case that this is final 8 bit per color channel one) to fool our perception.

Here is our "Tester" with Sun+Sky Rig with no Gamma Correction (brightness of either light source had been reduced to 0.018 to compensate.



I think you would agree that these shadows don't look natural by a long shot.

Now if I would take this image into Photoshop and adjust it's gamma by 2.2 we'll have this:



Definitely much more natural looking result. Precise value may range between 1.6 and 2.5 but the principle is illustrated... It also pushes any non-white parts brighter but the resulting shift is smaller in the brightest parts. Final result could be controlled through various settings, I'll show some later on.

Picture above had is a result of very crude manipulation in Photoshop. Crude, because those were performed on already 24bit (low dynamic color depth) images. Be they made on proper High Dynamic range images like those that Max ALWAYS generate during the render it would look much more balanced.

Luckily for us modern 3d packages have various tools that such a manipulation on results right during the render. Here I'll consider few options available to 3ds Max users.


1. Gamma correction in Preferences.


Customize -> Preferences -> Gamma and LUT



This is the easiest and, naturally, worst way to introduce gamma correction to render output. It doesn't allow for extreme brightness of the Sun and Sky (although those could be set to reduced brightness), has no fine tuning options and is not compatible with BATs prior to v2.5 In all fairness I wouldn't consider it to be an option at all, but since it is there I thought to mention it, especially because it could be a very useful tool in conjunction with other methods.

Here is our "tester" rendered in such a setup



Strength:
affects material editor and hence allows for quite accurate preview of colors and textures.

Weakness:
blunt, no precise control/tweaking, not compatible with BAT versions earlier then 2,5


2. Logarithmic Exposure Control.


Rendering -> Environment -> Exposure Control Parameters



This tool allows for the more precise control over the look of the render output, available in practically all versions of MAX and compatible with both Scanline and Mental Ray.

Unlike enabling Gamma in Preferences Logarithmic exposure control gives user to adjust  some very handy settings – brightness, contrast, color balance and, very importantly, to adjust for extremely bright natural light of photometric sun and sky. However those controls are somewhat limited.
Here is a result with Logarithmic Exposure control:



Strength:
extremely flexible color correction option.

Weakness:
Doesn't work – doesn't cooperate, to be precise,  with gamma settings in Preferences and so doesn't allow for accurate preview of either color or textures in material editor without great difficulty.  Limited controls over highlights and shadows (only general contrast and brightness controls). Numbers appear to be absolutely arbitrary. Actual Gamma correction is unknown, but appears to be somewhere around 2.2 and not changeable.


3. Mr Photographic Exposure Control.


Rendering -> Environment -> Exposure Control Parameters (3ds Max versions 2008 +)



Most flexible and evolved gamma correction tool available in Max to date. It was a ripe time when Metal Ray would take control over such a crucial step in the process in its own hands. Result is one of the best Gamma corrector/Color Mapper out there. It is highly recommended to use this option if it is available in your Max version. It offers greatest number (as compared with previous choices) of settings that could be used to fine-tune the outcome. Cooperates well with Gamma settings in Preferences.



Strength:
Very tunable, has separate controls for highlights, mid range and shadows. Control for saturation. Numbers are linked to the settings of the SLR cameras and should be as such intuitively familiar to those who had used them. Fully compatible with Preferences Gamma settings and hence allow for accurate preview of color and textures in Material editor. Actual gamma correction is 2.2 but is linked to the Preference settings and could be over-written from there to any value.

Weakness:
White balance option is somewhat limited only allowing for Kelvin temperature adjustment without of hue shift (too bad as any decent dSLR has hue shift option and here it would be extremely easy to realize. In fact this is an option in MR itself, but wasn't given UI controls in Max. When used in conjunction with Preferences Gamma requires BAT4Max v2,5 or greater to work.