Go to the documentation of this file. 1 #ifndef MYTH_OPENGLVIDEOSHADERS_H
2 #define MYTH_OPENGLVIDEOSHADERS_H
7 "attribute highp vec2 a_position;\n"
8 "attribute highp vec2 a_texcoord0;\n"
9 "varying highp vec2 v_texcoord0;\n"
10 "uniform highp mat4 u_projection;\n"
13 " gl_Position = u_projection * vec4(a_position, 0.0, 1.0);\n"
14 " v_texcoord0 = a_texcoord0;\n"
18 "uniform sampler2D s_texture0;\n"
19 "varying highp vec2 v_texcoord0;\n"
22 " highp vec4 color = texture2D(s_texture0, v_texcoord0);\n"
23 " gl_FragColor = vec4(color.rgb, 1.0);\n"
26 #ifdef USING_MEDIACODEC
27 static const QString MediaCodecVertexShader =
28 "attribute highp vec2 a_position;\n"
29 "attribute highp vec2 a_texcoord0;\n"
30 "varying highp vec2 v_texcoord0;\n"
31 "uniform highp mat4 u_projection;\n"
32 "uniform highp mat4 u_transform;\n"
35 " gl_Position = u_projection * vec4(a_position, 0.0, 1.0);\n"
36 " v_texcoord0 = (u_transform * vec4(a_texcoord0, 0.0, 1.0)).xy;\n"
42 "#define LINEHEIGHT m_frameData.x\n"
43 "#define COLUMN m_frameData.y\n"
44 "#define MAXHEIGHT m_frameData.z\n"
45 "#define FIELDSIZE m_frameData.w\n"
46 "#ifdef MYTHTV_RECTS\n"
47 "#extension GL_ARB_texture_rectangle : enable\n"
48 "#define texture2D texture2DRect\n"
49 "#define sampler2D sampler2DRect\n"
51 "#ifdef MYTHTV_EXTOES\n"
52 "#extension GL_OES_EGL_image_external : require\n"
53 "#define sampler2D samplerExternalOES\n"
57 "uniform highp mat4 m_colourMatrix;\n"
58 "uniform highp vec4 m_frameData;\n"
59 "varying highp vec2 v_texcoord0;\n"
60 "#ifdef MYTHTV_COLOURMAPPING\n"
61 "uniform highp mat4 m_primaryMatrix;\n"
62 "uniform highp float m_colourGamma;\n"
63 "uniform highp float m_displayGamma;\n"
64 "highp vec4 ColourMap(highp vec4 color)\n"
66 " highp vec4 res = clamp(color, 0.0, 1.0);\n"
67 " res.rgb = pow(res.rgb, vec3(m_colourGamma));\n"
68 " res = m_primaryMatrix * res;\n"
69 " return vec4(pow(res.rgb, vec3(m_displayGamma)), res.a);\n"
80 "highp vec2 chromaLocation(highp vec2 xy)\n"
83 " highp float temp = xy.y * FIELDSIZE;\n"
84 " highp float onetwo = min((floor(temp / 2.0) / (FIELDSIZE / 2.0)) + LINEHEIGHT, MAXHEIGHT);\n"
85 "#ifdef MYTHTV_CHROMALEFT\n"
86 " return vec2(xy.x + (0.5 / COLUMN), mix(onetwo, min(onetwo + (2.0 * LINEHEIGHT), MAXHEIGHT), step(0.5, fract(temp))));\n"
88 " return vec2(xy.x, mix(onetwo, min(onetwo + (2.0 * LINEHEIGHT), MAXHEIGHT), step(0.5, fract(temp))));\n"
91 "#ifdef MYTHTV_CHROMALEFT\n"
92 " return vec2(xy.x + (0.5 / COLUMN), xy.y);\n"
99 "#ifdef MYTHTV_NV12\n"
100 "highp vec4 sampleYUV(in sampler2D texture1, in sampler2D texture2, highp vec2 texcoord)\n"
102 "#ifdef MYTHTV_RECTS\n"
103 " return vec4(texture2D(texture1, texcoord).r, texture2D(texture2, chromaLocation(texcoord) * vec2(0.5, 0.5)).rg, 1.0);\n"
105 " return vec4(texture2D(texture1, texcoord).r, texture2D(texture2, chromaLocation(texcoord)).rg, 1.0);\n"
110 "#ifdef MYTHTV_YV12\n"
111 "highp vec4 sampleYUV(in sampler2D texture1, in sampler2D texture2, in sampler2D texture3, highp vec2 texcoord)\n"
113 " highp vec2 chroma = chromaLocation(texcoord);\n"
114 " return vec4(texture2D(texture1, texcoord).r,\n"
115 " texture2D(texture2, chroma).r,\n"
116 " texture2D(texture3, chroma).r,\n"
121 "#ifdef MYTHTV_YUY2\n"
122 "highp vec4 sampleYUV(in sampler2D texture1, highp vec2 texcoord)\n"
124 " return texture2D(texture1, texcoord);\n"
128 "#ifdef MYTHTV_KERNEL\n"
129 "highp vec4 kernel(in highp vec4 yuv, sampler2D kernelTex0, sampler2D kernelTex1)\n"
131 " highp vec2 twoup = vec2(v_texcoord0.x, max(v_texcoord0.y - (2.0 * LINEHEIGHT), LINEHEIGHT));\n"
132 " highp vec2 twodown = vec2(v_texcoord0.x, min(v_texcoord0.y + (2.0 * LINEHEIGHT), MAXHEIGHT));\n"
134 " yuv += 0.125 * sampleYUV(kernelTex1, v_texcoord0);\n"
135 " yuv += 0.5 * sampleYUV(kernelTex0, vec2(v_texcoord0.x, max(v_texcoord0.y - LINEHEIGHT, LINEHEIGHT)));\n"
136 " yuv += 0.5 * sampleYUV(kernelTex0, vec2(v_texcoord0.x, min(v_texcoord0.y + LINEHEIGHT, MAXHEIGHT)));\n"
137 " yuv += -0.0625 * sampleYUV(kernelTex0, twoup);\n"
138 " yuv += -0.0625 * sampleYUV(kernelTex0, twodown);\n"
139 " yuv += -0.0625 * sampleYUV(kernelTex1, twoup);\n"
140 " yuv += -0.0625 * sampleYUV(kernelTex1, twodown);\n"
147 "#ifdef MYTHTV_ONEFIELD\n"
148 "#ifdef MYTHTV_TOPFIELD\n"
149 " highp float field = min(v_texcoord0.y + (step(0.5, fract(v_texcoord0.y * FIELDSIZE))) * LINEHEIGHT, MAXHEIGHT);\n"
151 " highp float field = max(v_texcoord0.y + (step(0.5, 1.0 - fract(v_texcoord0.y * FIELDSIZE))) * LINEHEIGHT, 0.0);\n"
153 " highp vec4 yuv = sampleYUV(s_texture0, vec2(v_texcoord0.x, field));\n"
155 "#ifdef MYTHTV_KERNEL\n"
156 " highp vec4 yuv = sampleYUV(s_texture1, v_texcoord0);\n"
158 " highp vec4 yuv = sampleYUV(s_texture0, v_texcoord0);\n"
162 "#ifdef MYTHTV_KERNEL\n"
163 "#ifdef MYTHTV_TOPFIELD\n"
164 " yuv = mix(kernel(yuv, s_texture1, s_texture2), yuv, step(fract(v_texcoord0.y * FIELDSIZE), 0.5));\n"
166 " yuv = mix(yuv, kernel(yuv, s_texture1, s_texture0), step(fract(v_texcoord0.y * FIELDSIZE), 0.5));\n"
170 "#ifdef MYTHTV_LINEARBLEND\n"
171 " highp vec4 above = sampleYUV(s_texture0, vec2(v_texcoord0.x, min(v_texcoord0.y + LINEHEIGHT, MAXHEIGHT)));\n"
172 " highp vec4 below = sampleYUV(s_texture0, vec2(v_texcoord0.x, max(v_texcoord0.y - LINEHEIGHT, 0.0)));\n"
173 "#ifdef MYTHTV_TOPFIELD\n"
174 " yuv = mix(mix(above, below, 0.5), yuv, step(fract(v_texcoord0.y * FIELDSIZE), 0.5));\n"
176 " yuv = mix(yuv, mix(above, below, 0.5), step(fract(v_texcoord0.y * FIELDSIZE), 0.5));\n"
180 "#ifdef MYTHTV_YUY2\n"
181 " gl_FragColor = vec4(mix(yuv.arb, yuv.grb, step(fract(v_texcoord0.x * COLUMN), 0.5)), 1.0) * m_colourMatrix;\n"
183 " gl_FragColor = yuv * m_colourMatrix;\n"
184 "#ifdef MYTHTV_COLOURMAPPING\n"
185 " gl_FragColor = ColourMap(gl_FragColor);\n"
191 "uniform sampler2D s_texture0;\n"
192 "uniform highp vec2 m_textureSize;\n"
193 "varying highp vec2 v_texcoord0;\n"
194 "highp vec4 Cubic(highp float Pos) {\n"
195 " highp vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - Pos;\n"
196 " highp vec4 s = n * n * n;\n"
197 " highp float x = s.x;\n"
198 " highp float y = s.y - 4.0 * s.x;\n"
199 " highp float z = s.z - 4.0 * s.y + 6.0 * s.x;\n"
200 " highp float w = 6.0 - x - y - z;\n"
201 " return vec4(x, y, z, w) * (1.0/6.0);\n"
205 " highp vec2 pos = (v_texcoord0 * m_textureSize) - 0.5;\n"
206 " highp vec2 fxy = fract(pos);\n"
208 " highp vec4 xcubic = Cubic(fxy.x);\n"
209 " highp vec4 ycubic = Cubic(fxy.y);\n"
210 " highp vec4 c = pos.xxyy + vec2(-0.5, +1.5).xyxy;\n"
211 " highp vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw);\n"
212 " highp vec4 offset = c + vec4 (xcubic.yw, ycubic.yw) / s;\n"
213 " offset *= (1.0 / m_textureSize).xxyy;\n"
214 " highp vec4 sample0 = texture2D(s_texture0, offset.xz);\n"
215 " highp vec4 sample1 = texture2D(s_texture0, offset.yz);\n"
216 " highp vec4 sample2 = texture2D(s_texture0, offset.xw);\n"
217 " highp vec4 sample3 = texture2D(s_texture0, offset.yw);\n"
218 " highp float sx = s.x / (s.x + s.y);\n"
219 " highp float sy = s.z / (s.z + s.w);\n"
220 " gl_FragColor = mix(mix(sample3, sample2, sx), mix(sample1, sample0, sx), sy);\n"
226 "uniform sampler2D s_texture0;\n"
227 "uniform highp float u_random;\n"
228 "uniform highp vec2 m_textureSize;\n"
229 "uniform highp float m_depth;\n"
230 "varying highp vec2 v_texcoord0;\n"
231 "highp float Random(highp float Val)\n"
233 " return fract(Val * 1.0 / 41.0);\n"
235 "highp float Mod289(highp float Val)\n"
237 " return Val - floor(Val * 1.0 / 289.0) * 289.0;\n"
239 "highp float Permute(highp float Val)\n"
241 " return Mod289(Mod289(34.0 * Val + 1.0) * (fract(Val) + 1.0));\n"
243 "highp vec4 Average(in sampler2D texture, in highp vec2 pos, in highp float range, inout highp float pseud)\n"
245 " highp float dist = Random(pseud) * range; pseud = Permute(pseud);\n"
246 " highp float dir = Random(pseud) * 6.2831853; pseud = Permute(pseud);\n"
247 " highp vec2 off = dist * vec2(cos(dir), sin(dir));\n"
248 " highp vec2 adj = 1.0 / m_textureSize;\n"
249 " highp vec4 ref = texture2D(texture, pos + (adj * vec2( off.x, off.y)));\n"
250 " ref += texture2D(texture, pos + (adj * vec2(-off.y, off.x)));\n"
251 " ref += texture2D(texture, pos + (adj * vec2(-off.x, -off.y)));\n"
252 " ref += texture2D(texture, pos + (adj * vec2( off.y, -off.x)));\n"
253 " return ref * 0.25;\n"
257 " highp vec4 color = texture2D(s_texture0, v_texcoord0);\n"
258 " highp vec3 pseudo = vec3(v_texcoord0, u_random) + 1.0;\n"
259 " highp float pseud = Permute(Permute(Permute(pseudo.x) + pseudo.y) + pseudo.z);\n"
260 " highp vec4 avg = Average(s_texture0, v_texcoord0, 16.0, pseud);\n"
261 " highp vec4 diff = abs(color - avg);\n"
262 " color = mix(color, avg, step(diff, vec4(1.0 / m_depth)));\n"
264 " noise.x = Random(pseud); pseud = Permute(pseud);\n"
265 " noise.y = Random(pseud); pseud = Permute(pseud);\n"
266 " noise.z = Random(pseud); pseud = Permute(pseud);\n"
267 " color.rgb += (1.0 / m_depth) * (noise - 0.5);\n"
268 " gl_FragColor = color;\n"
299 "in highp vec2 a_position;\n"
300 "in highp vec2 a_texcoord0;\n"
301 "out highp vec2 v_texcoord0;\n"
302 "uniform highp mat4 u_projection;\n"
305 " gl_Position = u_projection * vec4(a_position, 0.0, 1.0);\n"
306 " v_texcoord0 = a_texcoord0;\n"
310 "#define LINEHEIGHT m_frameData.x\n"
311 "#define COLUMN m_frameData.y\n"
312 "#define MAXHEIGHT m_frameData.z\n"
313 "#define FIELDSIZE m_frameData.w\n"
314 "#define sampler2D highp usampler2D\n";
317 "uniform highp mat4 m_colourMatrix;\n"
318 "uniform highp vec4 m_frameData;\n"
319 "in highp vec2 v_texcoord0;\n"
320 "out highp vec4 fragmentColor;\n"
321 "#ifdef MYTHTV_COLOURMAPPING\n"
322 "uniform highp mat4 m_primaryMatrix;\n"
323 "uniform highp float m_colourGamma;\n"
324 "uniform highp float m_displayGamma;\n"
325 "highp vec4 ColourMap(highp vec4 color)\n"
327 " highp vec4 res = clamp(color, 0.0, 1.0);\n"
328 " res.rgb = pow(res.rgb, vec3(m_colourGamma));\n"
329 " res = m_primaryMatrix * res;\n"
330 " return vec4(pow(res.rgb, vec3(m_displayGamma)), res.a);\n"
340 "highp vec2 chromaLocation(highp vec2 xy)\n"
342 "#ifdef MYTHTV_CUE\n"
343 " highp float temp = xy.y * FIELDSIZE;\n"
344 " highp float onetwo = min((floor(temp / 2.0) / (FIELDSIZE / 2.0)) + LINEHEIGHT, MAXHEIGHT);\n"
345 "#ifdef MYTHTV_CHROMALEFT\n"
346 " return vec2(xy.x + (0.5 / COLUMN), mix(onetwo, min(onetwo + (2.0 * LINEHEIGHT), MAXHEIGHT), step(0.5, fract(temp))));\n"
348 " return vec2(xy.x, mix(onetwo, min(onetwo + (2.0 * LINEHEIGHT), MAXHEIGHT), step(0.5, fract(temp))));\n"
351 "#ifdef MYTHTV_CHROMALEFT\n"
352 " return vec2(xy.x + (0.5 / COLUMN), xy.y);\n"
359 "#ifdef MYTHTV_NV12\n"
360 "highp uvec4 sampleYUV(in sampler2D texture1, in sampler2D texture2, highp vec2 texcoord)\n"
362 " return uvec4(texture(texture1, texcoord).r, texture(texture2, chromaLocation(texcoord)).rg, 1.0);\n"
366 "#ifdef MYTHTV_YV12\n"
367 "highp uvec4 sampleYUV(in sampler2D texture1, in sampler2D texture2, in sampler2D texture3, highp vec2 texcoord)\n"
369 " highp vec2 chroma = chromaLocation(texcoord);\n"
370 " return uvec4(texture(texture1, texcoord).r,\n"
371 " texture(texture2, chroma).r,\n"
372 " texture(texture3, chroma).r,\n"
377 "#ifdef MYTHTV_KERNEL\n"
378 "highp uvec4 kernel(in highp uvec4 yuv, sampler2D kernelTex0, sampler2D kernelTex1)\n"
380 " highp vec2 twoup = vec2(v_texcoord0.x, max(v_texcoord0.y - (2.0 * LINEHEIGHT), LINEHEIGHT));\n"
381 " highp vec2 twodown = vec2(v_texcoord0.x, min(v_texcoord0.y + (2.0 * LINEHEIGHT), MAXHEIGHT));\n"
382 " highp vec4 yuvf = 0.125 * vec4(yuv);\n"
383 " yuvf += 0.125 * vec4(sampleYUV(kernelTex1, v_texcoord0));\n"
384 " yuvf += 0.5 * vec4(sampleYUV(kernelTex0, vec2(v_texcoord0.x, max(v_texcoord0.y - LINEHEIGHT, LINEHEIGHT))));\n"
385 " yuvf += 0.5 * vec4(sampleYUV(kernelTex0, vec2(v_texcoord0.x, min(v_texcoord0.y + LINEHEIGHT, MAXHEIGHT))));\n"
386 " yuvf += -0.0625 * vec4(sampleYUV(kernelTex0, twoup));\n"
387 " yuvf += -0.0625 * vec4(sampleYUV(kernelTex0, twodown));\n"
388 " yuvf += -0.0625 * vec4(sampleYUV(kernelTex1, twoup));\n"
389 " yuvf += -0.0625 * vec4(sampleYUV(kernelTex1, twodown));\n"
390 " return uvec4(yuv);\n"
396 "#ifdef MYTHTV_ONEFIELD\n"
397 "#ifdef MYTHTV_TOPFIELD\n"
398 " highp float field = min(v_texcoord0.y + (step(0.5, fract(v_texcoord0.y * FIELDSIZE))) * LINEHEIGHT, MAXHEIGHT);\n"
400 " highp float field = max(v_texcoord0.y + (step(0.5, 1.0 - fract(v_texcoord0.y * FIELDSIZE))) * LINEHEIGHT, 0.0);\n"
402 " highp uvec4 yuv = sampleYUV(s_texture0, vec2(v_texcoord0.x, field));\n"
404 "#ifdef MYTHTV_KERNEL\n"
405 " highp uvec4 yuv = sampleYUV(s_texture1, v_texcoord0);\n"
407 " highp uvec4 yuv = sampleYUV(s_texture0, v_texcoord0);\n"
411 "#ifdef MYTHTV_KERNEL\n"
412 " highp uint field = uint(step(fract(v_texcoord0.y * FIELDSIZE), 0.5));\n"
413 "#ifdef MYTHTV_TOPFIELD\n"
414 " yuv = (kernel(yuv, s_texture1, s_texture2) * uvec4(field)) + (yuv * uvec4(1u - field));\n"
416 " yuv = (yuv * uvec4(field)) + (kernel(yuv, s_texture1, s_texture0) * uvec4(1u - field));\n"
420 "#ifdef MYTHTV_LINEARBLEND\n"
421 " highp uvec4 mixed = (sampleYUV(s_texture0, vec2(v_texcoord0.x, min(v_texcoord0.y + LINEHEIGHT, MAXHEIGHT))) +\n"
422 " sampleYUV(s_texture0, vec2(v_texcoord0.x, max(v_texcoord0.y - LINEHEIGHT, 0.0)))) / uvec4(2.0);\n"
423 " highp uint field = uint(step(fract(v_texcoord0.y * FIELDSIZE), 0.5));\n"
424 "#ifdef MYTHTV_TOPFIELD\n"
425 " yuv = (mixed * uvec4(field)) + (yuv * uvec4(1u - field));\n"
427 " yuv = (yuv * uvec4(field)) + (mixed * uvec4(1u - field));\n"
431 " fragmentColor = (vec4(yuv) / vec4(65535.0, 65535.0, 65535.0, 1.0)) * m_colourMatrix;\n"
432 "#ifdef MYTHTV_COLOURMAPPING\n"
433 " fragmentColor = ColourMap(fragmentColor);\n"
437 #endif // MYTH_OPENGLVIDEOSHADERS_H
static const QString BicubicShader
static const QString GLSL300VertexShader
static const QString GLSL300YUVFragmentExtensions
static const QString DebandFragmentShader
static const QString YUVFragmentExtensions
static const QString DefaultVertexShader
static const QString YUVFragmentShader
static const QString RGBFragmentShader
static const QString GLSL300YUVFragmentShader