2012-03-30 23:13:38 +00:00
|
|
|
/*
|
2013-03-01 20:19:20 +00:00
|
|
|
* This file is part of mpv.
|
2012-03-30 23:13:38 +00:00
|
|
|
*
|
2013-03-01 20:19:20 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2012-03-30 23:13:38 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2013-03-01 20:19:20 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2012-03-30 23:13:38 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2013-03-01 20:19:20 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* You can alternatively redistribute this file and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-03-30 23:13:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Note that this file is not directly passed as shader, but run through some
|
|
|
|
// text processing functions, and in fact contains multiple vertex and fragment
|
|
|
|
// shaders.
|
|
|
|
|
|
|
|
// inserted at the beginning of all shaders
|
|
|
|
#!section prelude
|
2012-10-02 23:54:13 +00:00
|
|
|
|
|
|
|
// GLSL 1.20 compatibility layer
|
|
|
|
// texture() should be assumed to always map to texture2D()
|
|
|
|
#if __VERSION__ >= 130
|
|
|
|
# define texture1D texture
|
|
|
|
# define texture3D texture
|
|
|
|
# define DECLARE_FRAGPARMS \
|
|
|
|
out vec4 out_color;
|
|
|
|
#else
|
|
|
|
# define texture texture2D
|
|
|
|
# define DECLARE_FRAGPARMS
|
|
|
|
# define out_color gl_FragColor
|
|
|
|
# define in varying
|
|
|
|
#endif
|
|
|
|
|
vo_opengl: fix compatibility with OpenGL 2.1
The srgb_compand() function passes bvec to mix(), which is apparently
not available on GL 2.1 / GLSL 1.20:
0:0(0): error: no matching function for call to `mix(vec3, vec3, bvec3)'
0:0(0): error: candidates are: float mix(float, float, float)
0:0(0): error: vec2 mix(vec2, vec2, vec2)
0:0(0): error: vec3 mix(vec3, vec3, vec3)
0:0(0): error: vec4 mix(vec4, vec4, vec4)
0:0(0): error: vec2 mix(vec2, vec2, float)
0:0(0): error: vec3 mix(vec3, vec3, float)
0:0(0): error: vec4 mix(vec4, vec4, float)
Also add back disabling color management on older GL, as the
srgb_compand() function is needed for that.
2012-11-11 23:10:57 +00:00
|
|
|
// Earlier GLSL doesn't support mix() with bvec
|
|
|
|
#if __VERSION__ >= 130
|
2012-11-11 20:09:47 +00:00
|
|
|
vec3 srgb_compand(vec3 v)
|
|
|
|
{
|
2014-02-11 18:20:48 +00:00
|
|
|
return mix(v * 12.92, 1.055 * pow(v, vec3(1.0/2.4)) - vec3(0.055),
|
|
|
|
lessThanEqual(vec3(0.0031308), v));
|
|
|
|
}
|
|
|
|
|
2014-03-25 17:45:08 +00:00
|
|
|
vec3 bt2020_expand(vec3 v)
|
2014-02-11 18:20:48 +00:00
|
|
|
{
|
2014-03-25 17:45:08 +00:00
|
|
|
return mix(v / 4.5, pow((v + vec3(0.0993))/1.0993, vec3(1/0.45)),
|
|
|
|
lessThanEqual(vec3(0.08145), v));
|
2012-11-11 20:09:47 +00:00
|
|
|
}
|
vo_opengl: fix compatibility with OpenGL 2.1
The srgb_compand() function passes bvec to mix(), which is apparently
not available on GL 2.1 / GLSL 1.20:
0:0(0): error: no matching function for call to `mix(vec3, vec3, bvec3)'
0:0(0): error: candidates are: float mix(float, float, float)
0:0(0): error: vec2 mix(vec2, vec2, vec2)
0:0(0): error: vec3 mix(vec3, vec3, vec3)
0:0(0): error: vec4 mix(vec4, vec4, vec4)
0:0(0): error: vec2 mix(vec2, vec2, float)
0:0(0): error: vec3 mix(vec3, vec3, float)
0:0(0): error: vec4 mix(vec4, vec4, float)
Also add back disabling color management on older GL, as the
srgb_compand() function is needed for that.
2012-11-11 23:10:57 +00:00
|
|
|
#endif
|
2012-11-11 20:09:47 +00:00
|
|
|
|
2012-03-30 23:13:38 +00:00
|
|
|
#!section vertex_all
|
2012-10-02 23:54:13 +00:00
|
|
|
|
|
|
|
#if __VERSION__ < 130
|
|
|
|
# undef in
|
|
|
|
# define in attribute
|
|
|
|
# define out varying
|
|
|
|
#endif
|
|
|
|
|
2012-03-30 23:13:38 +00:00
|
|
|
uniform mat3 transform;
|
|
|
|
uniform sampler3D lut_3d;
|
|
|
|
|
|
|
|
in vec2 vertex_position;
|
|
|
|
in vec4 vertex_color;
|
|
|
|
out vec4 color;
|
|
|
|
in vec2 vertex_texcoord;
|
|
|
|
out vec2 texcoord;
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
vec3 position = vec3(vertex_position, 1);
|
|
|
|
#ifndef FIXED_SCALE
|
|
|
|
position = transform * position;
|
|
|
|
#endif
|
|
|
|
gl_Position = vec4(position, 1);
|
|
|
|
color = vertex_color;
|
2012-11-11 20:09:47 +00:00
|
|
|
|
|
|
|
#ifdef USE_OSD_LINEAR_CONV
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
// Although we are not scaling in linear light, both 3DLUT and SRGB still
|
|
|
|
// operate on linear light inputs so we have to convert to it before
|
|
|
|
// either step can be applied.
|
2014-03-25 17:45:08 +00:00
|
|
|
color.rgb = bt2020_expand(color.rgb);
|
|
|
|
// NOTE: This always applies the true BT2020, maybe we need to use
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
// approx-gamma here too?
|
2012-11-11 20:09:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_OSD_3DLUT
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
color.rgb = pow(color.rgb, vec3(1/2.4)); // linear -> 2.4 3DLUT space
|
2012-10-02 23:54:13 +00:00
|
|
|
color = vec4(texture3D(lut_3d, color.rgb).rgb, color.a);
|
2012-03-30 23:13:38 +00:00
|
|
|
#endif
|
2012-11-11 20:09:47 +00:00
|
|
|
#ifdef USE_OSD_SRGB
|
|
|
|
color.rgb = srgb_compand(color.rgb);
|
|
|
|
#endif
|
|
|
|
|
2012-03-30 23:13:38 +00:00
|
|
|
texcoord = vertex_texcoord;
|
|
|
|
}
|
|
|
|
|
2012-09-28 19:25:26 +00:00
|
|
|
#!section frag_osd_libass
|
2013-03-05 22:10:02 +00:00
|
|
|
uniform sampler2D texture0;
|
2012-03-30 23:13:38 +00:00
|
|
|
|
|
|
|
in vec2 texcoord;
|
|
|
|
in vec4 color;
|
2012-10-02 23:54:13 +00:00
|
|
|
DECLARE_FRAGPARMS
|
2012-03-30 23:13:38 +00:00
|
|
|
|
|
|
|
void main() {
|
2013-03-05 22:10:02 +00:00
|
|
|
out_color = vec4(color.rgb, color.a * texture(texture0, texcoord).r);
|
2012-03-30 23:13:38 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 19:25:26 +00:00
|
|
|
#!section frag_osd_rgba
|
2013-03-05 22:10:02 +00:00
|
|
|
uniform sampler2D texture0;
|
2012-03-30 23:13:38 +00:00
|
|
|
|
|
|
|
in vec2 texcoord;
|
2012-10-02 23:54:13 +00:00
|
|
|
DECLARE_FRAGPARMS
|
2012-03-30 23:13:38 +00:00
|
|
|
|
|
|
|
void main() {
|
2013-03-05 22:10:02 +00:00
|
|
|
out_color = texture(texture0, texcoord);
|
2012-09-28 19:25:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 23:13:38 +00:00
|
|
|
#!section frag_video
|
2013-12-01 22:39:13 +00:00
|
|
|
uniform VIDEO_SAMPLER texture0;
|
|
|
|
uniform VIDEO_SAMPLER texture1;
|
|
|
|
uniform VIDEO_SAMPLER texture2;
|
|
|
|
uniform VIDEO_SAMPLER texture3;
|
2013-03-28 20:44:27 +00:00
|
|
|
uniform vec2 textures_size[4];
|
vo_opengl: handle chroma location
Use the video decoder chroma location flags and render chroma locations
other than centered. Until now, we've always used the intuitive and
obvious centered chroma location, but H.264 uses something else.
FFmpeg provides a small overview in libavcodec/avcodec.h:
-----------
/**
* X X 3 4 X X are luma samples,
* 1 2 1-6 are possible chroma positions
* X X 5 6 X 0 is undefined/unknown position
*/
enum AVChromaLocation{
AVCHROMA_LOC_UNSPECIFIED = 0,
AVCHROMA_LOC_LEFT = 1, ///< mpeg2/4, h264 default
AVCHROMA_LOC_CENTER = 2, ///< mpeg1, jpeg, h263
AVCHROMA_LOC_TOPLEFT = 3, ///< DV
AVCHROMA_LOC_TOP = 4,
AVCHROMA_LOC_BOTTOMLEFT = 5,
AVCHROMA_LOC_BOTTOM = 6,
AVCHROMA_LOC_NB , ///< Not part of ABI
};
-----------
The visual difference is literally minimal, but since videophiles
apparently consider this detail as quality mark of a video renderer,
support it anyway. We don't bother with chroma locations other than
centered and left, though.
Not sure about correctness, but it's probably ok.
2013-06-08 00:15:24 +00:00
|
|
|
uniform vec2 chroma_center_offset;
|
2013-12-01 22:39:13 +00:00
|
|
|
uniform vec2 chroma_div;
|
2012-03-30 23:13:38 +00:00
|
|
|
uniform sampler1D lut_c_1d;
|
|
|
|
uniform sampler1D lut_l_1d;
|
|
|
|
uniform sampler2D lut_c_2d;
|
|
|
|
uniform sampler2D lut_l_2d;
|
|
|
|
uniform sampler3D lut_3d;
|
|
|
|
uniform sampler2D dither;
|
|
|
|
uniform mat4x3 colormatrix;
|
2013-05-25 23:48:39 +00:00
|
|
|
uniform mat2 dither_trafo;
|
2012-03-30 23:13:38 +00:00
|
|
|
uniform vec3 inv_gamma;
|
2013-05-01 21:59:00 +00:00
|
|
|
uniform float input_gamma;
|
2012-03-30 23:13:38 +00:00
|
|
|
uniform float conv_gamma;
|
|
|
|
uniform float dither_quantization;
|
2013-05-30 11:36:11 +00:00
|
|
|
uniform float dither_center;
|
2012-03-30 23:13:38 +00:00
|
|
|
uniform float filter_param1;
|
2012-10-02 23:54:13 +00:00
|
|
|
uniform vec2 dither_size;
|
2012-03-30 23:13:38 +00:00
|
|
|
|
|
|
|
in vec2 texcoord;
|
2012-10-02 23:54:13 +00:00
|
|
|
DECLARE_FRAGPARMS
|
2012-03-30 23:13:38 +00:00
|
|
|
|
2013-03-28 20:02:41 +00:00
|
|
|
#define CONV_NV12 1
|
|
|
|
#define CONV_PLANAR 2
|
|
|
|
|
2013-12-01 22:39:13 +00:00
|
|
|
vec4 sample_bilinear(VIDEO_SAMPLER tex, vec2 texsize, vec2 texcoord) {
|
2012-03-30 23:13:38 +00:00
|
|
|
return texture(tex, texcoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Explanation how bicubic scaling with only 4 texel fetches is done:
|
|
|
|
// http://www.mate.tue.nl/mate/pdfs/10318.pdf
|
|
|
|
// 'Efficient GPU-Based Texture Interpolation using Uniform B-Splines'
|
|
|
|
// Explanation why this algorithm normally always blurs, even with unit scaling:
|
|
|
|
// http://bigwww.epfl.ch/preprints/ruijters1001p.pdf
|
|
|
|
// 'GPU Prefilter for Accurate Cubic B-spline Interpolation'
|
|
|
|
vec4 calcweights(float s) {
|
|
|
|
vec4 t = vec4(-0.5, 0.1666, 0.3333, -0.3333) * s + vec4(1, 0, -0.5, 0.5);
|
|
|
|
t = t * s + vec4(0, 0, -0.5, 0.5);
|
|
|
|
t = t * s + vec4(-0.6666, 0, 0.8333, 0.1666);
|
2013-05-30 12:05:33 +00:00
|
|
|
vec2 a = vec2(1, 1) / vec2(t.z, t.w);
|
2012-03-30 23:13:38 +00:00
|
|
|
t.xy = t.xy * a + vec2(1, 1);
|
|
|
|
t.x = t.x + s;
|
|
|
|
t.y = t.y - s;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2013-12-01 22:39:13 +00:00
|
|
|
vec4 sample_bicubic_fast(VIDEO_SAMPLER tex, vec2 texsize, vec2 texcoord) {
|
2012-03-30 23:13:38 +00:00
|
|
|
vec2 pt = 1 / texsize;
|
|
|
|
vec2 fcoord = fract(texcoord * texsize + vec2(0.5, 0.5));
|
|
|
|
vec4 parmx = calcweights(fcoord.x);
|
|
|
|
vec4 parmy = calcweights(fcoord.y);
|
|
|
|
vec4 cdelta;
|
|
|
|
cdelta.xz = parmx.rg * vec2(-pt.x, pt.x);
|
|
|
|
cdelta.yw = parmy.rg * vec2(-pt.y, pt.y);
|
|
|
|
// first y-interpolation
|
|
|
|
vec4 ar = texture(tex, texcoord + cdelta.xy);
|
|
|
|
vec4 ag = texture(tex, texcoord + cdelta.xw);
|
|
|
|
vec4 ab = mix(ag, ar, parmy.b);
|
|
|
|
// second y-interpolation
|
|
|
|
vec4 br = texture(tex, texcoord + cdelta.zy);
|
|
|
|
vec4 bg = texture(tex, texcoord + cdelta.zw);
|
|
|
|
vec4 aa = mix(bg, br, parmy.b);
|
|
|
|
// x-interpolation
|
|
|
|
return mix(aa, ab, parmx.b);
|
|
|
|
}
|
|
|
|
|
|
|
|
float[2] weights2(sampler1D lookup, float f) {
|
2012-10-02 23:54:13 +00:00
|
|
|
vec4 c = texture1D(lookup, f);
|
2012-03-30 23:13:38 +00:00
|
|
|
return float[2](c.r, c.g);
|
|
|
|
}
|
|
|
|
|
|
|
|
float[4] weights4(sampler1D lookup, float f) {
|
2012-10-02 23:54:13 +00:00
|
|
|
vec4 c = texture1D(lookup, f);
|
2012-03-30 23:13:38 +00:00
|
|
|
return float[4](c.r, c.g, c.b, c.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
float[6] weights6(sampler2D lookup, float f) {
|
|
|
|
vec4 c1 = texture(lookup, vec2(0.25, f));
|
|
|
|
vec4 c2 = texture(lookup, vec2(0.75, f));
|
|
|
|
return float[6](c1.r, c1.g, c1.b, c2.r, c2.g, c2.b);
|
|
|
|
}
|
|
|
|
|
|
|
|
float[8] weights8(sampler2D lookup, float f) {
|
|
|
|
vec4 c1 = texture(lookup, vec2(0.25, f));
|
|
|
|
vec4 c2 = texture(lookup, vec2(0.75, f));
|
|
|
|
return float[8](c1.r, c1.g, c1.b, c1.a, c2.r, c2.g, c2.b, c2.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
float[12] weights12(sampler2D lookup, float f) {
|
|
|
|
vec4 c1 = texture(lookup, vec2(1.0/6.0, f));
|
|
|
|
vec4 c2 = texture(lookup, vec2(0.5, f));
|
|
|
|
vec4 c3 = texture(lookup, vec2(5.0/6.0, f));
|
|
|
|
return float[12](c1.r, c1.g, c1.b, c1.a,
|
|
|
|
c2.r, c2.g, c2.b, c2.a,
|
|
|
|
c3.r, c3.g, c3.b, c3.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
float[16] weights16(sampler2D lookup, float f) {
|
|
|
|
vec4 c1 = texture(lookup, vec2(0.125, f));
|
|
|
|
vec4 c2 = texture(lookup, vec2(0.375, f));
|
|
|
|
vec4 c3 = texture(lookup, vec2(0.625, f));
|
|
|
|
vec4 c4 = texture(lookup, vec2(0.875, f));
|
|
|
|
return float[16](c1.r, c1.g, c1.b, c1.a, c2.r, c2.g, c2.b, c2.a,
|
|
|
|
c3.r, c3.g, c3.b, c3.a, c4.r, c4.g, c4.b, c4.a);
|
|
|
|
}
|
|
|
|
|
2012-10-02 23:54:13 +00:00
|
|
|
#define CONVOLUTION_SEP_N(NAME, N) \
|
2013-12-01 22:39:13 +00:00
|
|
|
vec4 NAME(VIDEO_SAMPLER tex, vec2 texcoord, vec2 pt, float weights[N]) {\
|
2012-10-02 23:54:13 +00:00
|
|
|
vec4 res = vec4(0); \
|
|
|
|
for (int n = 0; n < N; n++) { \
|
|
|
|
res += weights[n] * texture(tex, texcoord + pt * n); \
|
|
|
|
} \
|
|
|
|
return res; \
|
2012-03-30 23:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CONVOLUTION_SEP_N(convolution_sep2, 2)
|
|
|
|
CONVOLUTION_SEP_N(convolution_sep4, 4)
|
|
|
|
CONVOLUTION_SEP_N(convolution_sep6, 6)
|
|
|
|
CONVOLUTION_SEP_N(convolution_sep8, 8)
|
|
|
|
CONVOLUTION_SEP_N(convolution_sep12, 12)
|
|
|
|
CONVOLUTION_SEP_N(convolution_sep16, 16)
|
|
|
|
|
|
|
|
// The dir parameter is (0, 1) or (1, 0), and we expect the shader compiler to
|
|
|
|
// remove all the redundant multiplications and additions.
|
|
|
|
#define SAMPLE_CONVOLUTION_SEP_N(NAME, N, SAMPLERT, CONV_FUNC, WEIGHTS_FUNC)\
|
2013-12-01 22:39:13 +00:00
|
|
|
vec4 NAME(vec2 dir, SAMPLERT lookup, VIDEO_SAMPLER tex, vec2 texsize, \
|
2012-10-02 23:54:13 +00:00
|
|
|
vec2 texcoord) { \
|
2012-03-30 23:13:38 +00:00
|
|
|
vec2 pt = (1 / texsize) * dir; \
|
|
|
|
float fcoord = dot(fract(texcoord * texsize - 0.5), dir); \
|
|
|
|
vec2 base = texcoord - fcoord * pt; \
|
|
|
|
return CONV_FUNC(tex, base - pt * (N / 2 - 1), pt, \
|
|
|
|
WEIGHTS_FUNC(lookup, fcoord)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
SAMPLE_CONVOLUTION_SEP_N(sample_convolution_sep2, 2, sampler1D, convolution_sep2, weights2)
|
|
|
|
SAMPLE_CONVOLUTION_SEP_N(sample_convolution_sep4, 4, sampler1D, convolution_sep4, weights4)
|
|
|
|
SAMPLE_CONVOLUTION_SEP_N(sample_convolution_sep6, 6, sampler2D, convolution_sep6, weights6)
|
|
|
|
SAMPLE_CONVOLUTION_SEP_N(sample_convolution_sep8, 8, sampler2D, convolution_sep8, weights8)
|
|
|
|
SAMPLE_CONVOLUTION_SEP_N(sample_convolution_sep12, 12, sampler2D, convolution_sep12, weights12)
|
|
|
|
SAMPLE_CONVOLUTION_SEP_N(sample_convolution_sep16, 16, sampler2D, convolution_sep16, weights16)
|
|
|
|
|
|
|
|
|
|
|
|
#define CONVOLUTION_N(NAME, N) \
|
2013-12-01 22:39:13 +00:00
|
|
|
vec4 NAME(VIDEO_SAMPLER tex, vec2 texcoord, vec2 pt, float taps_x[N], \
|
2012-03-30 23:13:38 +00:00
|
|
|
float taps_y[N]) { \
|
|
|
|
vec4 res = vec4(0); \
|
|
|
|
for (int y = 0; y < N; y++) { \
|
|
|
|
vec4 line = vec4(0); \
|
|
|
|
for (int x = 0; x < N; x++) \
|
|
|
|
line += taps_x[x] * texture(tex, texcoord + pt * vec2(x, y));\
|
|
|
|
res += taps_y[y] * line; \
|
|
|
|
} \
|
|
|
|
return res; \
|
|
|
|
}
|
|
|
|
|
|
|
|
CONVOLUTION_N(convolution2, 2)
|
|
|
|
CONVOLUTION_N(convolution4, 4)
|
|
|
|
CONVOLUTION_N(convolution6, 6)
|
|
|
|
CONVOLUTION_N(convolution8, 8)
|
|
|
|
CONVOLUTION_N(convolution12, 12)
|
|
|
|
CONVOLUTION_N(convolution16, 16)
|
|
|
|
|
|
|
|
#define SAMPLE_CONVOLUTION_N(NAME, N, SAMPLERT, CONV_FUNC, WEIGHTS_FUNC) \
|
2013-12-01 22:39:13 +00:00
|
|
|
vec4 NAME(SAMPLERT lookup, VIDEO_SAMPLER tex, vec2 texsize, vec2 texcoord) {\
|
2012-03-30 23:13:38 +00:00
|
|
|
vec2 pt = 1 / texsize; \
|
|
|
|
vec2 fcoord = fract(texcoord * texsize - 0.5); \
|
|
|
|
vec2 base = texcoord - fcoord * pt; \
|
|
|
|
return CONV_FUNC(tex, base - pt * (N / 2 - 1), pt, \
|
|
|
|
WEIGHTS_FUNC(lookup, fcoord.x), \
|
|
|
|
WEIGHTS_FUNC(lookup, fcoord.y)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
SAMPLE_CONVOLUTION_N(sample_convolution2, 2, sampler1D, convolution2, weights2)
|
|
|
|
SAMPLE_CONVOLUTION_N(sample_convolution4, 4, sampler1D, convolution4, weights4)
|
|
|
|
SAMPLE_CONVOLUTION_N(sample_convolution6, 6, sampler2D, convolution6, weights6)
|
|
|
|
SAMPLE_CONVOLUTION_N(sample_convolution8, 8, sampler2D, convolution8, weights8)
|
|
|
|
SAMPLE_CONVOLUTION_N(sample_convolution12, 12, sampler2D, convolution12, weights12)
|
|
|
|
SAMPLE_CONVOLUTION_N(sample_convolution16, 16, sampler2D, convolution16, weights16)
|
|
|
|
|
|
|
|
|
|
|
|
// Unsharp masking
|
2013-12-01 22:39:13 +00:00
|
|
|
vec4 sample_sharpen3(VIDEO_SAMPLER tex, vec2 texsize, vec2 texcoord) {
|
2012-03-30 23:13:38 +00:00
|
|
|
vec2 pt = 1 / texsize;
|
|
|
|
vec2 st = pt * 0.5;
|
|
|
|
vec4 p = texture(tex, texcoord);
|
|
|
|
vec4 sum = texture(tex, texcoord + st * vec2(+1, +1))
|
|
|
|
+ texture(tex, texcoord + st * vec2(+1, -1))
|
|
|
|
+ texture(tex, texcoord + st * vec2(-1, +1))
|
|
|
|
+ texture(tex, texcoord + st * vec2(-1, -1));
|
|
|
|
return p + (p - 0.25 * sum) * filter_param1;
|
|
|
|
}
|
|
|
|
|
2013-12-01 22:39:13 +00:00
|
|
|
vec4 sample_sharpen5(VIDEO_SAMPLER tex, vec2 texsize, vec2 texcoord) {
|
2012-03-30 23:13:38 +00:00
|
|
|
vec2 pt = 1 / texsize;
|
|
|
|
vec2 st1 = pt * 1.2;
|
|
|
|
vec4 p = texture(tex, texcoord);
|
|
|
|
vec4 sum1 = texture(tex, texcoord + st1 * vec2(+1, +1))
|
|
|
|
+ texture(tex, texcoord + st1 * vec2(+1, -1))
|
|
|
|
+ texture(tex, texcoord + st1 * vec2(-1, +1))
|
|
|
|
+ texture(tex, texcoord + st1 * vec2(-1, -1));
|
|
|
|
vec2 st2 = pt * 1.5;
|
|
|
|
vec4 sum2 = texture(tex, texcoord + st2 * vec2(+1, 0))
|
|
|
|
+ texture(tex, texcoord + st2 * vec2( 0, +1))
|
|
|
|
+ texture(tex, texcoord + st2 * vec2(-1, 0))
|
|
|
|
+ texture(tex, texcoord + st2 * vec2( 0, -1));
|
|
|
|
vec4 t = p * 0.859375 + sum2 * -0.1171875 + sum1 * -0.09765625;
|
|
|
|
return p + t * filter_param1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2013-12-01 22:39:13 +00:00
|
|
|
vec2 chr_texcoord = texcoord;
|
|
|
|
#ifdef USE_RECTANGLE
|
|
|
|
chr_texcoord = chr_texcoord * chroma_div;
|
|
|
|
#else
|
|
|
|
// Texture coordinates are [0,1], and chroma plane coordinates are
|
|
|
|
// magically rescaled.
|
|
|
|
#endif
|
|
|
|
chr_texcoord = chr_texcoord + chroma_center_offset;
|
2013-03-28 22:43:36 +00:00
|
|
|
#ifndef USE_CONV
|
|
|
|
#define USE_CONV 0
|
|
|
|
#endif
|
2013-03-28 20:02:41 +00:00
|
|
|
#if USE_CONV == CONV_PLANAR
|
2013-07-18 11:52:38 +00:00
|
|
|
vec4 acolor = vec4(SAMPLE_L(texture0, textures_size[0], texcoord).r,
|
|
|
|
SAMPLE_C(texture1, textures_size[1], chr_texcoord).r,
|
|
|
|
SAMPLE_C(texture2, textures_size[2], chr_texcoord).r,
|
|
|
|
1.0);
|
2013-03-28 20:02:41 +00:00
|
|
|
#elif USE_CONV == CONV_NV12
|
2013-07-18 11:52:38 +00:00
|
|
|
vec4 acolor = vec4(SAMPLE_L(texture0, textures_size[0], texcoord).r,
|
|
|
|
SAMPLE_C(texture1, textures_size[1], chr_texcoord).rg,
|
|
|
|
1.0);
|
2012-03-30 23:13:38 +00:00
|
|
|
#else
|
2013-04-29 22:52:32 +00:00
|
|
|
vec4 acolor = SAMPLE_L(texture0, textures_size[0], texcoord);
|
2013-03-28 20:44:27 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_ALPHA_PLANE
|
2013-07-18 11:52:38 +00:00
|
|
|
acolor.a = SAMPLE_L(texture3, textures_size[3], texcoord).r;
|
2012-03-30 23:13:38 +00:00
|
|
|
#endif
|
2013-07-18 11:52:38 +00:00
|
|
|
#ifdef USE_COLOR_SWIZZLE
|
|
|
|
acolor = acolor. USE_COLOR_SWIZZLE ;
|
2013-03-28 20:02:48 +00:00
|
|
|
#endif
|
2013-07-18 11:52:38 +00:00
|
|
|
vec3 color = acolor.rgb;
|
|
|
|
float alpha = acolor.a;
|
2012-03-30 23:13:38 +00:00
|
|
|
#ifdef USE_YGRAY
|
|
|
|
// NOTE: actually slightly wrong for 16 bit input video, and completely
|
|
|
|
// wrong for 9/10 bit input
|
|
|
|
color.gb = vec2(128.0/255.0);
|
|
|
|
#endif
|
2013-05-01 21:59:00 +00:00
|
|
|
#ifdef USE_INPUT_GAMMA
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
// Pre-colormatrix input gamma correction (eg. for MP_IMGFLAG_XYZ)
|
2013-05-01 21:59:00 +00:00
|
|
|
color = pow(color, vec3(input_gamma));
|
|
|
|
#endif
|
2012-03-30 23:13:38 +00:00
|
|
|
#ifdef USE_COLORMATRIX
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
// Conversion from Y'CbCr or other spaces to RGB
|
2012-03-30 23:13:38 +00:00
|
|
|
color = mat3(colormatrix) * color + colormatrix[3];
|
2013-05-31 19:28:13 +00:00
|
|
|
color = clamp(color, 0, 1);
|
2012-03-30 23:13:38 +00:00
|
|
|
#endif
|
2013-05-01 21:59:00 +00:00
|
|
|
#ifdef USE_CONV_GAMMA
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
// Post-colormatrix converted gamma correction (eg. for MP_IMGFLAG_XYZ)
|
2013-05-01 21:59:00 +00:00
|
|
|
color = pow(color, vec3(conv_gamma));
|
2012-03-30 23:13:38 +00:00
|
|
|
#endif
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
#ifdef USE_LINEAR_LIGHT
|
|
|
|
// If we are scaling in linear light (SRGB or 3DLUT option enabled), we
|
2014-03-25 17:45:08 +00:00
|
|
|
// expand our source colors before scaling. This shader currently just
|
|
|
|
// assumes everything uses the BT.2020 12-bit gamma function, since the
|
|
|
|
// difference between this and BT.601, BT.709 and BT.2020 10-bit is well
|
|
|
|
// below the rounding error threshold for both 8-bit and even 10-bit
|
|
|
|
// content. It only makes a difference for 12-bit sources, so it should be
|
|
|
|
// fine to use here.
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
#ifdef USE_APPROX_GAMMA
|
2014-03-25 17:45:08 +00:00
|
|
|
// We differentiate between approximate BT.2020 (gamma 1.95) ...
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
color = pow(color, vec3(1.95));
|
|
|
|
#else
|
2014-03-25 17:45:08 +00:00
|
|
|
// ... and actual BT.2020 (two-part function)
|
|
|
|
color = bt2020_expand(color);
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
#endif
|
2012-03-30 23:13:38 +00:00
|
|
|
#endif
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
// Image upscaling happens roughly here
|
2012-03-30 23:13:38 +00:00
|
|
|
#ifdef USE_GAMMA_POW
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
// User-defined gamma correction factor (via the gamma sub-option)
|
2012-03-30 23:13:38 +00:00
|
|
|
color = pow(color, inv_gamma);
|
|
|
|
#endif
|
|
|
|
#ifdef USE_3DLUT
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
// For the 3DLUT we are arbitrarily using 2.4 as input gamma to reduce
|
|
|
|
// the amount of rounding errors, so we pull up to that space first and
|
|
|
|
// then pass it through the 3D texture.
|
|
|
|
color = pow(color, vec3(1/2.4));
|
2012-10-02 23:54:13 +00:00
|
|
|
color = texture3D(lut_3d, color).rgb;
|
2012-03-30 23:13:38 +00:00
|
|
|
#endif
|
2012-11-10 18:08:21 +00:00
|
|
|
#ifdef USE_SRGB
|
vo_opengl: Simplify and clarify color correction code
This commit:
- Changes some of the #define and variable names for clarification and
adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
the decoding process and removing the weird interactions between both
of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
cases, making it happen before upscaling (instead of the old 0.45
gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
pretty arbitrary factor but I picked 2.4 mainly because a higher pure
power value here seems to produce visually better results with wide
gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
it more in the future, or even make it user customizable (though I
don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
behavior from circa a year ago.
This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.
I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.
Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.
Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.
Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-05 02:56:30 +00:00
|
|
|
// Compand from the linear scaling gamma to the sRGB output gamma
|
|
|
|
color = srgb_compand(color.rgb);
|
2012-11-10 18:08:21 +00:00
|
|
|
#endif
|
2012-03-30 23:13:38 +00:00
|
|
|
#ifdef USE_DITHER
|
2013-05-25 23:48:39 +00:00
|
|
|
vec2 dither_pos = gl_FragCoord.xy / dither_size;
|
|
|
|
#ifdef USE_TEMPORAL_DITHER
|
|
|
|
dither_pos = dither_trafo * dither_pos;
|
|
|
|
#endif
|
|
|
|
float dither_value = texture(dither, dither_pos).r;
|
2013-05-30 11:36:11 +00:00
|
|
|
color = floor(color * dither_quantization + dither_value + dither_center) /
|
|
|
|
dither_quantization;
|
2012-03-30 23:13:38 +00:00
|
|
|
#endif
|
2013-09-19 14:55:56 +00:00
|
|
|
#ifdef USE_ALPHA_BLEND
|
|
|
|
color = color * alpha;
|
|
|
|
#endif
|
2013-03-28 20:44:27 +00:00
|
|
|
#ifdef USE_ALPHA
|
|
|
|
out_color = vec4(color, alpha);
|
|
|
|
#else
|
|
|
|
out_color = vec4(color, 1.0);
|
|
|
|
#endif
|
2012-03-30 23:13:38 +00:00
|
|
|
}
|