diff options
author | sarbes <sarbes@kodi.tv> | 2020-11-08 20:44:14 +0100 |
---|---|---|
committer | sarbes <sarbes@kodi.tv> | 2020-11-08 20:44:14 +0100 |
commit | a6f509ced00026192828d3cc79e887bed8f590fc (patch) | |
tree | d669e97a970038983645397ea3af047202097537 /system/shaders | |
parent | 306145723ecad9b60e81837ad3d681762bdb8384 (diff) |
[OpenGL] Added ACES and Hable mapping
Diffstat (limited to 'system/shaders')
-rw-r--r-- | system/shaders/GL/1.5/gl_tonemap.glsl | 50 | ||||
-rw-r--r-- | system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl | 19 |
2 files changed, 65 insertions, 4 deletions
diff --git a/system/shaders/GL/1.5/gl_tonemap.glsl b/system/shaders/GL/1.5/gl_tonemap.glsl index bcec4e6550..a70dca2f97 100644 --- a/system/shaders/GL/1.5/gl_tonemap.glsl +++ b/system/shaders/GL/1.5/gl_tonemap.glsl @@ -1,4 +1,50 @@ -float tonemap(float val) +#if (defined(KODI_TONE_MAPPING_REINHARD) || defined(KODI_TONE_MAPPING_ACES) || defined(KODI_TONE_MAPPING_HABLE)) +const float ST2084_m1 = 2610.0 / (4096.0 * 4.0); +const float ST2084_m2 = (2523.0 / 4096.0) * 128.0; +const float ST2084_c1 = 3424.0 / 4096.0; +const float ST2084_c2 = (2413.0 / 4096.0) * 32.0; +const float ST2084_c3 = (2392.0 / 4096.0) * 32.0; +#endif + +#if defined(KODI_TONE_MAPPING_REINHARD) +float reinhard(float x) { - return val * (1 + val/(m_toneP1*m_toneP1))/(1 + val); + return x * (1.0 + x / (m_toneP1 * m_toneP1)) / (1.0 + x); } +#endif + +#if defined(KODI_TONE_MAPPING_ACES) +vec3 aces(vec3 x) +{ + float A = 2.51; + float B = 0.03; + float C = 2.43; + float D = 0.59; + float E = 0.14; + return (x * (A * x + B)) / (x * (C * x + D) + E); +} +#endif + +#if defined(KODI_TONE_MAPPING_HABLE) +vec3 hable(vec3 x) +{ + float A = 0.15; + float B = 0.5; + float C = 0.1; + float D = 0.2; + float E = 0.02; + float F = 0.3; + return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F; +} +#endif + +#if (defined(KODI_TONE_MAPPING_ACES) || defined(KODI_TONE_MAPPING_HABLE)) +vec3 inversePQ(vec3 x) +{ + x = pow(max(x, 0.0), vec3(1.0 / ST2084_m2)); + x = max(x - ST2084_c1, 0.0) / (ST2084_c2 - ST2084_c3 * x); + x = pow(x, vec3(1.0 / ST2084_m1)); + return x; +} +#endif + diff --git a/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl b/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl index 5bd2565ac2..7d5605c9cd 100644 --- a/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl +++ b/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl @@ -16,6 +16,7 @@ uniform mat3 m_primMat; uniform float m_gammaDstInv; uniform float m_gammaSrc; uniform float m_toneP1; +uniform float m_luminance; uniform vec3 m_coefsDst; in vec2 m_cordY; in vec2 m_cordU; @@ -97,9 +98,23 @@ vec4 process() rgb.rgb = max(vec3(0), m_primMat * rgb.rgb); rgb.rgb = pow(rgb.rgb, vec3(m_gammaDstInv)); -#if defined(XBMC_TONE_MAPPING) +#if defined(KODI_TONE_MAPPING_REINHARD) float luma = dot(rgb.rgb, m_coefsDst); - rgb.rgb *= tonemap(luma) / luma; + rgb.rgb *= reinhard(luma) / luma; + +#elif defined(KODI_TONE_MAPPING_ACES) + rgb.rgb = inversePQ(rgb.rgb); + rgb.rgb *= (10000.0 / m_luminance) * (2.0 / m_toneP1); + rgb.rgb = aces(rgb.rgb); + rgb.rgb *= (1.24 / m_toneP1); + rgb.rgb = pow(rgb.rgb, vec3(0.27)); + +#elif defined(KODI_TONE_MAPPING_HABLE) + rgb.rgb = inversePQ(rgb.rgb); + rgb.rgb *= m_toneP1; + float wp = m_luminance / 100.0; + rgb.rgb = hable(rgb.rgb * wp) / hable(vec3(wp)); + rgb.rgb = pow(rgb.rgb, vec3(1.0 / 2.2)); #endif #endif |