Created
February 19, 2020 02:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AhmedX6 https://gist.github.com/tsangz189/1b58f2df84024cf780add1f9fd6f6aaa