summaryrefslogtreecommitdiffstats
path: root/system/shaders/GLES/2.0/gles_tonemap.frag
diff options
context:
space:
mode:
Diffstat (limited to 'system/shaders/GLES/2.0/gles_tonemap.frag')
-rw-r--r--system/shaders/GLES/2.0/gles_tonemap.frag50
1 files changed, 50 insertions, 0 deletions
diff --git a/system/shaders/GLES/2.0/gles_tonemap.frag b/system/shaders/GLES/2.0/gles_tonemap.frag
new file mode 100644
index 0000000..28b2402
--- /dev/null
+++ b/system/shaders/GLES/2.0/gles_tonemap.frag
@@ -0,0 +1,50 @@
+#if (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 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
+