summaryrefslogtreecommitdiffstats
path: root/video/out/gl_video_shaders.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'video/out/gl_video_shaders.glsl')
-rw-r--r--video/out/gl_video_shaders.glsl16
1 files changed, 16 insertions, 0 deletions
diff --git a/video/out/gl_video_shaders.glsl b/video/out/gl_video_shaders.glsl
index bb6530295f..ff2a019b30 100644
--- a/video/out/gl_video_shaders.glsl
+++ b/video/out/gl_video_shaders.glsl
@@ -43,6 +43,12 @@
// Earlier GLSL doesn't support mix() with bvec
#if __VERSION__ >= 130
+vec3 srgb_expand(vec3 v)
+{
+ return mix(v / 12.92, pow((v + vec3(0.055))/1.055, vec3(2.4)),
+ lessThanEqual(vec3(0.04045), v));
+}
+
vec3 srgb_compand(vec3 v)
{
return mix(v * 12.92, 1.055 * pow(v, vec3(1.0/2.4)) - 0.055,
@@ -98,6 +104,9 @@ void main() {
#ifdef USE_OSD_LINEAR_CONV_BT2020
color.rgb = bt2020_expand(color.rgb);
#endif
+#ifdef USE_OSD_LINEAR_CONV_SRGB
+ color.rgb = srgb_expand(color.rgb);
+#endif
#ifdef USE_OSD_CMS_MATRIX
// Convert to the right target gamut first (to BT.709 for sRGB,
// and to BT.2020 for 3DLUT). Normal clamping here as perceptually
@@ -439,6 +448,13 @@ void main() {
// ... and actual BT.2020 (two-part function)
color = bt2020_expand(color);
#endif
+#ifdef USE_LINEAR_LIGHT_SRGB
+ // This is not needed for most sRGB content since we can use GL_SRGB to
+ // directly sample RGB texture in linear light, but for things which are
+ // also sRGB but in a different format (such as JPEG's YUV), we need
+ // to convert to linear light manually.
+ color = srgb_expand(color);
+#endif
#ifdef USE_CONST_LUMA
// Calculate the green channel from the expanded RYcB
// The BT.2020 specification says Yc = 0.2627*R + 0.6780*G + 0.0593*B