Guest User

fragment.glsl

a guest
Jul 21st, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // fragment.glsl
  2. #version 400
  3.  
  4. uniform usampler2D yuvTexture;
  5.  
  6. in vec4 texcoord;
  7.  
  8. out vec4 frag_color;
  9.  
  10. const mat3 HDTV = mat3(1.0,    1.0,   1.0,
  11.                        0.0,   -0.187, 1.856,
  12.                        1.575, -0.468, 0.0);
  13.                        
  14. // Constants needed to extract YUV planes from the texture
  15. const float YHeight = 2.0 / 3.0;
  16. const float UHeight = 1.0 / 6.0;
  17. const float VHeight = UHeight;
  18. const float UOffset = YHeight;
  19. const float VOffset = UOffset + UHeight;
  20.  
  21. void main()
  22. {
  23.     // Extract the YUV planes from texture
  24.     float y = (float(texture(yuvTexture, vec2(texcoord.s, texcoord.t * YHeight)).r) - 64) / 876.0;
  25.     float u = (float(texture(yuvTexture, vec2(texcoord.s / 2, UOffset + texcoord.t * UHeight)).r) - 512) / 896.0;
  26.     float v = (float(texture(yuvTexture, vec2(texcoord.s / 2, VOffset + texcoord.t * VHeight)).r) - 512) / 896.0;
  27.  
  28.     frag_color = vec4(HDTV * vec3(y, u, v), 1.0);
  29.     //frag_color = vec4(texcoord.stp, 1.0);
  30. }
Add Comment
Please, Sign In to add comment