[SOLVED] UnityCG.cginc Luminance values

Hello everyone,
I need to calculate the luminance of a cubemap. Now I am a bit confused about the included Luminance function in UnityCG.cginc: Unity - Manual: Built-in shader helper functions. I can’t find any reference why the RGB values in gamma or linear space are chosen like they are.

#ifdef UNITY_COLORSPACE_GAMMA
#define unity_ColorSpaceLuminance half4(0.22, 0.707, 0.071, 0.0)
#else // Linear values
#define unity_ColorSpaceLuminance half4(0.0396819152, 0.458021790, 0.00609653955, 1.0)
#endif

The only function I know a reference for is the LinearRgbToLuminance one, it is the ITU-R Recommendation 709. But this function is not even mentioned on the manual page for UnityCG.cginc.

// Converts color to luminance (grayscale)
inline half Luminance(half3 rgb)
{
    return dot(rgb, unity_ColorSpaceLuminance.rgb);
}

// Convert rgb to luminance
// with rgb in linear space with sRGB primaries and D65 white point
half LinearRgbToLuminance(half3 linearRgb)
{
    return dot(linearRgb, half3(0.2126729f,  0.7151522f, 0.0721750f));
}

Could someone help me get clarity on this? I am currently working on my thesis with Unity, so I would like to reference an official source why the luminance calculation is done this way and not differently.

It’s a color to grayscale conversion using some common values that give a decently natural look to our eyes. You can see in the Grayscale Conversion section of this Nvidia GPUGems page where they go over it and explain it some more:
https://developer.nvidia.com/sites/all/modules/custom/gpugems/books/GPUGems/gpugems_ch22.html

The Linear space value is simply this gamma space values mentioned above, passed through Unity’s “GammeToLinearSpace” function in the UnityCG.cginc file (using the commented out “Precise version” inside it, which it references this page for the formula:

1 Like

Ah yes, that was the piece of information I was missing. Thank you very much!