Created
November 10, 2021 03:22
-
-
Save behreajj/8f54231401ca0628279c6b19b369b534 to your computer and use it in GitHub Desktop.
Perceptual Luminance With Conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static float StandardToLinearChannel (in float x) | |
{ | |
return x > 0.04045f ? | |
Mathf.Pow ((x + 0.055f) / 1.055f, 2.4f) : | |
x / 12.92f; | |
} | |
static float LinearToStandardChannel (in float x) | |
{ | |
return x > 0.0031308f ? | |
Mathf.Pow (x, 1.0f / 2.4f) * 1.055f - 0.055f : | |
x * 12.92f; | |
} | |
static Color StandardToLinear (in Color c) | |
{ | |
return new Color ( | |
StandardToLinearChannel (c.r), | |
StandardToLinearChannel (c.g), | |
StandardToLinearChannel (c.b), | |
c.a); | |
} | |
static float GrayLumCorrect (in Color srgb) | |
{ | |
Color lrgb = StandardToLinear (srgb); | |
float lum = 0.21264935f * lrgb.r + 0.71516913f * lrgb.g + 0.07218152f * lrgb.b; | |
return LinearToStandardChannel (lum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment