thebookofshaders/08/yuv.frag

35 lines
921 B
GLSL
Raw Normal View History

2015-03-15 15:35:14 +00:00
// Author @patriciogv - 2015
// http://patriciogonzalezvivo.com
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform float u_time;
2015-06-02 10:29:49 +00:00
// YUV to RGB matrix
2015-03-15 15:35:14 +00:00
mat3 yuv2rgb = mat3(1.0, 0.0, 1.13983,
1.0, -0.39465, -0.58060,
1.0, 2.03211, 0.0);
2015-06-02 10:29:49 +00:00
// RGB to YUV matrix
2015-03-15 15:35:14 +00:00
mat3 rgb2yuv = mat3(0.2126, 0.7152, 0.0722,
-0.09991, -0.33609, 0.43600,
0.615, -0.5586, -0.05639);
void main(){
vec2 st = gl_FragCoord.xy/u_resolution;
vec3 color = vec3(0.0);
2015-06-02 10:29:49 +00:00
// UV values goes from -1 to 1
// So we need to remap st (0.0 to 1.0)
st -= 0.5; // becomes -0.5 to 0.5
st *= 2.0; // becomes -1.0 to 1.0
// we pass st as the y & z values of
// a three dimentional vector to be
// properly multiply by a 3x3 matrix
2015-03-15 15:35:14 +00:00
color = yuv2rgb * vec3(0.5, st.x, st.y);
gl_FragColor = vec4(color,1.0);
}