From 5e060d3d29d0d4f53b44a25ef31eb0cbcf6d4030 Mon Sep 17 00:00:00 2001 From: Troy James Sobotka Date: Sun, 28 Apr 2019 10:42:51 -0700 Subject: [PATCH] Update to REC.709, not batshit crazy REC.601 Update to use REC.709 coefficients. --- effects/shaders/chromakey.frag | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/effects/shaders/chromakey.frag b/effects/shaders/chromakey.frag index 4f57d8b1e..98c77dc7a 100644 --- a/effects/shaders/chromakey.frag +++ b/effects/shaders/chromakey.frag @@ -15,17 +15,24 @@ uniform int mode; float rgb2y (vec3 c) { /*a utility function to convert colors in RGB into YCbCr*/ - return (0.299*c.r + 0.587*c.g + 0.114*c.b); + +// This isn’t colour managed and is a huge mess, but in the +// short term, using correct weights will give significantly +// more ideal results. The correct weights for REC.709 are +// 0.2126 R, 0.7152 G, and 0.722 B. Easy change. +// The coefficients for YCbCr are calculated off of the +// REC.709 values. + return (0.2126*c.r + 0.7152*c.g + 0.0.722*c.b); } float rgb2cb (vec3 c) { /*a utility function to convert colors in RGB into YCbCr*/ - return (0.5 + -0.168736*c.r - 0.331264*c.g + 0.5*c.b); + return (0.5 + -0.1145721061*c.r - 0.3854278939*c.g + 0.5*c.b); } float rgb2cr (vec3 c) { /*a utility function to convert colors in RGB into YCbCr*/ - return (0.5 + 0.5*c.r - 0.418688*c.g - 0.081312*c.b); + return (0.5 + 0.5*c.r - 0.4541529083*c.g - 0.0458470917*c.b); } float colorclose(float Cb_p,float Cr_p,float Cb_key,float Cr_key,float tola,float tolb) { @@ -62,4 +69,4 @@ void main(void) { } gl_FragColor = texture_color; -} \ No newline at end of file +}