aboutsummaryrefslogtreecommitdiff
path: root/system/shaders
diff options
context:
space:
mode:
authorLukas Rusak <lorusak@gmail.com>2018-10-24 10:42:43 -0700
committerLukas Rusak <lorusak@gmail.com>2018-10-25 08:51:18 -0700
commit97a74b8970690f377dd0cc76e324ec568b980594 (patch)
tree6e112d1714345f103813d6542d2e078e634336f8 /system/shaders
parent3939c4985edf5e1cce1f70982e1b8c280a13acd2 (diff)
[GLES] VideoPlayer: implement tone mapping
Diffstat (limited to 'system/shaders')
-rw-r--r--system/shaders/GLES/2.0/gles_tonemap.frag4
-rw-r--r--system/shaders/GLES/2.0/gles_yuv2rgb_basic.frag54
-rw-r--r--system/shaders/GLES/2.0/gles_yuv2rgb_bob.frag33
3 files changed, 38 insertions, 53 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 0000000000..40c261cb76
--- /dev/null
+++ b/system/shaders/GLES/2.0/gles_tonemap.frag
@@ -0,0 +1,4 @@
+float tonemap(float val)
+{
+ return val * (1.0 + val/(m_toneP1*m_toneP1))/(1.0 + val);
+}
diff --git a/system/shaders/GLES/2.0/gles_yuv2rgb_basic.frag b/system/shaders/GLES/2.0/gles_yuv2rgb_basic.frag
index 9808749c07..eede848567 100644
--- a/system/shaders/GLES/2.0/gles_yuv2rgb_basic.frag
+++ b/system/shaders/GLES/2.0/gles_yuv2rgb_basic.frag
@@ -33,72 +33,44 @@ uniform mat4 m_yuvmat;
uniform mat3 m_primMat;
uniform float m_gammaDstInv;
uniform float m_gammaSrc;
+uniform float m_toneP1;
+uniform vec3 m_coefsDst;
uniform float m_alpha;
void main()
{
vec4 rgb;
+ vec4 yuv;
+
#if defined(XBMC_YV12) || defined(XBMC_NV12)
- vec4 yuv;
yuv.rgba = vec4( texture2D(m_sampY, m_cordY).r
, texture2D(m_sampU, m_cordU).g
, texture2D(m_sampV, m_cordV).a
, 1.0 );
- rgb = m_yuvmat * yuv;
-
- rgb.a = m_alpha;
-
#elif defined(XBMC_NV12_RRG)
- vec4 yuv;
yuv.rgba = vec4( texture2D(m_sampY, m_cordY).r
, texture2D(m_sampU, m_cordU).r
, texture2D(m_sampV, m_cordV).g
, 1.0 );
- rgb = m_yuvmat * yuv;
+#endif
+ rgb = m_yuvmat * yuv;
rgb.a = m_alpha;
-#elif defined(XBMC_YUY2) || defined(XBMC_UYVY)
-
- vec2 stepxy = m_step;
- vec2 pos = m_cordY;
- pos = vec2(pos.x - stepxy.x * 0.25, pos.y);
- vec2 f = fract(pos / stepxy);
-
- //y axis will be correctly interpolated by opengl
- //x axis will not, so we grab two pixels at the center of two columns and interpolate ourselves
- vec4 c1 = texture2D(m_sampY, vec2(pos.x + (0.5 - f.x) * stepxy.x, pos.y));
- vec4 c2 = texture2D(m_sampY, vec2(pos.x + (1.5 - f.x) * stepxy.x, pos.y));
-
- /* each pixel has two Y subpixels and one UV subpixel
- YUV Y YUV
- check if we're left or right of the middle Y subpixel and interpolate accordingly*/
-#ifdef XBMC_YUY2 //BGRA = YUYV
- float leftY = mix(c1.b, c1.r, f.x * 2.0);
- float rightY = mix(c1.r, c2.b, f.x * 2.0 - 1.0);
- vec2 outUV = mix(c1.ga, c2.ga, f.x);
-#else //BGRA = UYVY
- float leftY = mix(c1.g, c1.a, f.x * 2.0);
- float rightY = mix(c1.a, c2.g, f.x * 2.0 - 1.0);
- vec2 outUV = mix(c1.br, c2.br, f.x);
-#endif //XBMC_YUY2
-
- float outY = mix(leftY, rightY, step(0.5, f.x));
-
- vec4 yuv = vec4(outY, outUV, 1.0);
- rgb = m_yuvmat * yuv;
+#if defined(XBMC_COL_CONVERSION)
+ rgb.rgb = pow(max(vec3(0), rgb.rgb), vec3(m_gammaSrc));
+ rgb.rgb = max(vec3(0), m_primMat * rgb.rgb);
+ rgb.rgb = pow(rgb.rgb, vec3(m_gammaDstInv));
- rgb.a = m_alpha;
+#if defined(XBMC_TONE_MAPPING)
+ float luma = dot(rgb.rgb, m_coefsDst);
+ rgb.rgb *= tonemap(luma) / luma;
#endif
-#if defined(XBMC_COL_CONVERSION)
- rgb.rgb = pow(rgb.rgb, vec3(m_gammaSrc));
- rgb.rgb = m_primMat * rgb.rgb;
- rgb.rgb = pow(rgb.rgb, vec3(m_gammaDstInv));
#endif
gl_FragColor = rgb;
diff --git a/system/shaders/GLES/2.0/gles_yuv2rgb_bob.frag b/system/shaders/GLES/2.0/gles_yuv2rgb_bob.frag
index 2d242eb6b2..609f51d774 100644
--- a/system/shaders/GLES/2.0/gles_yuv2rgb_bob.frag
+++ b/system/shaders/GLES/2.0/gles_yuv2rgb_bob.frag
@@ -35,10 +35,12 @@ uniform int m_field;
uniform mat3 m_primMat;
uniform float m_gammaDstInv;
uniform float m_gammaSrc;
+uniform float m_toneP1;
+uniform vec3 m_coefsDst;
void main()
{
- vec4 yuv, rgb;
+ vec4 rgb;
vec2 offsetY;
vec2 offsetU;
@@ -65,25 +67,32 @@ void main()
belowV.x = offsetV.x;
belowV.y = offsetV.y + (m_stepY*bstep);
- vec4 yuvBelow, rgbBelow;
+ vec4 rgbAbove;
+ vec4 rgbBelow;
+ vec4 yuvAbove;
+ vec4 yuvBelow;
- yuv.rgba = vec4(texture2D(m_sampY, offsetY).r, texture2D(m_sampU, offsetU).g, texture2D(m_sampV, offsetV).a, 1.0);
- rgb = m_yuvmat * yuv;
- rgb.a = m_alpha;
+ yuvAbove.rgba = vec4(texture2D(m_sampY, offsetY).r, texture2D(m_sampU, offsetU).g, texture2D(m_sampV, offsetV).a, 1.0);
+ rgbAbove = m_yuvmat * yuvAbove;
+ rgbAbove.a = m_alpha;
yuvBelow.rgba = vec4(texture2D(m_sampY, belowY).r, texture2D(m_sampU, belowU).g, texture2D(m_sampV, belowV).a, 1.0);
- rgbBelow = m_yuvmat * yuvBelow;
+ rgbBelow = m_yuvmat * yuvBelow;
rgbBelow.a = m_alpha;
+ rgb = mix(rgb, rgbBelow, 0.5);
+
#if defined(XBMC_COL_CONVERSION)
- rgb.rgb = pow(rgb.rgb, vec3(m_gammaSrc));
- rgb.rgb = m_primMat * rgb.rgb;
+ rgb.rgb = pow(max(vec3(0), rgb.rgb), vec3(m_gammaSrc));
+ rgb.rgb = max(vec3(0), m_primMat * rgb.rgb);
rgb.rgb = pow(rgb.rgb, vec3(m_gammaDstInv));
- rgbBelow.rgb = pow(rgbBelow.rgb, vec3(m_gammaSrc));
- rgbBelow.rgb = m_primMat * rgbBelow.rgb;
- rgbBelow.rgb = pow(rgbBelow.rgb, vec3(m_gammaDstInv));
+#if defined(XBMC_TONE_MAPPING)
+ float luma = dot(rgb.rgb, m_coefsDst);
+ rgb.rgb *= tonemap(luma) / luma;
+#endif
+
#endif
- gl_FragColor.rgba = mix(rgb, rgbBelow, 0.5);
+ gl_FragColor.rgba = rgb;
}