diff options
author | Mikhail Burakov <mburakov@mailbox.org> | 2023-03-19 12:30:24 +0100 |
---|---|---|
committer | Mikhail Burakov <mburakov@mailbox.org> | 2023-03-19 12:30:24 +0100 |
commit | 1b00a18b7c50e54928dcd273d2b6800f0c0a24f0 (patch) | |
tree | f35e56f52bb76cbd847c758353eacd382ca9079b /chroma.glsl | |
parent | 85c81156a37e161ca08831b9ac9af022c72ebdea (diff) |
Add colorspace and ranges handling to streamer
Diffstat (limited to 'chroma.glsl')
-rw-r--r-- | chroma.glsl | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/chroma.glsl b/chroma.glsl index 9004793..dd103b1 100644 --- a/chroma.glsl +++ b/chroma.glsl @@ -16,27 +16,26 @@ */ uniform sampler2D img_input; -uniform mediump vec2 chroma_offsets; +uniform mediump vec2 sample_offsets[4]; +uniform mediump mat3 colorspace; +uniform mediump vec3 ranges[2]; varying mediump vec2 texcoord; -mediump vec2 rgb2chroma(in mediump vec4 rgb) { - // mburakov: This hardcodes BT.709 full-range. - mediump float y = rgb.r * 0.2126 + rgb.g * 0.7152 + rgb.b * 0.0722; - mediump float u = (rgb.b - y) / (2.0 * (1.0 - 0.0722)); - mediump float v = (rgb.r - y) / (2.0 * (1.0 - 0.2126)); - return vec2(u + 0.5, v + 0.5); +mediump vec4 supersample() { + return texture2D(img_input, texcoord + sample_offsets[0]) + + texture2D(img_input, texcoord + sample_offsets[1]) + + texture2D(img_input, texcoord + sample_offsets[2]) + + texture2D(img_input, texcoord + sample_offsets[3]); +} + +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 vec2 sample_points[4]; - sample_points[0] = texcoord; - sample_points[1] = texcoord + vec2(chroma_offsets.x, 0.0); - sample_points[2] = texcoord + vec2(0.0, chroma_offsets.y); - sample_points[3] = texcoord + chroma_offsets; - mediump vec4 rgb = texture2D(img_input, sample_points[0]) + - texture2D(img_input, sample_points[1]) + - texture2D(img_input, sample_points[2]) + - texture2D(img_input, sample_points[3]); - gl_FragColor = vec4(rgb2chroma(rgb / 4.0), 0.0, 1.0); + mediump vec4 rgb = supersample() / 4.0; + mediump vec3 yuv = rgb2yuv(rgb.rgb); + gl_FragColor = vec4(yuv.yz, 0.0, 1.0); } |