Created
July 10, 2018 20:20
-
-
Save Waelwindows/7b0506c6411c6409e06af647a797f4ee to your computer and use it in GitHub Desktop.
GLSL code for converting between RGB and YCbCr (DIVA Edition)
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
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
// Normalized pixel coordinates (from 0 to 1) | |
vec2 uv = fragCoord/iResolution.xy; | |
vec4 col = texture(iChannel2, uv); | |
vec2 mip1 = texture(iChannel0, uv).xy; | |
vec2 mip2 = texture(iChannel1, uv).xy; | |
mat3 yMat = mat3(1., 0., 1.5748, | |
1., -.1873, -.4681, | |
1., 1.8556, 0.); | |
mat3 rMat = mat3(.2126, .7152, .0722, | |
-.1146,-.3854, .5, | |
.5,-.4542,-.0458); | |
//YCbCr 2 RGB | |
vec3 final = vec3(mip1.g, mip2.r-.5, mip2.g-.5) * yMat; | |
final = final.zyx; | |
//RGB 2 YCbCr | |
vec3 final2 = col.zyx * rMat; | |
final2.gb += .5; | |
//Outputs | |
vec2 alum = vec2(col.a, final2.r); | |
vec2 cbr = vec2(final2.g, final2.b); | |
fragColor.xyz = vec4(alum, 1,1.0).xyz; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment