【TA100】Graphic 2.6 Gamma correction

very good video

https://www.bilibili.com/video/BV15t411Y7cf/?spm_id_from=333.788.b_636f6d6d656e74.96&vd_source=6f3a5e0ac931d869aee3d7c9bb6847e0

1. Gamma correction

1. Preface: Color Space

Insert image description here
● Some examples of color spaces, (please refer to Section 2.1 for details)
● As you can see from the figure, the color gamuts of sRGB and Rec.709 are almost the same, and the positions of the three primary colors are the same, so the difference between them is: transfer function different.

2. Transfer function

● What is a transfer function:
○ After knowing the color value of a color, if you want to display it on an electronic device, you need to convert it into a video signal. The transfer function is used for conversion .

● A transfer function consists of two parts:
○ Optical-to-electrical transfer function (OETF), which converts scene linear light into non-linear video signal values.
○ Electro-optical transfer function (EOTF) converts non-linear video signal values ​​into display brightness.
○ A simple understanding: When taking a photo, the photo is stored in the memory card using video signals. If you want to see the photo, the video signal is converted into a light signal.
Insert image description here

3.Gamma correction

Gamma Correction
Why is gamma correction needed?

Some people believe that it is because the output brightness of early CRT monitors has a non-linear relationship with the input voltage, specifically a relationship of approximately 2.2 powers, resulting in the brightness of the monitor being lower than the brightness stored on the computer.

For example: If the brightness stored in your computer is 0.5 (the brightness range is 0~1), the output brightness of the CRT monitor is not 0.5, but approximately equal to 0.218. The specific calculation process is as follows. When you input 0.5, the output brightness of the monitor
Insert image description here
○ Vout = Vingamma
is The value is
Insert image description here
where the index of 2.2 is the gamma value, and this nonlinear output process of the display is called gamma expansion. In order to obtain the correct output, the input must be compensated by performing a power operation with an exponent of 1/2.2 on the input. This compensation process is gamma correction: after gamma correction, the monitor can display us correctly
Insert image description here
. The input is:
Insert image description here

Since gamma correction originated from the non-linear output problem of early CRT monitors, and now these monitors have basically been eliminated, and today's monitors can already achieve linear output, can we directly abandon gamma correction?
Actually, we still need gamma correction! The reason is: Gamma correction can improve the storage accuracy of dark brightness.

The human eye is more sensitive to darker (closer to 0) brightness values ​​than to brighter (closer to 1) brightness values. We can only use an 8-bit binary (which can express an integer from 0 to 255) to store brightness. value, we want to preserve as much dark detail as possible throughout the image.

Examples are given below:

Suppose we want to store two brightness values ​​​​of 0.240 and 0.243. If no gamma correction is performed, the stored values ​​​​of the picture brightness are: The stored values ​​​​of 0.240
Insert image description here
and 0.243 become 133 and 134, and their actual display effects are different. Of course, gamma correction will bring about a reduction in the representation accuracy of larger brightness values. Examples are as follows:
Without gamma correction:
Insert image description here
With gamma correction:
Insert image description hereIt can be seen that the brightness values ​​that can be distinguished without gamma correction, when the gamma correction is reached, After the horse was corrected, it became impossible to separate.
However, the human eye happens to be more sensitive to darker values ​​and less sensitive to brighter values, so the loss of bright details will not have any impact, while the retention of dark details will greatly improve the image quality. This is what gamma correction has done so far. Reasons for still using it.

○ Gamma refers to the operation of encoding and decoding between linear trichromatic values ​​and nonlinear video signals.
Insert image description here·Understanding of encoding and decoding: ○ For example:
■ The photos taken are stored in the computer, which encodes the light signals in nature into video signals. ■
When viewing the photos, the video signals must be restored to linear light signals and decoded. operate

○ As shown in the figure: linear space (real-world light signal captured by the camera) + gamma encoding + monitor display = result

