ShaderSources.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @type {{type: string, source: string}}
  3. */
  4. export const vertexQuad = {
  5. type: 'x-shader/x-vertex',
  6. source: `
  7. precision mediump float;
  8. uniform mat4 u_projection;
  9. attribute vec2 a_position;
  10. attribute vec2 a_texCoord;
  11. varying vec2 v_texCoord;
  12. void main(){
  13. v_texCoord = a_texCoord;
  14. gl_Position = u_projection * vec4(a_position, 0.0, 1.0);
  15. }
  16. `
  17. }
  18. /**
  19. * @type {{type: string, source: string}}
  20. */
  21. export const fragmentYUV = {
  22. type: 'x-shader/x-fragment',
  23. source: `
  24. precision lowp float;
  25. varying vec2 v_texCoord;
  26. uniform sampler2D yTexture;
  27. uniform sampler2D uTexture;
  28. uniform sampler2D vTexture;
  29. const mat4 conversion = mat4(
  30. 1.0, 0.0, 1.402, -0.701,
  31. 1.0, -0.344, -0.714, 0.529,
  32. 1.0, 1.772, 0.0, -0.886,
  33. 0.0, 0.0, 0.0, 0.0
  34. );
  35. void main(void) {
  36. float yChannel = texture2D(yTexture, v_texCoord).x;
  37. float uChannel = texture2D(uTexture, v_texCoord).x;
  38. float vChannel = texture2D(vTexture, v_texCoord).x;
  39. vec4 channels = vec4(yChannel, uChannel, vChannel, 1.0);
  40. vec3 rgb = (channels * conversion).xyz;
  41. gl_FragColor = vec4(rgb, 1.0);
  42. }
  43. `
  44. }