render: convert yuv to rgb on gpu

Huge performance improvement
This commit is contained in:
itsmattkc
2022-05-30 15:34:38 -07:00
parent 930848e07a
commit d28202a2db
2 changed files with 135 additions and 12 deletions
+35
View File
@@ -0,0 +1,35 @@
uniform sampler2D y_channel;
uniform sampler2D u_channel;
uniform sampler2D v_channel;
uniform int bits_per_pixel;
in vec2 ove_texcoord;
out vec4 frag_color;
void main() {
vec4 rgba;
vec3 yuv;
yuv.r = texture(y_channel, ove_texcoord).r;
yuv.g = texture(u_channel, ove_texcoord).r;
yuv.b = texture(v_channel, ove_texcoord).r;
if (bits_per_pixel == 10) {
yuv *= 64.0;
} else if (bits_per_pixel == 12) {
yuv *= 16.0;
}
yuv.r = 1.1643 * (yuv.r - 0.0625);
yuv.g = yuv.g - 0.5;
yuv.b = yuv.b - 0.5;
rgba.r = yuv.r + 1.5958 * yuv.b;
rgba.g = yuv.r - 0.39173 * yuv.g - 0.81290 * yuv.b;
rgba.b = yuv.r + 2.017 * yuv.g;
rgba.a = 1.0;
frag_color = rgba;
}