·Use a picture as an example:
○ gamma encoding:
■ The picture on the left shows the captured physics stored in the hard disk The data is mapped once with a gamma value of about 0.4. This process is called gamma encoding.
■ As you can see from the picture, the image is brighter than the actual physical pixels at this time (the picture is not necessarily the actual situation, but just an intuitive representation of the increased brightness) Represents)
○ Gamma correction:
■ When the middle image is displayed, a correction with a gamma value of approximately 2.2 is required for each pixel to make the final result a correct physical data.
○ You can see that after gamma correction, the brightness of the previously bright image has been reduced.

·Why not store it in a linear way, but convert it back and forth?
● ①Related to the characteristics of the human eye
○The human eye is more sensitive to changes in dark areas
●②Nonlinear conversion in order to optimize storage space and bandwidth
○The image data we use to display is all 8bit. To make full use of the bandwidth, we need to use more Location to store shadow values. That is, the dark parts are saved with high precision, and the bright parts are saved with relatively low precision.

2. Weber’s theorem (a reason for using gamma correction)

1. Artistic uniformity and physical uniformity

Insert image description here
● As mentioned above, our human eyes are more sensitive to dark parts
○ The upper part is a uniform change in vision, while the lower part is a uniform change in physical quantity.
● Supplement: Theoretically, the upper medium gray is 21.8% of the physical quantity (lower). The visual medium gray in art is about 20% of the physical gray.

2.gamma encoding curve

● Gamma encoding curve:
○ Mapping the uniform gray scale felt by people and the linearly increasing brightness in nature is the gamma encoding curve ● As
can be seen from the figure
○ A brightness of about 0.2 of the brightness in nature corresponds to Medium gray perceived by human eyes (0.5)
○ It can be seen that the change rate of dark parts is higher, which means that the human eye is more sensitive to changes in dark parts.
Insert image description here

3. Weber’s law

Insert image description here
● In human terms:
○ When the stimulation received is greater, the stimulation needs to be increased enough to make people feel obvious changes, but it is only suitable for medium-intensity stimulation.

3. CRT nonlinear response (another reason for using gamma correction)

1.CRT and conversion function

● CRT (cathode ray picture tube)
○ The brightness of this device does not have a linear relationship with the voltage, but has a power-law-like relationship with the gamma value of about 2.2
○ Due to the physical characteristics of the CRT, the brightness can just be darkened, that is to say , when the picture on the left becomes brighter, the display on the right is corrected by lowering the brightness, and the result is just right enough to display normally.
■ It is worth noting that the premise mentioned above is that under the same conditions (in different light and dark environments, the results seen may be different), the mid-gray value we take does not refer to a specific value.

2. Medium gray value

● The so-called neutral gray value is not a specific value, but the specific feeling of the human eye
● An example can prove
○ For the first picture, you can clearly see that the colors of AB are different
Insert image description here

对于下面这张图,只是把AB连起来,就可以看到,其实是一种颜色(影子让周围更暗了)
//ps:如果你不信的话,可以用Snipaste取一下图1的A、B两种颜色,你就会发现,真的是一个颜色
Insert image description here

四、线性工作流

1.课程中内容
● 对于技术美术来说,知道上边所说的还不够,因为很多时候我们会接触到一些图形效果的制作和修改。
● 这时候就需要一个正确的工作流程。
Insert image description here
● 线性工作流:
○ 在各个环节正确的使用gamma编码/解码,来达到最终输出的数据和最初输入的物理数据一致的目的。
○ 如果使用Gamma空间的贴图,在传给着色器之前需要从Gamma空间转到线性空间。
■ 目的是在着色器中做一些渲染计算时会使用线性空间的颜色值,这样就不会出现一些显示错误的结果。
● 如果不在线性空间下进行渲染工作,可能会产生的问题:

○ ①亮度叠加时
■ 可以看到非线性空间下亮度叠加出现了过曝(亮度>1的)的情况
■ 因为Gamma空间经过gamma编码后的亮度值相对之前会变大。
Insert image description here
○ ②颜色混合时
■ 如果在混合前没有非线性的颜色进行转换,就会在纯色的边界出现一些黑边。
Insert image description here

