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') 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