diff options
author | Rainer Hochecker <fernetmenta@online.de> | 2018-02-09 18:03:20 +0100 |
---|---|---|
committer | Rainer Hochecker <fernetmenta@online.de> | 2018-02-10 08:35:49 +0100 |
commit | 787a0c28f1641e572b03c71657337712cd4efabe (patch) | |
tree | 9ac0be9cb98fd5c9868445fe09865d68bc10be48 /system/shaders/GL | |
parent | 8f33367f8324c1104c248363467e92c56a79c6d6 (diff) |
VideoPlayer: OpenGL - implement tone mapping
Diffstat (limited to 'system/shaders/GL')
-rw-r--r-- | system/shaders/GL/1.2/gl_yuv2rgb_basic.glsl | 8 | ||||
-rw-r--r-- | system/shaders/GL/1.5/gl_tonemap.glsl | 4 | ||||
-rw-r--r-- | system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl | 37 | ||||
-rw-r--r-- | system/shaders/GL/4.0/gl_yuv2rgb_filter4.glsl | 40 |
4 files changed, 49 insertions, 40 deletions
diff --git a/system/shaders/GL/1.2/gl_yuv2rgb_basic.glsl b/system/shaders/GL/1.2/gl_yuv2rgb_basic.glsl index bae6d79a21..e4ea964a72 100644 --- a/system/shaders/GL/1.2/gl_yuv2rgb_basic.glsl +++ b/system/shaders/GL/1.2/gl_yuv2rgb_basic.glsl @@ -122,13 +122,9 @@ vec4 process() #endif #if defined(XBMC_COL_CONVERSION) - rgb.r = pow(rgb.r, m_gammaSrc); - rgb.g = pow(rgb.g, m_gammaSrc); - rgb.b = pow(rgb.b, m_gammaSrc); + rgb.rgb = pow(rgb.rgb, vec3(m_gammaSrc)); rgb.rgb = m_primMat * rgb.rgb; - rgb.r = pow(rgb.r, m_gammaDstInv); - rgb.g = pow(rgb.g, m_gammaDstInv); - rgb.b = pow(rgb.b, m_gammaDstInv); + rgb.rgb = pow(rgb.rgb, vec3(m_gammaDstInv)); #endif return rgb; diff --git a/system/shaders/GL/1.5/gl_tonemap.glsl b/system/shaders/GL/1.5/gl_tonemap.glsl new file mode 100644 index 0000000000..bcec4e6550 --- /dev/null +++ b/system/shaders/GL/1.5/gl_tonemap.glsl @@ -0,0 +1,4 @@ +float tonemap(float val) +{ + return val * (1 + val/(m_toneP1*m_toneP1))/(1 + val); +} diff --git a/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl b/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl index a34c30143a..b4fb012910 100644 --- a/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl +++ b/system/shaders/GL/1.5/gl_yuv2rgb_basic.glsl @@ -15,6 +15,8 @@ uniform float m_alpha; uniform mat3 m_primMat; uniform float m_gammaDstInv; uniform float m_gammaSrc; +uniform float m_toneP1; +uniform vec3 m_coefsDst; in vec2 m_cordY; in vec2 m_cordU; in vec2 m_cordV; @@ -41,25 +43,20 @@ vec2 stretch(vec2 pos) vec4 process() { vec4 rgb; + vec4 yuv; + #if defined(XBMC_YV12) - vec4 yuv; yuv.rgba = vec4( texture(m_sampY, stretch(m_cordY)).r , texture(m_sampU, stretch(m_cordU)).r , texture(m_sampV, stretch(m_cordV)).r , 1.0 ); - rgb = m_yuvmat * yuv; - rgb.a = m_alpha; - #elif defined(XBMC_NV12) - vec4 yuv; yuv.rgba = vec4( texture(m_sampY, stretch(m_cordY)).r , texture(m_sampU, stretch(m_cordU)).rg , 1.0 ); - rgb = m_yuvmat * yuv; - rgb.a = m_alpha; #elif defined(XBMC_YUY2) || defined(XBMC_UYVY) @@ -86,23 +83,29 @@ vec4 process() vec2 outUV = mix(c1.br, c2.br, f.x); #endif //XBMC_YUY2 - float outY = mix(leftY, rightY, step(0.5, f.x)); + float outY = mix(leftY, rightY, step(0.5, f.x)); - vec4 yuv = vec4(outY, outUV, 1.0); - rgb = m_yuvmat * yuv; + yuv = vec4(outY, outUV, 1.0); - rgb.a = m_alpha; +#endif +#if defined(XBMC_TONE_MAPPING) + //float scale = tonemap(yuv.x) / yuv.x; #endif + rgb = m_yuvmat * yuv; + rgb.a = m_alpha; + #if defined(XBMC_COL_CONVERSION) - rgb.r = pow(rgb.r, m_gammaSrc); - rgb.g = pow(rgb.g, m_gammaSrc); - rgb.b = pow(rgb.b, m_gammaSrc); + rgb.rgb = pow(rgb.rgb, vec3(m_gammaSrc)); rgb.rgb = m_primMat * rgb.rgb; - rgb.r = pow(rgb.r, m_gammaDstInv); - rgb.g = pow(rgb.g, m_gammaDstInv); - rgb.b = pow(rgb.b, m_gammaDstInv); + rgb.rgb = pow(rgb.rgb, vec3(m_gammaDstInv)); + +#if defined(XBMC_TONE_MAPPING) + float luma = dot(rgb.rgb, m_coefsDst); + rgb.rgb *= tonemap(luma) / luma; +#endif + #endif return rgb; diff --git a/system/shaders/GL/4.0/gl_yuv2rgb_filter4.glsl b/system/shaders/GL/4.0/gl_yuv2rgb_filter4.glsl index ccfbaa8115..bbcfe19a96 100644 --- a/system/shaders/GL/4.0/gl_yuv2rgb_filter4.glsl +++ b/system/shaders/GL/4.0/gl_yuv2rgb_filter4.glsl @@ -16,6 +16,8 @@ uniform sampler1D m_kernelTex; uniform mat3 m_primMat; uniform float m_gammaDstInv; uniform float m_gammaSrc; +uniform float m_toneP1; +uniform vec3 m_coefsDst; in vec2 m_cordY; in vec2 m_cordU; in vec2 m_cordV; @@ -88,33 +90,37 @@ float filter_0(sampler2D sampler, vec2 coord) vec4 process() { vec4 rgb; -#if defined(XBMC_YV12) + vec4 yuv; - vec4 yuv = vec4(filter_0(m_sampY, stretch(m_cordY)), - texture(m_sampU, stretch(m_cordU)).r, - texture(m_sampV, stretch(m_cordV)).r, - 1.0); +#if defined(XBMC_YV12) - rgb = m_yuvmat * yuv; - rgb.a = m_alpha; + yuv = vec4(filter_0(m_sampY, stretch(m_cordY)), + texture(m_sampU, stretch(m_cordU)).r, + texture(m_sampV, stretch(m_cordV)).r, + 1.0); #elif defined(XBMC_NV12) - vec4 yuv = vec4(filter_0(m_sampY, stretch(m_cordY)), - texture(m_sampU, stretch(m_cordU)).rg, - 1.0); + yuv = vec4(filter_0(m_sampY, stretch(m_cordY)), + texture(m_sampU, stretch(m_cordU)).rg, + 1.0); + +#endif + rgb = m_yuvmat * yuv; rgb.a = m_alpha; -#endif #if defined(XBMC_COL_CONVERSION) - rgb.r = pow(rgb.r, m_gammaSrc); - rgb.g = pow(rgb.g, m_gammaSrc); - rgb.b = pow(rgb.b, m_gammaSrc); + rgb.rgb = pow(rgb.rgb, vec3(m_gammaSrc)); rgb.rgb = m_primMat * rgb.rgb; - rgb.r = pow(rgb.r, m_gammaDstInv); - rgb.g = pow(rgb.g, m_gammaDstInv); - rgb.b = pow(rgb.b, m_gammaDstInv); + rgb.rgb = pow(rgb.rgb, vec3(m_gammaDstInv)); + +#if defined(XBMC_TONE_MAPPING) + float luma = dot(rgb.rgb, m_coefsDst); + rgb.rgb *= tonemap(luma) / luma; #endif + +#endif + return rgb; } |