iOS Metal. Why does simply changing colorPixelFormat result in brighter imagery?

人盡茶涼 提交于 2019-12-24 00:48:43

问题


In Metal on iOS the default colorPixelFormat is bgra8Unorm. When I change format to rgba16Float all imagery brightens. Why?

An example:

Artwork

MTKView with format bgra8Unorm. Texture-mapped quad. Texture created with SRGB=false.

MTKView with format rgba16Float. Texture-mapped quad. Texture created with SRGB=false.

Why is everything brighter with rgba16Float. My understanding is that SRGB=false implies that no gamma correction is done when importing artwork. The assumption is the artwork has no gamma applied.

What is going on here?


回答1:


If your artwork has a gamma (it does per the first image you uploaded), you have to convert it to a linear gamma if you want to use it in a linear space.

What is happening here is you are displaying gamma encoded values of the image in a linear workspace, without using color management or transform to convert those values.

BUT: Reading some of your comments, is the texture not an image but an .svg?? Did you convert your color values to linear space?

Here's the thing: RGB values are meaningless numbers unless you define how those RGB values relate to a given space.

#00FF00 in sRGB is a different color than #00FF00 in Adobe98 for instance. In your case you are going linear, but what primaries? Still using sRGB primaries? P3 Primaries? I'm not seeing a real hue shift, so I assume you are using sRGB primaries and a linear transfer curve for the second example.

THAT SAID, an RGB value of the top middle kid's green shirt is #8DB54F, normalized to 0-1, that's 0.553 0.710 0.310 .These numbers by themselves don't know if they are gamma encoded or not.

THE RELATIONSHIP BETWEEN sRGB, Y, and Light:

For the purposes of this discussion, we will assume the SIMPLE sRGB gamma of 1/2.2 and not the piecewise version. Same for L*

In sRGB, #8DB54F when displayed on an sRGB monitor with a sRGB gamma curve, the luminance (Y) is 39

This can be found by

(0.553^2.2)*0.2126 + (0.710^2.2)*0.7152 + (0.310^2.2)*0.0722

or 0.057 + 0.33 + 0.0061 = 0.39 and 0.39 * 100 = 39 (Y)

But if color management is told the values are linear, then the gamma correction is discarded, and (more or less):

0.553*0.2126 + 0.710*0.7152 + 0.310*0.0722

or 0.1175 + 0.5078 + 0.0223 = 0.65 and 0.65 * 100 = 65 (Y)

(Assuming the same coefficients are used.)

Luminance (Y) is linear, like light. But human perception is not, and neither are sRGB values.

Y is the linear luminance from CIEXYZ, while it is spectrally weighted based on the eye's response to different wavelengths, it is NOT uniform in terms of lightness. On a scale of 0-100, 18.4 is perceived as the middle.

L* is a perceptual lightness from CIELAB (L* a* b*), it is (simplified curve of):

L* = Y^0.42 On a scale of 0-100, L* 50 is the "perceived middle" value. So that green shirt at Y 39 is L* 69 when interpreted and displayed as sRGB, and the Y 65 is about L* 84 (those numbers are based on the math, here are the values per the color picker on my MacBook):

sRGB is a gamma encoded signal, done to make the best use of the limited bit depth of 8bits per channel. The effective gamma curve is similar to human perception so that more bits are used to define darker areas as human perception is more sensitive to luminance changes in dark regions. As noted above it is a simplified curve of:

sRGB_Video = Linear_Video^0.455 (And to be noted, the MONITOR adds an exponent of about 1.1)

So if 0% is black and 100% is white, then middle gray, the point most humans will say is in between 0% and 100% is:

Y 18.4%. = L* 50% = sRGB 46.7%

That is, an sRGB hex value of #777777 will display a luminance of 18.4 Y, and is equivalent to a perceived lightness of 50 L*. Middle Grey.

BUT WAIT, THERE'S MORE

So what is happening, you are telling MTKView that you are sending it image data that references linear values. But you are actually sending it sRGB values which are lighter due to the applied gamma correction. And then color management is taking what it thinks are linear values, and transforming them to the needed values for the output display.

Color management needs to know what the values mean, what colorspace they relate to. When you set SRGB=false then you are telling it that you are sending it linear values, not gamma encoded values.

BUT you are clearly sending gamma encoded values into a linear space without transforming/decoding the values to linear. Linearization won't happen unless you implicitly do so.

SOLUTION

Linearize the image data OR set the flag SRGB=true

Please let me know if you have further questions. But also, you may wish to see the Poynton Gamma FAQ or also the Color FAQ for clarification.

Also, for your grey: A linear value of 0.216 is equivalent to an sRGB (0-1) value of 0.500



来源:https://stackoverflow.com/questions/54256198/ios-metal-why-does-simply-changing-colorpixelformat-result-in-brighter-imagery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!