Merge pull request #7625 from aws-lumberyard-dev/cgalvan/AddSupportForUNORM_SRGB

Added support for several UNORM_SRGB formats
This commit is contained in:
Chris Galvan
2022-02-16 09:18:34 -06:00
committed by GitHub
12 changed files with 77 additions and 152 deletions
@@ -134,6 +134,12 @@ namespace AZ
//! Color from u32 => 0xAABBGGRR, RGB convert from Gamma corrected to Linear values.
void FromU32GammaToLinear(u32 c);
//! Convert SRGB gamma space to linear space
static float ConvertSrgbGammaToLinear(float x);
//! Convert SRGB linear space to gamma space
static float ConvertSrgbLinearToGamma(float x);
//! Convert color from linear to gamma corrected space.
Color LinearToGamma() const;
+15 -6
View File
@@ -370,6 +370,15 @@ namespace AZ
*this = GammaToLinear();
}
AZ_MATH_INLINE float Color::ConvertSrgbGammaToLinear(float x)
{
return x <= 0.04045 ? (x / 12.92f) : static_cast<float>(pow((static_cast<double>(x) + 0.055) / 1.055, 2.4));
}
AZ_MATH_INLINE float Color::ConvertSrgbLinearToGamma(float x)
{
return x <= 0.0031308 ? 12.92f * x : static_cast<float>(1.055 * pow(static_cast<double>(x), 1.0 / 2.4) - 0.055);
}
AZ_MATH_INLINE Color Color::LinearToGamma() const
{
@@ -377,9 +386,9 @@ namespace AZ
float g = GetG();
float b = GetB();
r = (r <= 0.0031308 ? 12.92f * r : static_cast<float>(1.055 * pow(static_cast<double>(r), 1.0 / 2.4) - 0.055));
g = (g <= 0.0031308 ? 12.92f * g : static_cast<float>(1.055 * pow(static_cast<double>(g), 1.0 / 2.4) - 0.055));
b = (b <= 0.0031308 ? 12.92f * b : static_cast<float>(1.055 * pow(static_cast<double>(b), 1.0 / 2.4) - 0.055));
r = ConvertSrgbLinearToGamma(r);
g = ConvertSrgbLinearToGamma(g);
b = ConvertSrgbLinearToGamma(b);
return Color(r,g,b,GetA());
}
@@ -391,9 +400,9 @@ namespace AZ
float g = GetG();
float b = GetB();
return Color(r <= 0.04045 ? (r / 12.92f) : static_cast<float>(pow((static_cast<double>(r) + 0.055) / 1.055, 2.4)),
g <= 0.04045 ? (g / 12.92f) : static_cast<float>(pow((static_cast<double>(g) + 0.055) / 1.055, 2.4)),
b <= 0.04045 ? (b / 12.92f) : static_cast<float>(pow((static_cast<double>(b) + 0.055) / 1.055, 2.4)), GetA());
return Color(ConvertSrgbGammaToLinear(r),
ConvertSrgbGammaToLinear(g),
ConvertSrgbGammaToLinear(b), GetA());
}