summaryrefslogtreecommitdiff
path: root/luma.glsl
diff options
context:
space:
mode:
authorMikhail Burakov <mburakov@mailbox.org>2023-03-19 12:30:24 +0100
committerMikhail Burakov <mburakov@mailbox.org>2023-03-19 12:30:24 +0100
commit1b00a18b7c50e54928dcd273d2b6800f0c0a24f0 (patch)
treef35e56f52bb76cbd847c758353eacd382ca9079b /luma.glsl
parent85c81156a37e161ca08831b9ac9af022c72ebdea (diff)
Add colorspace and ranges handling to streamer
Diffstat (limited to 'luma.glsl')
-rw-r--r--luma.glsl11
1 files changed, 7 insertions, 4 deletions
diff --git a/luma.glsl b/luma.glsl
index cc56377..4dac957 100644
--- a/luma.glsl
+++ b/luma.glsl
@@ -16,15 +16,18 @@
*/
uniform sampler2D img_input;
+uniform mediump mat3 colorspace;
+uniform mediump vec3 ranges[2];
varying mediump vec2 texcoord;
-mediump float rgb2luma(in mediump vec4 rgb) {
- // mburakov: This hardcodes BT.709 full-range.
- return rgb.r * 0.2126 + rgb.g * 0.7152 + rgb.b * 0.0722;
+mediump vec3 rgb2yuv(in mediump vec3 rgb) {
+ mediump vec3 yuv = colorspace * rgb.rgb + vec3(0.0, 0.5, 0.5);
+ return ranges[0] + yuv * ranges[1];
}
void main() {
mediump vec4 rgb = texture2D(img_input, texcoord);
- gl_FragColor = vec4(rgb2luma(rgb), 0.0, 0.0, 1.0);
+ mediump vec3 yuv = rgb2yuv(rgb.rgb);
+ gl_FragColor = vec4(yuv.x, 0.0, 0.0, 1.0);
}