summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x
blob: e5c16b5b758a8d242481041d0d2f161918214155 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED */
/* IF IT IS CHANGED PLEASE COMMIT THE CHANGES */

static const char fragment_glsl[] =
   "/* General-purpose fragment shader for all operations in Evas.\n"
   " * This file can either be used directly by evas at runtime to\n"
   " * generate its shaders with the appropriate #defines, or passed\n"
   " * through cpp first (in which case the precision must be manually added).\n"
   " */\n"
   "#ifdef GL_ES\n"
   "# ifdef GL_FRAGMENT_PRECISION_HIGH\n"
   "precision highp float;\n"
   "# else\n"
   "precision mediump float;\n"
   "# endif\n"
   "# ifdef SHD_EXTERNAL\n"
   "extension GL_OES_EGL_image_external : require\n"
   "#  define SAMPLER_EXTERNAL_OES samplerExternalOES\n"
   "# endif\n"
   "#else\n"
   "# define SAMPLER_EXTERNAL_OES sampler2D\n"
   "#endif\n"
   "#define M_PI   3.141592653589793238462643383279502884\n"
   "#define M_PI_2 1.570796326794896619231321691639751442\n"
   "#ifndef SHD_NOMUL\n"
   "varying vec4 col;\n"
   "#endif\n"
   "#ifdef SHD_EXTERNAL\n"
   "uniform SAMPLER_EXTERNAL_OES tex;\n"
   "varying vec2 tex_c;\n"
   "#elif defined(SHD_TEX)\n"
   "uniform sampler2D tex;\n"
   "varying vec2 tex_c;\n"
   "#endif\n"
   "#if defined(SHD_NV12) || defined(SHD_YUY2)\n"
   "uniform sampler2D texuv;\n"
   "varying vec2 tex_c2;\n"
   "#endif\n"
   "#if defined(SHD_YUV)\n"
   "uniform sampler2D texu;\n"
   "uniform sampler2D texv;\n"
   "varying vec2 tex_c2;\n"
   "varying vec2 tex_c3;\n"
   "#endif\n"
   "#ifdef SHD_TEXA\n"
   "uniform sampler2D texa;\n"
   "varying vec2 tex_a;\n"
   "#endif\n"
   "#if defined(SHD_SAM12) || defined(SHD_SAM21) || defined(SHD_SAM22)\n"
   "varying vec4 div_s;\n"
   "# if defined(SHD_SAM12) || defined(SHD_SAM21)\n"
   "varying vec2 tex_s[2];\n"
   "# else\n"
   "varying vec2 tex_s[4];\n"
   "# endif\n"
   "#endif\n"
   "#ifdef SHD_MASK\n"
   "uniform sampler2D texm;\n"
   "varying vec2 tex_m;\n"
   "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
   "varying float maskdiv_s;\n"
   "varying vec2 masktex_s[2];\n"
   "# elif defined(SHD_MASKSAM22)\n"
   "varying float maskdiv_s;\n"
   "varying vec2 masktex_s[4];\n"
   "# endif\n"
   "#endif\n"
   "#ifdef SHD_ALPHA\n"
   "# define SWZ aaaa\n"
   "#else\n"
   "# ifndef SHD_BGRA\n"
   "#  if defined(SHD_IMG) && defined(SHD_BIGENDIAN)\n"
   "#   define SWZ gbar\n"
   "#  else\n"
   "#   define SWZ bgra\n"
   "#endif\n"
   "# else\n"
   "#  if defined(SHD_IMG) && defined(SHD_BIGENDIAN)\n"
   "#   define SWZ grab\n"
   "#  else\n"
   "#   define SWZ rgba\n"
   "#  endif\n"
   "# endif\n"
   "#endif\n"
   "#ifdef SHD_FILTER_DISPLACE\n"
   "uniform sampler2D tex_filter;\n"
   "varying vec2 displace_vector;\n"
   "varying vec2 displace_min;\n"
   "varying vec2 displace_max;\n"
   "#endif\n"
   "#ifdef SHD_FILTER_CURVE\n"
   "uniform sampler2D tex_filter;\n"
   "#endif\n"
   "#ifdef SHD_FILTER_BLUR\n"
   "uniform sampler2D tex_filter;\n"
   "uniform int blur_count;\n"
   "uniform float blur_texlen;\n"
   "uniform float blur_div;\n"
   "#endif\n"
   "// ----------------------------------------------------------------------------\n"
   "#ifndef SHD_FILTER_BLUR\n"
   "void main()\n"
   "{\n"
   "#if defined(SHD_EXTERNAL) || defined(SHD_TEX)\n"
   "   vec2 coord = tex_c;\n"
   "#endif\n"
   "#else // SHD_FILTER_BLUR\n"
   "vec4 fetch_pixel(float ox, float oy)\n"
   "{\n"
   "   vec2 coord = tex_c + vec2(ox, oy);\n"
   "#endif // SHD_FILTER_BLUR\n"
   "   vec4 c;\n"
   "#ifdef SHD_FILTER_DISPLACE\n"
   "   vec2 dxy = (texture2D(tex_filter, tex_c).rg - vec2(0.5, 0.5)) * displace_vector;\n"
   "   float fa = texture2D(tex_filter, tex_c).a;\n"
   "   coord = clamp(tex_c + dxy, displace_min, displace_max);\n"
   "#endif\n"
   "#if defined(SHD_YUV) || defined(SHD_NV12) || defined(SHD_YUY2)\n"
   "   float r, g, b, y, u, v, vmu;\n"
   "# if defined(SHD_YUV)\n"
   "   y = texture2D(tex, tex_c).r;\n"
   "   u = texture2D(texu, tex_c2).r;\n"
   "   v = texture2D(texv, tex_c3).r;\n"
   "# elif defined(SHD_NV12) || defined(SHD_YUY2)\n"
   "   y = texture2D(tex, tex_c).g;\n"
   "   u = texture2D(texuv, tex_c2).g;\n"
   "   v = texture2D(texuv, tex_c2).a;\n"
   "# endif\n"
   "// center u and v around 0 for uv and y (with 128/255 for u + v, 16/255 for y)\n"
   "   u = u - 0.5;\n"
   "   v = v - 0.5;\n"
   "# if defined (SHD_YUV_709)\n"
   "// 709 yuv colorspace for hd content\n"
   "   y = (y - 0.062) * 1.164;\n"
   "   vmu = (v * 0.534) + (u * 0.213);\n"
   "   v = v * 1.793;\n"
   "   u = u * 2.115;\n"
   "# else\n"
   "// 601 colorspace constants (older yuv content)\n"
   "   y = (y - 0.062) * 1.164;\n"
   "   vmu = (v * 0.813) + (u * 0.391);\n"
   "   v = v * 1.596;\n"
   "   u = u * 2.018;\n"
   "# endif\n"
   "// common yuv\n"
   "   r = y + v;\n"
   "   g = y - vmu;\n"
   "   b = y + u;\n"
   "   c = vec4(r, g, b, 1.0);\n"
   "#elif defined(SHD_SAM12) || defined(SHD_SAM21)\n"
   "   vec4 col00 = texture2D(tex, coord + tex_s[0]).SWZ;\n"
   "   vec4 col01 = texture2D(tex, coord + tex_s[1]).SWZ;\n"
   "   c = (col00 + col01) / div_s;\n"
   "#elif defined(SHD_SAM22)\n"
   "   vec4 col00 = texture2D(tex, coord + tex_s[0]).SWZ;\n"
   "   vec4 col01 = texture2D(tex, coord + tex_s[1]).SWZ;\n"
   "   vec4 col10 = texture2D(tex, coord + tex_s[2]).SWZ;\n"
   "   vec4 col11 = texture2D(tex, coord + tex_s[3]).SWZ;\n"
   "   c = (col00 + col01 + col10 + col11) / div_s;\n"
   "#elif defined(SHD_TEX) || defined(SHD_EXTERNAL)\n"
   "   c = texture2D(tex, coord).SWZ;\n"
   "#else\n"
   "   c = vec4(1, 1, 1, 1);\n"
   "#endif\n"
   "#ifdef SHD_MASK\n"
   "# ifndef SHD_MASK_COLOR\n"
   "   // Classic mask: alpha only\n"
   "   float ma;\n"
   "#  if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
   "   float ma00 = texture2D(texm, tex_m + masktex_s[0]).a;\n"
   "   float ma01 = texture2D(texm, tex_m + masktex_s[1]).a;\n"
   "   ma = (ma00 + ma01) / maskdiv_s;\n"
   "#  elif defined(SHD_MASKSAM22)\n"
   "   float ma00 = texture2D(texm, tex_m + masktex_s[0]).a;\n"
   "   float ma01 = texture2D(texm, tex_m + masktex_s[1]).a;\n"
   "   float ma10 = texture2D(texm, tex_m + masktex_s[2]).a;\n"
   "   float ma11 = texture2D(texm, tex_m + masktex_s[3]).a;\n"
   "   ma = (ma00 + ma01 + ma10 + ma11) / maskdiv_s;\n"
   "#  else\n"
   "   ma = texture2D(texm, tex_m).a;\n"
   "#  endif\n"
   "# else\n"
   "   // Full color mask\n"
   "   vec4 ma;\n"
   "#  if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
   "   vec4 ma00 = texture2D(texm, tex_m + masktex_s[0]);\n"
   "   vec4 ma01 = texture2D(texm, tex_m + masktex_s[1]);\n"
   "   ma = (ma00 + ma01) / maskdiv_s;\n"
   "#  elif defined(SHD_MASKSAM22)\n"
   "   vec4 ma00 = texture2D(texm, tex_m + masktex_s[0]);\n"
   "   vec4 ma01 = texture2D(texm, tex_m + masktex_s[1]);\n"
   "   vec4 ma10 = texture2D(texm, tex_m + masktex_s[2]);\n"
   "   vec4 ma11 = texture2D(texm, tex_m + masktex_s[3]);\n"
   "   ma = (ma00 + ma01 + ma10 + ma11) / maskdiv_s;\n"
   "#  else\n"
   "   ma = texture2D(texm, tex_m);\n"
   "#  endif\n"
   "# endif\n"
   "#endif\n"
   "#ifdef SHD_AFILL\n"
   "   c.a = 1.0;\n"
   "#endif\n"
   "#ifdef SHD_TEXA\n"
   "   c *= texture2D(texa, tex_a).r;\n"
   "#endif\n"
   "#if defined(SHD_FILTER_CURVE)\n"
   "   float old_alpha = max(c.a, 0.00001);\n"
   "   float new_alpha = texture2D(tex_filter, vec2(old_alpha, 0.0)).a;\n"
   "   c = vec4(texture2D(tex_filter, vec2(c.r / old_alpha, 0.0)).r * new_alpha,\n"
   "            texture2D(tex_filter, vec2(c.g / old_alpha, 0.0)).g * new_alpha,\n"
   "            texture2D(tex_filter, vec2(c.b / old_alpha, 0.0)).b * new_alpha,\n"
   "            new_alpha);\n"
   "#endif\n"
   "#ifdef SHD_ALPHA_ONLY\n"
   "   c = vec4(c.a, c.a, c.a, c.a);\n"
   "#endif\n"
   "#ifdef SHD_FILTER_GRAYSCALE\n"
   "   c.rgb = 0.3 * c.r + 0.59 * c.g + 0.11 * c.b;\n"
   "#endif\n"
   "#ifdef SHD_FILTER_INVERSE_COLOR\n"
   "   c.rgb = c.a - c.rgb;\n"
   "#endif\n"
   "#ifndef SHD_FILTER_BLUR\n"
   "   gl_FragColor =\n"
   "       c\n"
   "#ifndef SHD_NOMUL\n"
   "     * col\n"
   "#endif\n"
   "#ifdef SHD_MASK\n"
   "     * ma\n"
   "#endif\n"
   "#ifdef SHD_FILTER_DISPLACE\n"
   "     * fa\n"
   "#endif\n"
   "   ;\n"
   "}\n"
   "#else // SHD_FILTER_BLUR\n"
   "   return c;\n"
   "}\n"
   "#ifndef SHD_FILTER_DIR_Y\n"
   "# define FETCH_PIXEL(x) fetch_pixel((x), 0.0)\n"
   "#else\n"
   "# define FETCH_PIXEL(x) fetch_pixel(0.0, (x))\n"
   "#endif\n"
   "float weight_get(float u, float count, float index)\n"
   "{\n"
   "   vec4 val = texture2D(tex_filter, vec2(u / count, index)).bgra;\n"
   "   return val.a * 255.0 + val.r + val.g / 256.0 + val.b / 65536.0;\n"
   "}\n"
   "float offset_get(float u, float count, float index)\n"
   "{\n"
   "   // val.a is always 0 here ~ discard\n"
   "   vec4 val = texture2D(tex_filter, vec2(u / count, index)).bgra;\n"
   "   return val.r + val.g / 256.0 + val.b / 65536.0;\n"
   "}\n"
   "void main()\n"
   "{\n"
   "   float weight, offset, count;\n"
   "   vec4 acc, px;\n"
   "   int k;\n"
   "   count = float(blur_count);\n"
   "   // Center pixel, offset is 0.0\n"
   "   weight = weight_get(0.0, count, 0.0);\n"
   "   px = FETCH_PIXEL(0.0);\n"
   "   acc = px * weight;\n"
   "   // Left & right pixels\n"
   "   for (k = 1; k <= blur_count; k++)\n"
   "   {\n"
   "      float u = float(k);\n"
   "      weight = weight_get(u, count, 0.0);\n"
   "      offset = offset_get(u, count, 1.0);\n"
   "      // Left\n"
   "      vec4 px1 = FETCH_PIXEL(-((offset + (2.0 * u) - 1.0)) / blur_texlen);\n"
   "      // Right\n"
   "      vec4 px2 = FETCH_PIXEL((offset + (2.0 * u) - 1.0) / blur_texlen);\n"
   "      acc += (px1 + px2) * weight;\n"
   "   }\n"
   "#ifndef SHD_NOMUL\n"
   "   gl_FragColor = (acc / blur_div) * col;\n"
   "#else\n"
   "   gl_FragColor = (acc / blur_div);\n"
   "#endif\n"
   "}\n"
   "#endif // SHD_FILTER_BLUR\n";

