From 3fa8b844c39311a2e4e319a8d4f7ab2c848ae140 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 29 Mar 2019 02:51:41 -0700 Subject: Fixing gamma correction in EEP Step 1: Thou shall always read the sky cubemap as sRGB using hardware sampling. --- indra/llmath/llmath.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'indra/llmath/llmath.h') diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index e508c9a199..bb19248f1f 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -537,6 +537,26 @@ inline void ll_remove_outliers(std::vector& data, F32 k) } } +// This converts from a non-linear sRGB floating point value (0..1) to a linear value. +// Useful for gamma correction and such. Note: any values passed through this should not be serialized. You should also ideally cache the output of this. +inline float sRGBtoLinear(const float val) { + if (val < 0.0031308f) { + return val * 12.92f; + } + else { + return 1.055f * pow(val, 1.0f / 2.4f) - 0.055f; + } +} + +inline float linearTosRGB(const float val) { + if (val < 0.04045f) { + return val / 12.92f; + } + else { + return pow((val + 0.055f) / 1.055f, 2.4f); + } +} + // Include simd math header #include "llsimdmath.h" -- cgit v1.2.3 From 0272c47e5a31cf972e02fbf14cb2642f86f75d78 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 29 Mar 2019 11:57:45 -0700 Subject: Tweaked naming a bit, also white space. Will wait for a response from @graham_linden regarding moving the sRGB conversion functions in llmath.h to llrender. --- indra/llmath/llmath.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'indra/llmath/llmath.h') diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index bb19248f1f..57f2489a2d 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -540,21 +540,21 @@ inline void ll_remove_outliers(std::vector& data, F32 k) // This converts from a non-linear sRGB floating point value (0..1) to a linear value. // Useful for gamma correction and such. Note: any values passed through this should not be serialized. You should also ideally cache the output of this. inline float sRGBtoLinear(const float val) { - if (val < 0.0031308f) { - return val * 12.92f; - } - else { - return 1.055f * pow(val, 1.0f / 2.4f) - 0.055f; - } + if (val < 0.0031308f) { + return val * 12.92f; + } + else { + return 1.055f * pow(val, 1.0f / 2.4f) - 0.055f; + } } inline float linearTosRGB(const float val) { - if (val < 0.04045f) { - return val / 12.92f; - } - else { - return pow((val + 0.055f) / 1.055f, 2.4f); - } + if (val < 0.04045f) { + return val / 12.92f; + } + else { + return pow((val + 0.055f) / 1.055f, 2.4f); + } } // Include simd math header -- cgit v1.2.3 From d756e185730f46fd78e88215e0b4b9fd282fd1d7 Mon Sep 17 00:00:00 2001 From: Runitai Linden Date: Thu, 26 Mar 2020 16:48:33 -0500 Subject: SL-12902 Fix for doing the technically correct but compatibility wrong thing WRT light color values. --- indra/llmath/llmath.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'indra/llmath/llmath.h') diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index 57f2489a2d..8f01ad6c1c 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -537,9 +537,12 @@ inline void ll_remove_outliers(std::vector& data, F32 k) } } -// This converts from a non-linear sRGB floating point value (0..1) to a linear value. -// Useful for gamma correction and such. Note: any values passed through this should not be serialized. You should also ideally cache the output of this. -inline float sRGBtoLinear(const float val) { +// Converts given value from a linear RGB floating point value (0..1) to a gamma corrected (sRGB) value. +// Some shaders require color values in linear space, while others require color values in gamma corrected (sRGB) space. +// Note: in our code, values labeled as sRGB are ALWAYS gamma corrected linear values, NOT linear values with monitor gamma applied +// Note: stored color values should always be gamma corrected linear (i.e. the values returned from an on-screen color swatch) +// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses +inline float linearTosRGB(const float val) { if (val < 0.0031308f) { return val * 12.92f; } @@ -548,7 +551,13 @@ inline float sRGBtoLinear(const float val) { } } -inline float linearTosRGB(const float val) { +// Converts given value from a gamma corrected (sRGB) floating point value (0..1) to a linear color value. +// Some shaders require color values in linear space, while others require color values in gamma corrected (sRGB) space. +// Note: In our code, values labeled as sRGB are gamma corrected linear values, NOT linear values with monitor gamma applied +// Note: Stored color values should generally be gamma corrected sRGB. +// If you're serializing the return value of this function, you're probably doing it wrong. +// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses. +inline float sRGBtoLinear(const float val) { if (val < 0.04045f) { return val / 12.92f; } -- cgit v1.2.3