opengl_enc_shaders.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 2014 Lukasz Marek
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVDEVICE_OPENGL_ENC_SHADERS_H
  21. #define AVDEVICE_OPENGL_ENC_SHADERS_H
  22. #include "libavutil/pixfmt.h"
  23. static const char * const FF_OPENGL_VERTEX_SHADER =
  24. "uniform mat4 u_projectionMatrix;"
  25. "uniform mat4 u_modelViewMatrix;"
  26. "attribute vec4 a_position;"
  27. "attribute vec2 a_textureCoords;"
  28. "varying vec2 texture_coordinate;"
  29. "void main()"
  30. "{"
  31. "gl_Position = u_projectionMatrix * (a_position * u_modelViewMatrix);"
  32. "texture_coordinate = a_textureCoords;"
  33. "}";
  34. /**
  35. * Fragment shader for packet RGBA formats.
  36. */
  37. static const char * const FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET =
  38. #if defined(GL_ES_VERSION_2_0)
  39. "precision mediump float;"
  40. #endif
  41. "uniform sampler2D u_texture0;"
  42. "uniform mat4 u_colorMap;"
  43. "varying vec2 texture_coordinate;"
  44. "void main()"
  45. "{"
  46. "gl_FragColor = texture2D(u_texture0, texture_coordinate) * u_colorMap;"
  47. "}";
  48. /**
  49. * Fragment shader for packet RGB formats.
  50. */
  51. static const char * const FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET =
  52. #if defined(GL_ES_VERSION_2_0)
  53. "precision mediump float;"
  54. #endif
  55. "uniform sampler2D u_texture0;"
  56. "uniform mat4 u_colorMap;"
  57. "varying vec2 texture_coordinate;"
  58. "void main()"
  59. "{"
  60. "gl_FragColor = vec4((texture2D(u_texture0, texture_coordinate) * u_colorMap).rgb, 1.0);"
  61. "}";
  62. /**
  63. * Fragment shader for planar RGBA formats.
  64. */
  65. static const char * const FF_OPENGL_FRAGMENT_SHADER_RGBA_PLANAR =
  66. #if defined(GL_ES_VERSION_2_0)
  67. "precision mediump float;"
  68. #endif
  69. "uniform sampler2D u_texture0;"
  70. "uniform sampler2D u_texture1;"
  71. "uniform sampler2D u_texture2;"
  72. "uniform sampler2D u_texture3;"
  73. "varying vec2 texture_coordinate;"
  74. "void main()"
  75. "{"
  76. "gl_FragColor = vec4(texture2D(u_texture0, texture_coordinate).r,"
  77. "texture2D(u_texture1, texture_coordinate).r,"
  78. "texture2D(u_texture2, texture_coordinate).r,"
  79. "texture2D(u_texture3, texture_coordinate).r);"
  80. "}";
  81. /**
  82. * Fragment shader for planar RGB formats.
  83. */
  84. static const char * const FF_OPENGL_FRAGMENT_SHADER_RGB_PLANAR =
  85. #if defined(GL_ES_VERSION_2_0)
  86. "precision mediump float;"
  87. #endif
  88. "uniform sampler2D u_texture0;"
  89. "uniform sampler2D u_texture1;"
  90. "uniform sampler2D u_texture2;"
  91. "varying vec2 texture_coordinate;"
  92. "void main()"
  93. "{"
  94. "gl_FragColor = vec4(texture2D(u_texture0, texture_coordinate).r,"
  95. "texture2D(u_texture1, texture_coordinate).r,"
  96. "texture2D(u_texture2, texture_coordinate).r,"
  97. "1.0);"
  98. "}";
  99. /**
  100. * Fragment shader for planar YUV formats.
  101. */
  102. static const char * const FF_OPENGL_FRAGMENT_SHADER_YUV_PLANAR =
  103. #if defined(GL_ES_VERSION_2_0)
  104. "precision mediump float;"
  105. #endif
  106. "uniform sampler2D u_texture0;"
  107. "uniform sampler2D u_texture1;"
  108. "uniform sampler2D u_texture2;"
  109. "uniform float u_chroma_div_w;"
  110. "uniform float u_chroma_div_h;"
  111. "varying vec2 texture_coordinate;"
  112. "void main()"
  113. "{"
  114. "vec3 yuv;"
  115. "yuv.r = texture2D(u_texture0, texture_coordinate).r - 0.0625;"
  116. "yuv.g = texture2D(u_texture1, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
  117. "yuv.b = texture2D(u_texture2, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
  118. "gl_FragColor = clamp(vec4(mat3(1.1643, 1.16430, 1.1643,"
  119. "0.0, -0.39173, 2.0170,"
  120. "1.5958, -0.81290, 0.0) * yuv, 1.0), 0.0, 1.0);"
  121. "}";
  122. /**
  123. * Fragment shader for planar YUVA formats.
  124. */
  125. static const char * const FF_OPENGL_FRAGMENT_SHADER_YUVA_PLANAR =
  126. #if defined(GL_ES_VERSION_2_0)
  127. "precision mediump float;"
  128. #endif
  129. "uniform sampler2D u_texture0;"
  130. "uniform sampler2D u_texture1;"
  131. "uniform sampler2D u_texture2;"
  132. "uniform sampler2D u_texture3;"
  133. "uniform float u_chroma_div_w;"
  134. "uniform float u_chroma_div_h;"
  135. "varying vec2 texture_coordinate;"
  136. "void main()"
  137. "{"
  138. "vec3 yuv;"
  139. "yuv.r = texture2D(u_texture0, texture_coordinate).r - 0.0625;"
  140. "yuv.g = texture2D(u_texture1, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
  141. "yuv.b = texture2D(u_texture2, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
  142. "gl_FragColor = clamp(vec4(mat3(1.1643, 1.16430, 1.1643,"
  143. "0.0, -0.39173, 2.0170,"
  144. "1.5958, -0.81290, 0.0) * yuv, texture2D(u_texture3, texture_coordinate).r), 0.0, 1.0);"
  145. "}";
  146. static const char * const FF_OPENGL_FRAGMENT_SHADER_GRAY =
  147. #if defined(GL_ES_VERSION_2_0)
  148. "precision mediump float;"
  149. #endif
  150. "uniform sampler2D u_texture0;"
  151. "varying vec2 texture_coordinate;"
  152. "void main()"
  153. "{"
  154. "float c = texture2D(u_texture0, texture_coordinate).r;"
  155. "gl_FragColor = vec4(c, c, c, 1.0);"
  156. "}";
  157. #endif /* AVDEVICE_OPENGL_ENC_SHADERS_H */