static const char vertex_glsl[] =
   "/* General-purpose vertex shader for all operations in Evas.\n"
   " * This file can either be used directly by evas at runtime to\n"
   " * generate its shaders with the appropriate #defines, or passed\n"
   " * through cpp first (in which case the precision must be manually added).\n"
   " */\n"
   "#ifdef GL_ES\n"
   "precision highp float;\n"
   "#endif\n"
   "attribute vec4 vertex;\n"
   "uniform mat4 mvp;\n"
   "/* Window rotation by id 0,1,2,3 (represents 0,90,180,270) */\n"
   "uniform int rotation_id;\n"
   "/* All except nomul */\n"
   "#ifndef SHD_NOMUL\n"
   "attribute vec4 color;\n"
   "varying vec4 col;\n"
   "#endif\n"
   "/* All images & fonts */\n"
   "#if defined(SHD_TEX) || defined(SHD_EXTERNAL)\n"
   "attribute vec2 tex_coord;\n"
   "varying vec2 tex_c;\n"
   "#endif\n"
   "/* NV12, YUY2 */\n"
   "#if defined(SHD_NV12) || defined(SHD_YUY2) || defined(SHD_YUV)\n"
   "attribute vec2 tex_coord2;\n"
   "varying vec2 tex_c2;\n"
   "#endif\n"
   "/* YUV */\n"
   "#ifdef SHD_YUV\n"
   "attribute vec2 tex_coord3;\n"
   "varying vec2 tex_c3;\n"
   "#endif\n"
   "/* RGB+A */\n"
   "#ifdef SHD_TEXA\n"
   "attribute vec2 tex_coorda;\n"
   "varying vec2 tex_a;\n"
   "#endif\n"
   "/* Sampling */\n"
   "#if defined(SHD_SAM12) || defined(SHD_SAM21) || defined(SHD_SAM22)\n"
   "attribute vec2 tex_sample;\n"
   "varying vec4 div_s;\n"
   "# if defined(SHD_SAM12) || defined(SHD_SAM21)\n"
   "varying vec2 tex_s[2];\n"
   "# else\n"
   "varying vec2 tex_s[4];\n"
   "# endif\n"
   "#endif\n"
   "/* Masking */\n"
   "#ifdef SHD_MASK\n"
   "attribute vec4 mask_coord;\n"
   "varying vec2 tex_m;\n"
   "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
   "attribute vec2 tex_masksample;\n"
   "varying float maskdiv_s;\n"
   "varying vec2 masktex_s[2];\n"
   "# elif defined(SHD_MASKSAM22)\n"
   "attribute vec2 tex_masksample;\n"
   "varying float maskdiv_s;\n"
   "varying vec2 masktex_s[4];\n"
   "# endif\n"
   "#endif\n"
   "/* Gfx Filters: displace */\n"
   "#ifdef SHD_FILTER_DISPLACE\n"
   "attribute vec2 filter_data_0;\n"
   "attribute vec2 filter_data_1;\n"
   "attribute vec2 filter_data_2;\n"
   "varying vec2 displace_vector;\n"
   "varying vec2 displace_min;\n"
   "varying vec2 displace_max;\n"
   "#endif\n"
   "void main()\n"
   "{\n"
   "   gl_Position = mvp * vertex;\n"
   "#ifndef SHD_NOMUL\n"
   "   col = color;\n"
   "#endif\n"
   "#if defined(SHD_TEX) || defined(SHD_EXTERNAL)\n"
   "   tex_c = tex_coord;\n"
   "#endif\n"
   "#ifdef SHD_NV12\n"
   "   tex_c2 = tex_coord2 * 0.5;\n"
   "#endif\n"
   "#ifdef SHD_YUY2\n"
   "   tex_c2 = vec2(tex_coord2.x * 0.5, tex_coord2.y);\n"
   "#endif\n"
   "#ifdef SHD_YUV\n"
   "   tex_c2 = tex_coord2;\n"
   "   tex_c3 = tex_coord3;\n"
   "#endif\n"
   "#ifdef SHD_TEXA\n"
   "   tex_a = tex_coorda;\n"
   "#endif\n"
   "#if defined(SHD_SAM12)\n"
   "   tex_s[0] = vec2(0, -tex_sample.y);\n"
   "   tex_s[1] = vec2(0,  tex_sample.y);\n"
   "   div_s = vec4(2, 2, 2, 2);\n"
   "#elif defined(SHD_SAM21)\n"
   "   tex_s[0] = vec2(-tex_sample.x, 0);\n"
   "   tex_s[1] = vec2( tex_sample.x, 0);\n"
   "   div_s = vec4(2, 2, 2, 2);\n"
   "#elif defined(SHD_SAM22)\n"
   "   tex_s[0] = vec2(-tex_sample.x, -tex_sample.y);\n"
   "   tex_s[1] = vec2( tex_sample.x, -tex_sample.y);\n"
   "   tex_s[2] = vec2( tex_sample.x,  tex_sample.y);\n"
   "   tex_s[3] = vec2(-tex_sample.x,  tex_sample.y);\n"
   "   div_s = vec4(4, 4, 4, 4);\n"
   "#endif\n"
   "#if defined(SHD_MASKSAM12)\n"
   "   masktex_s[0] = vec2(0, -tex_masksample.y);\n"
   "   masktex_s[1] = vec2(0,  tex_masksample.y);\n"
   "   maskdiv_s = 2.0;\n"
   "#elif defined(SHD_MASKSAM21)\n"
   "   masktex_s[0] = vec2(-tex_masksample.x, 0);\n"
   "   masktex_s[1] = vec2( tex_masksample.x, 0);\n"
   "   maskdiv_s = 2.0;\n"
   "#elif defined(SHD_MASKSAM22)\n"
   "   masktex_s[0] = vec2(-tex_masksample.x, -tex_masksample.y);\n"
   "   masktex_s[1] = vec2( tex_masksample.x, -tex_masksample.y);\n"
   "   masktex_s[2] = vec2( tex_masksample.x,  tex_masksample.y);\n"
   "   masktex_s[3] = vec2(-tex_masksample.x,  tex_masksample.y);\n"
   "   maskdiv_s = 4.0;\n"
   "#endif\n"
   "#ifdef SHD_MASK\n"
   "   // mask_coord.w contains the Y-invert flag\n"
   "   // position on screen in [0..1] range of current pixel\n"
   "   vec4 window_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
   "   vec2 pos[4];\n"
   "   pos[0] = vec2(window_Position.xy);\n"
   "   pos[1] = vec2(1.0 - window_Position.y, window_Position.x);\n"
   "   pos[2] = vec2(1.0 - window_Position.xy);\n"
   "   pos[3] = vec2(window_Position.y, 1.0 - window_Position.x);\n"
   "   tex_m = pos[rotation_id] * abs(mask_coord.zw) + mask_coord.xy;\n"
   "#endif\n"
   "#ifdef SHD_FILTER_DISPLACE\n"
   "   displace_vector = filter_data_0;\n"
   "   displace_min = filter_data_1;\n"
   "   displace_max = filter_data_2;\n"
   "#endif\n"
   "}\n";