diff options
author | Lukas Rusak <lorusak@gmail.com> | 2018-10-29 10:11:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-29 10:11:25 -0700 |
commit | de57423adae7f389cbb2758fff4964bb91f003c2 (patch) | |
tree | e61dc2935215a92c3bb9415005cc505bb5c0d791 /system | |
parent | f237c7e5b3697316fc059d9974c87dd20c7feba4 (diff) | |
parent | b7ce0080227458d1b93fd62297dd8d22945aa245 (diff) |
Merge pull request #14704 from lrusak/gles-updates
[GLES] VideoPlayer: YUV2RGB rework, Tonemapping, and other cleanup
Diffstat (limited to 'system')
18 files changed, 253 insertions, 220 deletions
diff --git a/system/shaders/GLES/2.0/gles_convolution-4x4.frag b/system/shaders/GLES/2.0/gles_convolution-4x4.frag index 89e5b8d58d..85bec53d4f 100644 --- a/system/shaders/GLES/2.0/gles_convolution-4x4.frag +++ b/system/shaders/GLES/2.0/gles_convolution-4x4.frag @@ -23,14 +23,14 @@ precision highp float; uniform sampler2D img; -uniform vec2 stepxy; -varying vec2 cord; -uniform float m_alpha; +uniform vec2 stepxy; +varying vec2 cord; +uniform float m_alpha; uniform sampler2D kernelTex; vec4 weight(float pos) { -#if (HAS_FLOAT_TEXTURE) +#if defined(HAS_FLOAT_TEXTURE) return texture2D(kernelTex, vec2(pos - 0.5)); #else return texture2D(kernelTex, vec2(pos - 0.5)) * 2.0 - 1.0; @@ -44,11 +44,10 @@ vec3 pixel(float xpos, float ypos) vec3 line (float ypos, vec4 xpos, vec4 linetaps) { - return - pixel(xpos.r, ypos) * linetaps.r + - pixel(xpos.g, ypos) * linetaps.g + - pixel(xpos.b, ypos) * linetaps.b + - pixel(xpos.a, ypos) * linetaps.a; + return pixel(xpos.r, ypos) * linetaps.r + + pixel(xpos.g, ypos) * linetaps.g + + pixel(xpos.b, ypos) * linetaps.b + + pixel(xpos.a, ypos) * linetaps.a; } void main() @@ -57,21 +56,20 @@ void main() vec2 pos = cord + stepxy * 0.5; vec2 f = fract(pos / stepxy); - vec4 linetaps = weight(1.0 - f.x); + vec4 linetaps = weight(1.0 - f.x); vec4 columntaps = weight(1.0 - f.y); - //make sure all taps added together is exactly 1.0, otherwise some (very small) distortion can occur + // make sure all taps added together is exactly 1.0, otherwise some (very small) distortion can occur linetaps /= linetaps.r + linetaps.g + linetaps.b + linetaps.a; columntaps /= columntaps.r + columntaps.g + columntaps.b + columntaps.a; vec2 xystart = (-1.5 - f) * stepxy + pos; vec4 xpos = vec4(xystart.x, xystart.x + stepxy.x, xystart.x + stepxy.x * 2.0, xystart.x + stepxy.x * 3.0); - rgb.rgb = - line(xystart.y , xpos, linetaps) * columntaps.r + - line(xystart.y + stepxy.y , xpos, linetaps) * columntaps.g + - line(xystart.y + stepxy.y * 2.0, xpos, linetaps) * columntaps.b + - line(xystart.y + stepxy.y * 3.0, xpos, linetaps) * columntaps.a; + rgb.rgb = line(xystart.y, xpos, linetaps) * columntaps.r + + line(xystart.y + stepxy.y, xpos, linetaps) * columntaps.g + + line(xystart.y + stepxy.y * 2.0, xpos, linetaps) * columntaps.b + + line(xystart.y + stepxy.y * 3.0, xpos, linetaps) * columntaps.a; rgb.a = m_alpha; diff --git a/system/shaders/GLES/2.0/gles_convolution-6x6.frag b/system/shaders/GLES/2.0/gles_convolution-6x6.frag index 8333d51f32..c992b4b4a9 100644 --- a/system/shaders/GLES/2.0/gles_convolution-6x6.frag +++ b/system/shaders/GLES/2.0/gles_convolution-6x6.frag @@ -23,14 +23,14 @@ precision highp float; uniform sampler2D img; -uniform vec2 stepxy; -varying vec2 cord; -uniform float m_alpha; +uniform vec2 stepxy; +varying vec2 cord; +uniform float m_alpha; uniform sampler2D kernelTex; vec3 weight(float pos) { -#if (HAS_FLOAT_TEXTURE) +#if defined(HAS_FLOAT_TEXTURE) return texture2D(kernelTex, vec2(pos - 0.5)).rgb; #else return texture2D(kernelTex, vec2(pos - 0.5)).rgb * 2.0 - 1.0; @@ -44,13 +44,12 @@ vec3 pixel(float xpos, float ypos) vec3 line (float ypos, vec3 xpos1, vec3 xpos2, vec3 linetaps1, vec3 linetaps2) { - return - pixel(xpos1.r, ypos) * linetaps1.r + - pixel(xpos1.g, ypos) * linetaps2.r + - pixel(xpos1.b, ypos) * linetaps1.g + - pixel(xpos2.r, ypos) * linetaps2.g + - pixel(xpos2.g, ypos) * linetaps1.b + - pixel(xpos2.b, ypos) * linetaps2.b; + return pixel(xpos1.r, ypos) * linetaps1.r + + pixel(xpos1.g, ypos) * linetaps2.r + + pixel(xpos1.b, ypos) * linetaps1.g + + pixel(xpos2.r, ypos) * linetaps2.g + + pixel(xpos2.g, ypos) * linetaps1.b + + pixel(xpos2.b, ypos) * linetaps2.b; } void main() @@ -59,12 +58,12 @@ void main() vec2 pos = cord + stepxy * 0.5; vec2 f = fract(pos / stepxy); - vec3 linetaps1 = weight((1.0 - f.x) / 2.0); - vec3 linetaps2 = weight((1.0 - f.x) / 2.0 + 0.5); + vec3 linetaps1 = weight((1.0 - f.x) / 2.0); + vec3 linetaps2 = weight((1.0 - f.x) / 2.0 + 0.5); vec3 columntaps1 = weight((1.0 - f.y) / 2.0); vec3 columntaps2 = weight((1.0 - f.y) / 2.0 + 0.5); - //make sure all taps added together is exactly 1.0, otherwise some (very small) distortion can occur + // make sure all taps added together is exactly 1.0, otherwise some (very small) distortion can occur float sum = linetaps1.r + linetaps1.g + linetaps1.b + linetaps2.r + linetaps2.g + linetaps2.b; linetaps1 /= sum; linetaps2 /= sum; @@ -76,13 +75,12 @@ void main() vec3 xpos1 = vec3(xystart.x, xystart.x + stepxy.x, xystart.x + stepxy.x * 2.0); vec3 xpos2 = vec3(xystart.x + stepxy.x * 3.0, xystart.x + stepxy.x * 4.0, xystart.x + stepxy.x * 5.0); - rgb.rgb = - line(xystart.y , xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r + - line(xystart.y + stepxy.y , xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r + - line(xystart.y + stepxy.y * 2.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g + - line(xystart.y + stepxy.y * 3.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g + - line(xystart.y + stepxy.y * 4.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b + - line(xystart.y + stepxy.y * 5.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b; + rgb.rgb = line(xystart.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r + + line(xystart.y + stepxy.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r + + line(xystart.y + stepxy.y * 2.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g + + line(xystart.y + stepxy.y * 3.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g + + line(xystart.y + stepxy.y * 4.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b + + line(xystart.y + stepxy.y * 5.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b; rgb.a = m_alpha; diff --git a/system/shaders/GLES/2.0/gles_shader.vert b/system/shaders/GLES/2.0/gles_shader.vert index 018961f556..890acbbb81 100644 --- a/system/shaders/GLES/2.0/gles_shader.vert +++ b/system/shaders/GLES/2.0/gles_shader.vert @@ -24,18 +24,18 @@ attribute vec4 m_attrpos; attribute vec4 m_attrcol; attribute vec4 m_attrcord0; attribute vec4 m_attrcord1; -varying vec4 m_cord0; -varying vec4 m_cord1; +varying vec4 m_cord0; +varying vec4 m_cord1; varying lowp vec4 m_colour; -uniform mat4 m_proj; -uniform mat4 m_model; -uniform mat4 m_coord0Matrix; +uniform mat4 m_proj; +uniform mat4 m_model; +uniform mat4 m_coord0Matrix; void main () { - mat4 mvp = m_proj * m_model; + mat4 mvp = m_proj * m_model; gl_Position = mvp * m_attrpos; - m_colour = m_attrcol; - m_cord0 = m_coord0Matrix * m_attrcord0; - m_cord1 = m_attrcord1; + m_colour = m_attrcol; + m_cord0 = m_coord0Matrix * m_attrcord0; + m_cord1 = m_attrcord1; } diff --git a/system/shaders/GLES/2.0/gles_shader_default.frag b/system/shaders/GLES/2.0/gles_shader_default.frag index 0983b85c5c..f213360454 100644 --- a/system/shaders/GLES/2.0/gles_shader_default.frag +++ b/system/shaders/GLES/2.0/gles_shader_default.frag @@ -23,12 +23,16 @@ precision mediump float; uniform lowp vec4 m_unicol; -// SM_DEFAULT shader void main () { - gl_FragColor = m_unicol; + vec4 rgb; + + rgb = m_unicol; + #if defined(KODI_LIMITED_RANGE) - gl_FragColor.rgb *= (235.0-16.0) / 255.0; - gl_FragColor.rgb += 16.0 / 255.0; + rgb.rgb *= (235.0 - 16.0) / 255.0; + rgb.rgb += 16.0 / 255.0; #endif + + gl_FragColor = rgb; } diff --git a/system/shaders/GLES/2.0/gles_shader_fonts.frag b/system/shaders/GLES/2.0/gles_shader_fonts.frag index 36dfd6c740..075d26f67a 100644 --- a/system/shaders/GLES/2.0/gles_shader_fonts.frag +++ b/system/shaders/GLES/2.0/gles_shader_fonts.frag @@ -20,20 +20,22 @@ #version 100 -precision mediump float; -uniform sampler2D m_samp0; -varying vec4 m_cord0; -varying lowp vec4 m_colour; +precision mediump float; +uniform sampler2D m_samp0; +varying vec4 m_cord0; +varying lowp vec4 m_colour; -// SM_FONTS shader void main () { - gl_FragColor.r = m_colour.r; - gl_FragColor.g = m_colour.g; - gl_FragColor.b = m_colour.b; - gl_FragColor.a = m_colour.a * texture2D(m_samp0, m_cord0.xy).a; + vec4 rgb; + + rgb.rgb = m_colour.rgb; + rgb.a = m_colour.a * texture2D(m_samp0, m_cord0.xy).a; + #if defined(KODI_LIMITED_RANGE) - gl_FragColor.rgb *= (235.0-16.0) / 255.0; - gl_FragColor.rgb += 16.0 / 255.0; + rgb.rgb *= (235.0 - 16.0) / 255.0; + rgb.rgb += 16.0 / 255.0; #endif + + gl_FragColor = rgb; } diff --git a/system/shaders/GLES/2.0/gles_shader_multi.frag b/system/shaders/GLES/2.0/gles_shader_multi.frag index 7f76358124..9f288982ec 100644 --- a/system/shaders/GLES/2.0/gles_shader_multi.frag +++ b/system/shaders/GLES/2.0/gles_shader_multi.frag @@ -20,18 +20,22 @@ #version 100 -precision mediump float; -uniform sampler2D m_samp0; -uniform sampler2D m_samp1; -varying vec4 m_cord0; -varying vec4 m_cord1; +precision mediump float; +uniform sampler2D m_samp0; +uniform sampler2D m_samp1; +varying vec4 m_cord0; +varying vec4 m_cord1; -// SM_MULTI shader void main () { - gl_FragColor.rgba = (texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy)).rgba; + vec4 rgb; + + rgb = texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy); + #if defined(KODI_LIMITED_RANGE) - gl_FragColor.rgb *= (235.0-16.0) / 255.0; - gl_FragColor.rgb += 16.0 / 255.0; + rgb.rgb *= (235.0 - 16.0) / 255.0; + rgb.rgb += 16.0 / 255.0; #endif + + gl_FragColor = rgb; } diff --git a/system/shaders/GLES/2.0/gles_shader_multi_blendcolor.frag b/system/shaders/GLES/2.0/gles_shader_multi_blendcolor.frag index 062f292f28..35153da34c 100644 --- a/system/shaders/GLES/2.0/gles_shader_multi_blendcolor.frag +++ b/system/shaders/GLES/2.0/gles_shader_multi_blendcolor.frag @@ -20,19 +20,23 @@ #version 100 -precision mediump float; -uniform sampler2D m_samp0; -uniform sampler2D m_samp1; -varying vec4 m_cord0; -varying vec4 m_cord1; -uniform lowp vec4 m_unicol; +precision mediump float; +uniform sampler2D m_samp0; +uniform sampler2D m_samp1; +varying vec4 m_cord0; +varying vec4 m_cord1; +uniform lowp vec4 m_unicol; -// SM_MULTI shader void main () { - gl_FragColor.rgba = m_unicol * texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy); + vec4 rgb; + + rgb = m_unicol * texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy); + #if defined(KODI_LIMITED_RANGE) - gl_FragColor.rgb *= (235.0-16.0) / 255.0; - gl_FragColor.rgb += 16.0 / 255.0; + rgb.rgb *= (235.0 - 16.0) / 255.0; + rgb.rgb += 16.0 / 255.0; #endif + + gl_FragColor = rgb; } diff --git a/system/shaders/GLES/2.0/gles_shader_rgba.frag b/system/shaders/GLES/2.0/gles_shader_rgba.frag index d5d7ffb3e6..cdbb076fb4 100644 --- a/system/shaders/GLES/2.0/gles_shader_rgba.frag +++ b/system/shaders/GLES/2.0/gles_shader_rgba.frag @@ -23,19 +23,21 @@ precision mediump float; uniform sampler2D m_samp0; uniform sampler2D m_samp1; -varying vec4 m_cord0; -varying vec4 m_cord1; +varying vec4 m_cord0; +varying vec4 m_cord1; varying lowp vec4 m_colour; -uniform int m_method; +uniform int m_method; -uniform float m_brightness; -uniform float m_contrast; +uniform float m_brightness; +uniform float m_contrast; void main () { - vec4 color = texture2D(m_samp0, m_cord0.xy).rgba; - color = color * m_contrast; - color = color + m_brightness; + vec4 rgb; - gl_FragColor.rgba = color; + rgb = texture2D(m_samp0, m_cord0.xy); + rgb *= m_contrast; + rgb += m_brightness; + + gl_FragColor = rgb; } diff --git a/system/shaders/GLES/2.0/gles_shader_rgba_blendcolor.frag b/system/shaders/GLES/2.0/gles_shader_rgba_blendcolor.frag index 5c4e89990b..3f08da0fd7 100644 --- a/system/shaders/GLES/2.0/gles_shader_rgba_blendcolor.frag +++ b/system/shaders/GLES/2.0/gles_shader_rgba_blendcolor.frag @@ -23,17 +23,21 @@ precision mediump float; uniform sampler2D m_samp0; uniform sampler2D m_samp1; -varying vec4 m_cord0; -varying vec4 m_cord1; +varying vec4 m_cord0; +varying vec4 m_cord1; varying lowp vec4 m_colour; -uniform int m_method; +uniform int m_method; -// SM_TEXTURE void main () { - gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba * m_colour); + vec4 rgb; + + rgb = texture2D(m_samp0, m_cord0.xy).rgba * m_colour; + #if defined(KODI_LIMITED_RANGE) - gl_FragColor.rgb *= (235.0-16.0) / 255.0; - gl_FragColor.rgb += 16.0 / 255.0; + rgb.rgb *= (235.0 - 16.0) / 255.0; + rgb.rgb += 16.0 / 255.0; #endif + + gl_FragColor = rgb; } diff --git a/system/shaders/GLES/2.0/gles_shader_rgba_bob.frag b/system/shaders/GLES/2.0/gles_shader_rgba_bob.frag index b1c1628204..fd4a83babc 100644 --- a/system/shaders/GLES/2.0/gles_shader_rgba_bob.frag +++ b/system/shaders/GLES/2.0/gles_shader_rgba_bob.frag @@ -23,34 +23,34 @@ precision highp float; uniform sampler2D m_samp0; uniform sampler2D m_samp1; -varying vec4 m_cord0; -varying vec4 m_cord1; +varying vec4 m_cord0; +varying vec4 m_cord1; varying lowp vec4 m_colour; -uniform int m_method; -uniform int m_field; -uniform float m_step; +uniform int m_method; +uniform int m_field; +uniform float m_step; -uniform float m_brightness; -uniform float m_contrast; +uniform float m_brightness; +uniform float m_contrast; void main () { vec2 source; source = m_cord0.xy; - float temp1 = mod(source.y, 2.0*m_step); + float temp1 = mod(source.y, 2.0 * m_step); float temp2 = source.y - temp1; - source.y = temp2 + m_step/2.0 - float(m_field)*m_step; + source.y = temp2 + m_step / 2.0 - float(m_field) * m_step; // Blend missing line vec2 below; float bstep = step(m_step, temp1); below.x = source.x; - below.y = source.y + (2.0*m_step*bstep); + below.y = source.y + (2.0 * m_step * bstep); vec4 color = mix(texture2D(m_samp0, source), texture2D(m_samp0, below), 0.5); - color = color * m_contrast; - color = color + m_brightness; + color *= m_contrast; + color += m_brightness; - gl_FragColor.rgba = color; + gl_FragColor = color; } diff --git a/system/shaders/GLES/2.0/gles_shader_rgba_bob_oes.frag b/system/shaders/GLES/2.0/gles_shader_rgba_bob_oes.frag index bbab5c4091..16894affb6 100644 --- a/system/shaders/GLES/2.0/gles_shader_rgba_bob_oes.frag +++ b/system/shaders/GLES/2.0/gles_shader_rgba_bob_oes.frag @@ -25,34 +25,34 @@ precision highp float; uniform samplerExternalOES m_samp0; uniform samplerExternalOES m_samp1; -varying vec4 m_cord0; -varying vec4 m_cord1; +varying vec4 m_cord0; +varying vec4 m_cord1; varying lowp vec4 m_colour; -uniform int m_method; -uniform int m_field; -uniform float m_step; +uniform int m_method; +uniform int m_field; +uniform float m_step; -uniform float m_brightness; -uniform float m_contrast; +uniform float m_brightness; +uniform float m_contrast; void main () { vec2 source; source = m_cord0.xy; - float temp1 = mod(source.y, 2.0*m_step); + float temp1 = mod(source.y, 2.0 * m_step); float temp2 = source.y - temp1; - source.y = temp2 + m_step/2.0 - float(m_field)*m_step; + source.y = temp2 + m_step / 2.0 - float(m_field) * m_step; // Blend missing line vec2 below; float bstep = step(m_step, temp1); below.x = source.x; - below.y = source.y + (2.0*m_step*bstep); + below.y = source.y + (2.0*m_step * bstep); vec4 color = mix(texture2D(m_samp0, source), texture2D(m_samp0, below), 0.5); - color = color * m_contrast; - color = color + m_brightness; + color *= m_contrast; + color += m_brightness; - gl_FragColor.rgba = color; + gl_FragColor = color; } diff --git a/system/shaders/GLES/2.0/gles_shader_rgba_oes.frag b/system/shaders/GLES/2.0/gles_shader_rgba_oes.frag index 55e311cf1e..2936954235 100644 --- a/system/shaders/GLES/2.0/gles_shader_rgba_oes.frag +++ b/system/shaders/GLES/2.0/gles_shader_rgba_oes.frag @@ -24,16 +24,18 @@ precision mediump float; uniform samplerExternalOES m_samp0; -varying vec4 m_cord0; +varying vec4 m_cord0; -uniform float m_brightness; -uniform float m_contrast; +uniform float m_brightness; +uniform float m_contrast; void main () { - vec4 color = texture2D(m_samp0, m_cord0.xy).rgba; - color = color * m_contrast; - color = color + m_brightness; + vec4 rgb; - gl_FragColor.rgba = color; + rgb = texture2D(m_samp0, m_cord0.xy); + rgb *= m_contrast; + rgb += m_brightness; + + gl_FragColor = rgb; } diff --git a/system/shaders/GLES/2.0/gles_shader_texture.frag b/system/shaders/GLES/2.0/gles_shader_texture.frag index e664330ffd..a2ac2de79b 100644 --- a/system/shaders/GLES/2.0/gles_shader_texture.frag +++ b/system/shaders/GLES/2.0/gles_shader_texture.frag @@ -20,17 +20,21 @@ #version 100 -precision mediump float; -uniform sampler2D m_samp0; -uniform lowp vec4 m_unicol; -varying vec4 m_cord0; +precision mediump float; +uniform sampler2D m_samp0; +uniform lowp vec4 m_unicol; +varying vec4 m_cord0; -// SM_TEXTURE shader void main () { - gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba * m_unicol); + vec4 rgb; + + rgb = texture2D(m_samp0, m_cord0.xy).rgba * m_unicol; + #if defined(KODI_LIMITED_RANGE) - gl_FragColor.rgb *= (235.0-16.0) / 255.0; - gl_FragColor.rgb += 16.0 / 255.0; + rgb.rgb *= (235.0 - 16.0) / 255.0; + rgb.rgb += 16.0 / 255.0; #endif + + gl_FragColor = rgb; } diff --git a/system/shaders/GLES/2.0/gles_shader_texture_noblend.frag b/system/shaders/GLES/2.0/gles_shader_texture_noblend.frag index 1752c4cc03..8cc66c94c9 100644 --- a/system/shaders/GLES/2.0/gles_shader_texture_noblend.frag +++ b/system/shaders/GLES/2.0/gles_shader_texture_noblend.frag @@ -20,16 +20,20 @@ #version 100 -precision mediump float; -uniform sampler2D m_samp0; -varying vec4 m_cord0; +precision mediump float; +uniform sampler2D m_samp0; +varying vec4 m_cord0; -// SM_TEXTURE_NOBLEND shader void main () { - gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba); + vec4 rgb; + + rgb = texture2D(m_samp0, m_cord0.xy); + #if defined(KODI_LIMITED_RANGE) - gl_FragColor.rgb *= (235.0-16.0) / 255.0; - gl_FragColor.rgb += 16.0 / 255.0; + rgb.rgb *= (235.0 - 16.0) / 255.0; + rgb.rgb += 16.0 / 255.0; #endif + + gl_FragColor = rgb; } 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..4a98f56dbb --- /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.vert b/system/shaders/GLES/2.0/gles_yuv2rgb.vert index 43b4b06dcc..bc437afdc3 100644 --- a/system/shaders/GLES/2.0/gles_yuv2rgb.vert +++ b/system/shaders/GLES/2.0/gles_yuv2rgb.vert @@ -32,9 +32,9 @@ uniform mat4 m_model; void main () { - mat4 mvp = m_proj * m_model; + mat4 mvp = m_proj * m_model; gl_Position = mvp * m_attrpos; - m_cordY = m_attrcordY; - m_cordU = m_attrcordU; - m_cordV = m_attrcordV; + m_cordY = m_attrcordY; + m_cordU = m_attrcordU; + m_cordV = m_attrcordV; } diff --git a/system/shaders/GLES/2.0/gles_yuv2rgb_basic.frag b/system/shaders/GLES/2.0/gles_yuv2rgb_basic.frag index 4447b6aa7f..ecd82b13ca 100644 --- a/system/shaders/GLES/2.0/gles_yuv2rgb_basic.frag +++ b/system/shaders/GLES/2.0/gles_yuv2rgb_basic.frag @@ -25,71 +25,52 @@ precision mediump float; uniform sampler2D m_sampY; uniform sampler2D m_sampU; uniform sampler2D m_sampV; -varying vec2 m_cordY; -varying vec2 m_cordU; -varying vec2 m_cordV; -uniform vec2 m_step; -uniform mat4 m_yuvmat; -uniform float m_alpha; +varying vec2 m_cordY; +varying vec2 m_cordU; +varying vec2 m_cordV; +uniform vec2 m_step; +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; -#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; +#if defined(XBMC_YV12) || defined(XBMC_NV12) - rgb.a = m_alpha; + yuv = vec4(texture2D(m_sampY, m_cordY).r, + texture2D(m_sampU, m_cordU).g, + texture2D(m_sampV, m_cordV).a, + 1.0); #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 ); + yuv = 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) +#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)); - 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_TONE_MAPPING) + float luma = dot(rgb.rgb, m_coefsDst); + rgb.rgb *= tonemap(luma) / luma; +#endif - rgb.a = m_alpha; #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 28254e26af..22d672dd14 100644 --- a/system/shaders/GLES/2.0/gles_yuv2rgb_bob.frag +++ b/system/shaders/GLES/2.0/gles_yuv2rgb_bob.frag @@ -24,31 +24,36 @@ precision highp float; uniform sampler2D m_sampY; uniform sampler2D m_sampU; uniform sampler2D m_sampV; -varying vec2 m_cordY; -varying vec2 m_cordU; -varying vec2 m_cordV; -uniform float m_alpha; -uniform mat4 m_yuvmat; -uniform float m_stepX; -uniform float m_stepY; -uniform int m_field; +varying vec2 m_cordY; +varying vec2 m_cordU; +varying vec2 m_cordV; +uniform float m_alpha; +uniform mat4 m_yuvmat; +uniform float m_stepX; +uniform float m_stepY; +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; vec2 offsetV; - float temp1 = mod(m_cordY.y, 2.0*m_stepY); + float temp1 = mod(m_cordY.y, 2.0 * m_stepY); offsetY = m_cordY; offsetU = m_cordU; offsetV = m_cordV; - offsetY.y -= (temp1 - m_stepY/2.0 + float(m_field)*m_stepY); - offsetU.y -= (temp1 - m_stepY/2.0 + float(m_field)*m_stepY)/2.0; - offsetV.y -= (temp1 - m_stepY/2.0 + float(m_field)*m_stepY)/2.0; + offsetY.y -= (temp1 - m_stepY / 2.0 + float(m_field) * m_stepY); + offsetU.y -= (temp1 - m_stepY / 2.0 + float(m_field) * m_stepY) / 2.0; + offsetV.y -= (temp1 - m_stepY / 2.0 + float(m_field) * m_stepY) / 2.0; float bstep = step(m_stepY, temp1); @@ -56,21 +61,38 @@ void main() vec2 belowY, belowU, belowV; belowY.x = offsetY.x; - belowY.y = offsetY.y + (2.0*m_stepY*bstep); + belowY.y = offsetY.y + (2.0 * m_stepY * bstep); belowU.x = offsetU.x; - belowU.y = offsetU.y + (m_stepY*bstep); + belowU.y = offsetU.y + (m_stepY * bstep); belowV.x = offsetV.x; - belowV.y = offsetV.y + (m_stepY*bstep); + 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 = 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; + yuvBelow = vec4(texture2D(m_sampY, belowY).r, texture2D(m_sampU, belowU).g, texture2D(m_sampV, belowV).a, 1.0); + rgbBelow = m_yuvmat * yuvBelow; rgbBelow.a = m_alpha; - gl_FragColor.rgba = mix(rgb, rgbBelow, 0.5); + rgb = mix(rgb, rgbBelow, 0.5); + +#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)); + +#if defined(XBMC_TONE_MAPPING) + float luma = dot(rgb.rgb, m_coefsDst); + rgb.rgb *= tonemap(luma) / luma; +#endif + +#endif + + gl_FragColor = rgb; } |