Skip to content

Instantly share code, notes, and snippets.

@ithmz
Created February 19, 2020 02:25
Show Gist options
  • Save ithmz/18fa42ed46a3cad367241c239b7b3adb to your computer and use it in GitHub Desktop.
Save ithmz/18fa42ed46a3cad367241c239b7b3adb to your computer and use it in GitHub Desktop.
Fragment shader to convert YUV420SP (a.k.a NV12 or NV21) to RGB
#version 330 core
out vec4 FragColor;
in vec2 texCoord;
uniform sampler2D textureY;
uniform sampler2D textureVU;
void main()
{
vec3 yuv, rgb;
vec3 yuv2r = vec3(1.164, 0.0, 1.596);
vec3 yuv2g = vec3(1.164, -0.391, -0.813);
vec3 yuv2b = vec3(1.164, 2.018, 0.0);
yuv.x = texture(textureY, texCoord).r - 0.0625;
yuv.y = texture(textureVU, texCoord).g - 0.5;
yuv.z = texture(textureVU, texCoord).r - 0.5;
rgb.x = dot(yuv, yuv2r);
rgb.y = dot(yuv, yuv2g);
rgb.z = dot(yuv, yuv2b);
FragColor = vec4(rgb, 1.0);
}
@ithmz
Copy link
Author

ithmz commented Dec 7, 2020

@refvalue
Copy link

Appreciate it!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment