📜 ⬆️ ⬇️

Gamma, ColorMapping and LinearWorkflow

Overview and practical application of Gamma and Color Mapping in a combination of 3D max, V-ray and Nuke.

image

Part one. Gamma. Start


This story began with the fact that the imperfect technology of displaying the video signal with a ray tube suffered from severe blackouts and the matter is not at all in the cookies. It was impossible to compensate this deficiency programmatically, and the hardware is very expensive and therefore decided to make adjustments to the video itself at the stage of content production. Years passed, the mountains turned out to be exclusively gamma-corrected images, and when the era of computers came, no one began to transfer the industry to new standards, but adopted the existing ones. Since then, the computer and we see the image in different ways. If everything is “ok” for us, then for the company the picture looks much brighter, just before showing us the image the signal goes through the “natural” reverse gamma correction on the monitor side. Modern monitors can display a picture linearly, but we are haunted by the “legacy of the old time” in the form of a heap of bright films and TV shows.

All-nothing, but for some reason, computer graphics was built on mathematical principles and all color manipulations converge on banal arithmetic operations. And imagine now that you need to increase the average gray color in two. In the linear space “medium gray” is equal to 0.5 * the total is 0.5x2 = 1.0, that is, you get pure white color, which is quite logical, and not in the linear space “medium gray” is equal to 0.72 somewhere, multiplied by 2 and it turns out ... nonsense it turns out guys.
')
So Rendering is a bunch of different arithmetic perverts and all sorts of multiplayer, overlayers and colorburns are a little different than what is required of them if the color space is not linear. Therefore, those who have eyes able to distinguish blue from blue decided to work in the “ruler” in order not to create problems for themselves at all stages of image processing.

Rule: We bring the input material into linear space. We work in linear space. Gamma correction is applied only to the final picture (and in most cases this happens automatically).

An example of a gamma translation is in the description for Blender:



By the way, it’s not worthwhile to bring Normal Bump into linear space, since such maps are already in the “ruler”, when connecting such textures, you should exclude them from the correction.

Part two. Color mapping


In addition to the complexity of the scale, we have a technological problem, which rests on the possibility of display. We have 2 main ways to display images - on paper and on the screen. Both methods differ fundamentally by the fact that one reflects light, and the second emits, but both of them have a very limited transmission range of the light intensity, in comparison with the one we can see, therefore the image must be “compressed” to the desired range. Moreover, it is not enough just to squeeze the brightness, it should be done so that in places of weak sensitivity to compress a lot, and where we have a lot of sensitivity to compress it is necessary ... well, you understand. This is done because of the peculiarities of our perception. Now I am going to be a little more detailed.

Our feelings lie to us.

We perceive the world around us not linearly. To enhance the feeling of something 2 times, it’s not enough for us to double the serving ... we need to triple or quadruple it, that is, if we twist the brightness of the light source by 2 times, we feel that we’ve said that the brightness has increased by 30% ... we are such “clear guys” . All sense organs work in a logarithmic proportion. The reverse natural logarithm is called the Exponent ... which looms in the Color Mapping settings. Logarithm is the main function when converting intensity, regardless of whether it is an image, a portion of salt or the joy of the amount of money in the bank.

For this reason, we are well aware of halftones in dark areas and are more indifferent to differences in bright ones. That is why during compression we neglect high color values.
Imagine that in the visible world, the difference in brightness can go far beyond a million, and the monitor is able to show a difference of about 10,000. ColorMapping “squeezes” a wide range of brightness into that small area that a monitor or picture printed on a sheet of paper can display. it is instead of our eyes, and the brain interprets the image as a finished image. Pay attention to the Binary Logarithm graph, it becomes clear from it - mainly the light areas are compressed while the “shadows” remain unchanged, so we get rid of the unpleasant “glares” that run the work of novice visualizers.
Logarithm and gamma are almost the same, but they have particular differences in construction: for gamma you need to have two extreme points - zero and one corresponding to black and white, between these points a curve is constructed with a bending force equal to gamma. But for the exponent, one starting point is enough and the curve can be built to infinity. Therefore, in the linear space with a high dynamic range (HDR) color, where there is no limit to the brightness of the applied exponent, and already in the ready-used gamma. There are, of course, programs where gamma can be applied to an HDR image, but such a perversion can lead to unpredictable values ​​initially standing above one.