○ ③光照计算时
■ 在光照渲染结算时,如果我们把非线性空间下(视觉上的)的棕灰色0.5当做实际物理光强为0.5来计算时,就会出现左边这种情况
■ 在显示空间下是0.5,但在渲染空间下它的实际物理光强为0.18(如右图)
Insert image description here

Insert image description here

五、Unity中颜色空间

1. Select the color space in Unity
● Click the menu->Project Settings->Player tab->Rendering section under Other Settings, you can select Gamma/Linear (linear) by modifying the Color Space
Insert image description here

● When Gamma Space is selected
○ Unity will not perform any operation (default Gamma)
● When Linear Space is selected
○ The engine’s rendering process is calculated in linear space. Ideally, the project uses the texture color of linear space, and there is no need to check sRGB;
● Check sRGB?
○ If the sRGB texture is checked, Unity will perform linear conversion when sampling through hardware characteristics.

2.Hardware support

● Currently the following platforms can support hardware in linear space
○ Windows, Mac OSx, Linux (Standalone)
○ Xbox One
○ PS4
○ Android (OpenGL ES3.0)
○ IOS (Metal)
○ WebGL
● Unity mainly uses the following two hardware Features to support
○ sRGB Frame Buffer
■ Perform Gamma correction before outputting the Shader calculation results to the display
■ When being read as a texture, the stored color will be automatically converted from sRBG space to linear space
■ When calling ReadPixels(), ReadBackImage() , will directly return the color in the sRGB space.
■ sRBG Frame Buffer only supports the format of 8 bits per channel, and does not support the float floating point format. ■
After HDR is turned on, the rendering results will be first put into the FB in the floating point format, and finally drawn to sRGB. Output on FB.
○ sRGB Sampler
■ Convert sRBG textures to linear sampling
● Use hardware features to complete linear sampling of sRGB textures and gamma correction of shader calculation results, which is faster than correcting texture sampling and calculation results in the shader.

6. Resource export issues/precautions

1.SubstancePainter
○ When the SubstancePainter map is exported, its linear color value is gamma encoded, so the color is brightened.
○ At this time, this texture needs to check the sRBG option in Unity so that it can be restored to a linear value when it is sampled.
Insert image description here
2.PS
● When exporting images from PS, if you set the gamma coefficient to one, you do not need to check the sRBG option in Unity; ●
If you do not set anything in PS, check the sRGB option in Unity That’s it.
Insert image description here
● Document Color Profile
○ PS is very precise in its color management. The colors we see in Unity need to undergo the gamma transformation of the monitor, but not in PS. PS will read the Color Profile of the monitor and reversely compensate it.
■ (In other words, what is in ps is the real color value).
○ PS itself has a system that controls the display of colors through grayscale values ​​(usually this value is consistent with the gamma value of the monitor, so it will look the same as the effect seen in Unity). You can change the grayscale value to change the final color display.
● Translucent effect
○ In Unity:
■ When Unity performs semi-transparent mixing, it will first convert them into a linear space and then mix them
○ In PS:
■ When mixing between PS layers, each upper layer The layers will read their Color Profile (gamma value), and then undergo a gamma transformation before blending. The result will be darker.
■ (You can change it in the settings of its workspace, choose to use gamma to mix RGB colors, and set the parameter to one, so that the layer is the final direct mixing result)
Insert image description here
● If you do a non-linear mapping (that is, gamma correction), raise the middle gray in the art grayscale to the middle, so that both bright and dark parts can be assigned to 128 samples. What is saved in this way is a comfortable/normal result for human eyes.
②Understanding of Gamma correction function
● It is a power function, y=xgamma
● It will always pass through (1,1) and (0,0), corresponding to white and black
● For the value of gamma
○ If gamma=1, the function That is, y=x, input value = output value, that is, no correction is performed
○ If gamma>1, the function image is suppressed, and the input value will be suppressed.

linear space Please add image description
gammar space
Please add image description

Guess you like

Origin blog.csdn.net/weixin_45810196/article/details/131105988