ColorMapping and gamma correction are two similar things, but deals with different tasks. Gamma is designed to compensate for the “old legacy”, while ColorMapping compresses the “ruler”.

That is, in the work we take into account two separate color conversions and do not confuse them with each other.

Part Three Practical work


There are two main ways of making pictures. One path leads immediately to the finished file: with a gamut clipped by HDR, with a minimal number of bits per channel, with all that implies the absence of serious edits. The second is preparing a “raw cake mix” which wakes up “cooked” until ready in the post-processing program. If we are preparing a file for the post, we need to keep the linear space + high dynamic range of colors. We will consider in practice both methods.

Path number 2. Longer - then skillfully!

In the latest version of 3D Max, Input and Output were removed from the Gamma settings, so the total gamma value should be set to 2.2. 3D Max itself will bring incoming textures into linear space.

The settings for ColorMapping in 3D Max are as follows:
Type - Linear multiply. - We work in the line
Dark - 1.
Bright - 1. - these values ​​will remain the default if necessary, we will change them in the post.
Gamma - 2.2. - The fact is that this scale will not be applied to the final image and in fact will remain - 1 ... because we will set a tick in:
Don't affect colors - check the box. We do this in order to stay in linear space, but knowing that Vraevsky Sampler does not always report in dark places, we apply the gamut only to him. Thus, in the dark areas we will not lose the details and we will remain in the "line"
Clamp - Disable, because we need the whole range of brightness.

Save such images in Float point formats (32 bits), such as openEXR. Now, at the output, we will have a relatively accurate model of color representation, almost like in reality.

Cooking cake mix in Nuke

I admit, I like the post with my creative flexibility. When all the basic, rough work is done and it remains to “twist” the buttons for taste.
Omit the details specific to specific projects and go straight to ColorMapping for Nuke.
So we have a “linear” picture with scorched light areas. Recalling my story about the features of perception, we will repeat a similar focus. And the mechanics of the work will be similar to the type of Reinhard in ColorMapping V-ray.
We need 2 nodes: Grade and Log2Lin.
Grade will play the role of the multiplier of the entire image or the ISO value of the camera if you prefer.

Log2Lin will compress the image, but first you need to configure it:
Operation - lin2log.
Black - 0
White - 255
Gamma - 1
Mix - 0.95

“Squeezing” the brightness, we make the image darker, so you can immediately set the Gain value to 5 in the settings of the Grade node. The two Log2Lin nodes will perform the same function that the Burn value in ColorMapping 3D Max is just the other way, that is, if the Burn value is 0.3, then Mix will set about 0.7

Path number 1. Without dancing.

If you avoid Post, then you can do all color conversions in ColorMapping, but for this purpose it is necessary to do test renders. Select the type of transformation - Rinhard, since it is averaging between the ruler and the exponent through the parameter Burn value. If you have "burned" colors, then it is enough to lower the Burn value.

Gamma - 1
Clamp - 1
Don't affect colors - uncheck.

Since now the Sampler will scatter samples based on the visible image, it is necessary to lower the noise threshold in the DMC Sampler from 0.01 for the “ruler” to about 0.003.

Some guys, instead of lowering the noise level, simply increase the gamma by 2.2, and in the Gamma settings of the program, set the unit to the Output field. I think this is ideologically incorrect, although it also works.

_______________________________________________________________________________
* Hereinafter we are talking about the color values ​​in Float Point where 0 = black, and 1 = white.

Source: https://habr.com/ru/post/227857/


All Articles