@thenick775/mgba-wasm 2.7.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mgba.data ADDED
@@ -0,0 +1,3645 @@
1
+ varying vec2 texCoord;
2
+ uniform sampler2D tex;
3
+ uniform vec2 texSize;
4
+
5
+ void main() {
6
+ vec4 color = texture2D(tex, texCoord);
7
+ color.rgb = pow(color.rgb * vec3(0.8, 0.8, 0.8), vec3(1.8, 1.8, 1.8)) + vec3(0.16, 0.16, 0.16);
8
+
9
+ // GLSL ES 1.00 cannot dynamically index locally written arrays.
10
+ float x = mod(texCoord.s * texSize.x * 3.0, 3.0);
11
+ if (x < 1.0) {
12
+ color.rgb *= vec3(0.2, 0.2, 1.0);
13
+ } else if (x < 2.0) {
14
+ color.rgb *= vec3(0.2, 1.0, 0.2);
15
+ } else {
16
+ color.rgb *= vec3(1.0, 0.2, 0.2);
17
+ }
18
+
19
+ float y = mod(texCoord.t * texSize.y * 4.0, 4.0);
20
+ if (y >= 3.0) {
21
+ color.rgb *= vec3(0.8, 0.8, 0.8);
22
+ }
23
+
24
+ color.a = 0.5;
25
+ gl_FragColor = color;
26
+ }
27
+ [shader]
28
+ name=AGB-001
29
+ author=endrift
30
+ description=A glorious recreation of the original Game Boy Advance
31
+ passes=1
32
+
33
+ [pass.0]
34
+ fragmentShader=agb001.fs
35
+ blend=1
36
+ width=-3
37
+ height=-4
38
+ varying vec2 texCoord;
39
+ uniform sampler2D tex;
40
+ uniform float reflectionBrightness;
41
+ uniform vec2 reflectionDistance;
42
+ uniform float lightBrightness;
43
+
44
+ const float speed = 2.0;
45
+ const float decay = 2.0;
46
+ const float coeff = 2.5;
47
+
48
+ void main() {
49
+ float sp = pow(speed, lightBrightness);
50
+ float dc = pow(decay, -lightBrightness);
51
+ float s = (sp - dc) / (sp + dc);
52
+ vec2 radius = (texCoord.st - vec2(0.5, 0.5)) * vec2(coeff * s);
53
+ radius = pow(abs(radius), vec2(4.0));
54
+ vec3 bleed = vec3(0.12, 0.14, 0.19);
55
+ bleed += (dot(radius, radius) + vec3(0.02, 0.03, 0.05)) * vec3(0.14, 0.18, 0.2);
56
+
57
+ vec4 color = texture2D(tex, texCoord);
58
+ color.rgb += pow(bleed, pow(vec3(lightBrightness), vec3(-0.5)));
59
+
60
+ vec4 reflection = texture2D(tex, texCoord - reflectionDistance);
61
+ color.rgb += reflection.rgb * reflectionBrightness;
62
+ color.a = 1.0;
63
+ gl_FragColor = color;
64
+ }
65
+ varying vec2 texCoord;
66
+ uniform sampler2D tex;
67
+ uniform vec2 texSize;
68
+
69
+ const vec3 kArrayX0 = vec3(0.2, 0.2, 1.0);
70
+ const vec3 kArrayX1 = vec3(0.2, 1.0, 0.2);
71
+ const vec3 kArrayX2 = vec3(1.0, 0.2, 0.2);
72
+ const vec3 kArrayY0 = vec3(1.0, 1.0, 1.0);
73
+ const vec3 kArrayY1 = vec3(1.0, 1.0, 1.0);
74
+ const vec3 kArrayY2 = vec3(1.0, 1.0, 1.0);
75
+ const vec3 kArrayY3 = vec3(0.9, 0.9, 0.9);
76
+
77
+
78
+ void main() {
79
+ vec4 color = texture2D(tex, texCoord);
80
+ // WebGL1-safe: precomputed constant LUTs (no runtime array writes)
81
+ color.rgb = pow(color.rgb, vec3(1.6, 1.6, 1.6));
82
+ int xi = int(mod(texCoord.s * texSize.x * 3.0, 3.0));
83
+ vec3 ax = (xi == 0) ? kArrayX0 : ((xi == 1) ? kArrayX1 : kArrayX2);
84
+ int yi = int(mod(texCoord.t * texSize.y * 4.0, 4.0));
85
+ vec3 ay = (yi == 0) ? kArrayY0 : ((yi == 1) ? kArrayY1 : ((yi == 2) ? kArrayY2 : kArrayY3));
86
+ color.rgb *= ax;
87
+ color.rgb *= ay;
88
+ color.a = 0.8;
89
+ gl_FragColor = color;
90
+ }
91
+ [shader]
92
+ name=AGS-001
93
+ author=endrift
94
+ description=A pristine recreation of the illuminated Game Boy Advance SP
95
+ passes=2
96
+
97
+ [pass.0]
98
+ fragmentShader=ags001.fs
99
+ blend=1
100
+ width=-3
101
+ height=-4
102
+
103
+ [pass.1]
104
+ fragmentShader=ags001-light.fs
105
+ width=-3
106
+ height=-4
107
+
108
+ [pass.1.uniform.lightBrightness]
109
+ type=float
110
+ default=1
111
+ readableName=Light brightness
112
+
113
+ [pass.1.uniform.reflectionBrightness]
114
+ type=float
115
+ default=0.07
116
+ readableName=Reflection brightness
117
+
118
+ [pass.1.uniform.reflectionDistance]
119
+ type=float2
120
+ default[0]=0
121
+ default[1]=0.025
122
+ readableName=Reflection distance
123
+ // Shader that replicates the LCD Colorspace from a Nintendo DS Lite --
124
+ varying vec2 texCoord;
125
+ varying mat4 profile;
126
+ uniform sampler2D tex;
127
+ uniform vec2 texSize;
128
+
129
+ const float target_gamma = 2.2;
130
+ const float display_gamma = 2.2;
131
+
132
+ void main() {
133
+ // bring out our stored luminance value
134
+ float lum = profile[3].w;
135
+
136
+ // our adjustments need to happen in linear gamma
137
+ vec4 screen = pow(texture2D(tex, texCoord), vec4(target_gamma)).rgba;
138
+
139
+ screen = clamp(screen * lum, 0.0, 1.0);
140
+ screen = profile * screen;
141
+ gl_FragColor = pow(screen, vec4(1.0 / display_gamma));
142
+ }
143
+ uniform int color_mode;
144
+ attribute vec4 position;
145
+ varying vec2 texCoord;
146
+ varying mat4 profile;
147
+
148
+ const mat4 DSL_sRGB = mat4(
149
+ 0.93, 0.025, 0.008, 0.0, //red channel
150
+ 0.14, 0.90, -0.03, 0.0, //green channel
151
+ -0.07, 0.075, 1.022, 0.0, //blue channel
152
+ 0.0, 0.0, 0.0, 0.935 //alpha channel
153
+ );
154
+
155
+ const mat4 DSL_DCI = mat4(
156
+ 0.76, 0.055, 0.0225, 0.0, //red channel
157
+ 0.27, 0.875, 0.0225, 0.0, //green channel
158
+ -0.03, 0.07, 0.955, 0.0, //blue channel
159
+ 0.0, 0.0, 0.0, 0.97 //alpha channel
160
+ );
161
+
162
+ const mat4 DSL_Rec2020 = mat4(
163
+ 0.585, 0.09, 0.0225, 0.0, //red channel
164
+ 0.3725, 0.825, 0.035, 0.0, //green channel
165
+ 0.0425, 0.085, 0.9425, 0.0, //blue channel
166
+ 0.0, 0.0, 0.0, 1.0 //alpha channel
167
+ );
168
+
169
+ void main() {
170
+ if (color_mode == 1) profile = DSL_sRGB;
171
+ else if (color_mode == 2) profile = DSL_DCI;
172
+ else if (color_mode == 3) profile = DSL_Rec2020;
173
+
174
+ gl_Position = position;
175
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
176
+ }
177
+ [shader]
178
+ name=Nintendo DS Lite Color
179
+ author=Pokefan531 and hunterk
180
+ description=Shader that replicates the LCD Colorspace from a Nintendo DS Lite.
181
+ passes=1
182
+
183
+ [pass.0]
184
+ fragmentShader=dslite-color.fs
185
+ vertexShader=dslite-color.vs
186
+ blend=1
187
+ width=-1
188
+ height=-1
189
+
190
+ [pass.0.uniform.color_mode]
191
+ type=int
192
+ default=1
193
+ min=1
194
+ max=3
195
+ readableName=Color Profile (1=sRGB, 2=DCI, 3=Rec2020)
196
+ /*
197
+ fish shader
198
+
199
+ algorithm and original implementation by Miloslav "drummyfish" Ciz
200
+ (tastyfish@seznam.cz)
201
+
202
+ Permission is hereby granted, free of charge, to any person obtaining a copy
203
+ of this software and associated documentation files (the "Software"), to deal
204
+ in the Software without restriction, including without limitation the rights
205
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
206
+ copies of the Software, and to permit persons to whom the Software is
207
+ furnished to do so, subject to the following conditions:
208
+
209
+ The above copyright notice and this permission notice shall be included in
210
+ all copies or substantial portions of the Software.
211
+
212
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
213
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
214
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
215
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
216
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
217
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
218
+ THE SOFTWARE.
219
+ */
220
+
221
+ uniform sampler2D tex;
222
+ uniform vec2 texSize;
223
+ varying vec2 texCoord;
224
+
225
+ uniform float similarity_threshold;
226
+
227
+ vec4 texel_fetch(sampler2D t, ivec2 c) // because GLSL TexelFetch is not supported
228
+ {
229
+ return texture2D(t, (2.0 * vec2(c) + vec2(1.0,1.0)) / (2.0 * texSize));
230
+ }
231
+
232
+ float pixel_brightness(vec4 pixel)
233
+ {
234
+ return 0.21 * pixel.x + 0.72 * pixel.y + 0.07 * pixel.z;
235
+ }
236
+
237
+ bool pixel_is_brighter(vec4 pixel1, vec4 pixel2)
238
+ {
239
+ return pixel_brightness(pixel1) > pixel_brightness(pixel2);
240
+ }
241
+
242
+ vec3 pixel_to_yuv(vec4 pixel)
243
+ {
244
+ float y = 0.299 * pixel.x + 0.587 * pixel.y + 0.114 * pixel.z;
245
+ return vec3(y, 0.492 * (pixel.z - y), 0.877 * (pixel.x - y));
246
+ }
247
+
248
+ bool yuvs_are_similar(vec3 yuv1, vec3 yuv2)
249
+ {
250
+ vec3 yuv_difference = abs(yuv1 - yuv2);
251
+ return yuv_difference.x <= similarity_threshold && yuv_difference.y <= similarity_threshold && yuv_difference.z <= similarity_threshold;
252
+ }
253
+
254
+ bool pixels_are_similar(vec4 pixel1, vec4 pixel2)
255
+ {
256
+ vec3 yuv1 = pixel_to_yuv(pixel1);
257
+ vec3 yuv2 = pixel_to_yuv(pixel2);
258
+
259
+ return yuvs_are_similar(yuv1, yuv2);
260
+ }
261
+
262
+ vec4 interpolate_nondiagonal(vec4 neighbour1, vec4 neighbour2)
263
+ {
264
+ if (pixels_are_similar(neighbour1,neighbour2))
265
+ return mix(neighbour1,neighbour2,0.5);
266
+ else
267
+ return pixel_is_brighter(neighbour1, neighbour2) ? neighbour1 : neighbour2;
268
+ }
269
+
270
+ vec4 mix3(vec4 value1, vec4 value2, vec4 value3)
271
+ {
272
+ return (value1 + value2 + value3) / 3.0;
273
+ }
274
+
275
+ vec4 straight_line(vec4 p0, vec4 p1, vec4 p2, vec4 p3)
276
+ {
277
+ return pixel_is_brighter(p2,p0) ? mix(p2,p3,0.5) : mix(p0,p1,0.5);
278
+ }
279
+
280
+ vec4 corner(vec4 p0, vec4 p1, vec4 p2, vec4 p3)
281
+ {
282
+ return pixel_is_brighter(p1,p0) ? mix3(p1,p2,p3) : mix3(p0,p1,p2);
283
+ }
284
+
285
+ vec4 interpolate_diagonal(vec4 a, vec4 b, vec4 c, vec4 d)
286
+ {
287
+ // a b
288
+ // c d
289
+
290
+ vec3 a_yuv = pixel_to_yuv(a);
291
+ vec3 b_yuv = pixel_to_yuv(b);
292
+ vec3 c_yuv = pixel_to_yuv(c);
293
+ vec3 d_yuv = pixel_to_yuv(d);
294
+
295
+ bool ad = yuvs_are_similar(a_yuv,d_yuv);
296
+ bool bc = yuvs_are_similar(b_yuv,c_yuv);
297
+ bool ab = yuvs_are_similar(a_yuv,b_yuv);
298
+ bool cd = yuvs_are_similar(c_yuv,d_yuv);
299
+ bool ac = yuvs_are_similar(a_yuv,c_yuv);
300
+ bool bd = yuvs_are_similar(b_yuv,d_yuv);
301
+
302
+ if (ad && cd && ab) // all pixels are equal?
303
+ return( mix(mix(a,b,0.5), mix(c,d,0.5), 0.5) );
304
+
305
+ else if (ac && cd && ! ab) // corner 1?
306
+ return corner(b,a,d,c);
307
+ else if (bd && cd && ! ab) // corner 2?
308
+ return corner(a,b,c,d);
309
+ else if (ac && ab && ! bd) // corner 3?
310
+ return corner(d,c,b,a);
311
+ else if (ab && bd && ! ac) // corner 4?
312
+ return corner(c,a,d,b);
313
+
314
+ else if (ad && (!bc || pixel_is_brighter(b,a))) // diagonal line 1?
315
+ return mix(a,d,0.5);
316
+ else if (bc && (!ad || pixel_is_brighter(a,b))) // diagonal line 2?
317
+ return mix(b,c,0.5);
318
+
319
+ else if (ab) // horizontal line 1?
320
+ return straight_line(a,b,c,d);
321
+ else if (cd) // horizontal line 2?
322
+ return straight_line(c,d,a,b);
323
+
324
+ else if (ac) // vertical line 1?
325
+ return straight_line(a,c,b,d);
326
+ else if (bd) // vertical line 2?
327
+ return straight_line(b,d,a,c);
328
+
329
+ return( mix(mix(a,b,0.5), mix(c,d,0.5), 0.5) );
330
+ }
331
+
332
+ void main()
333
+ {
334
+ ivec2 pixel_coords2 = ivec2(vec2(texCoord) * vec2(texSize) * 2.0);
335
+ ivec2 pixel_coords = pixel_coords2 / 2;
336
+
337
+ bool x_even = (pixel_coords2.x - (pixel_coords2.x / 2) * 2) == 0;
338
+ bool y_even = (pixel_coords2.y - (pixel_coords2.y / 2) * 2) == 0;
339
+
340
+ if (x_even)
341
+ {
342
+ if (y_even)
343
+ {
344
+
345
+ gl_FragColor = interpolate_diagonal(
346
+ texel_fetch(tex, pixel_coords + ivec2(-1,-1)),
347
+ texel_fetch(tex, pixel_coords + ivec2(0,-1)),
348
+ texel_fetch(tex, pixel_coords + ivec2(-1,0)),
349
+ texel_fetch(tex, pixel_coords + ivec2(0,0))
350
+ );
351
+
352
+ }
353
+ else
354
+ {
355
+ gl_FragColor = interpolate_nondiagonal
356
+ (
357
+ texel_fetch(tex, pixel_coords + ivec2(-1,0)),
358
+ texel_fetch(tex, pixel_coords)
359
+ );
360
+ }
361
+ }
362
+ else if (y_even)
363
+ {
364
+ gl_FragColor = interpolate_nondiagonal
365
+ (
366
+ texel_fetch(tex, pixel_coords + ivec2(0,-1)),
367
+ texel_fetch(tex, pixel_coords)
368
+ );
369
+ }
370
+ else
371
+ gl_FragColor = texel_fetch(tex, pixel_coords);
372
+ }
373
+ [shader]
374
+ name=fish
375
+ author=Drummyfish
376
+ description=Attempts to keep thin lines thin.
377
+ passes=1
378
+
379
+ [pass.0]
380
+ fragmentShader=fish.fs
381
+ integerScaling=1
382
+
383
+ [pass.0.uniform.similarity_threshold]
384
+ type=float
385
+ default=0.2
386
+ readableName=Similarity Threshold
387
+ min=0
388
+ max=1
389
+ // Shader that replicates the LCD Colorspace from a Gameboy Micro (OXY-001) --
390
+ varying vec2 texCoord;
391
+ varying mat4 profile;
392
+ uniform sampler2D tex;
393
+ uniform vec2 texSize;
394
+
395
+ const float target_gamma = 2.2;
396
+ const float display_gamma = 2.2;
397
+
398
+ void main() {
399
+ // bring out our stored luminance value
400
+ float lum = profile[3].w;
401
+
402
+ // our adjustments need to happen in linear gamma
403
+ vec4 screen = pow(texture2D(tex, texCoord), vec4(target_gamma)).rgba;
404
+
405
+ screen = clamp(screen * lum, 0.0, 1.0);
406
+ screen = profile * screen;
407
+ gl_FragColor = pow(screen, vec4(1.0 / display_gamma));
408
+ }
409
+ uniform int color_mode;
410
+ attribute vec4 position;
411
+ varying vec2 texCoord;
412
+ varying mat4 profile;
413
+
414
+ const mat4 GBM_sRGB = mat4(
415
+ 0.8025, 0.10, 0.1225, 0.0, //red channel
416
+ 0.31, 0.6875, 0.1125, 0.0, //green channel
417
+ -0.1125, 0.2125, 0.765, 0.0, //blue channel
418
+ 0.0, 0.0, 0.0, 0.9 //alpha channel
419
+ );
420
+
421
+ const mat4 GBM_DCI = mat4(
422
+ 0.6675, 0.125, 0.13, 0.0, //red channel
423
+ 0.3825, 0.675, 0.1475, 0.0, //green channel
424
+ -0.05, 0.20, 0.7225, 0.0, //blue channel
425
+ 0.0, 0.0, 0.0, 0.96 //alpha channel
426
+ );
427
+
428
+ const mat4 GBM_Rec2020 = mat4(
429
+ 0.525, 0.15, 0.13, 0.0, //red channel
430
+ 0.43, 0.65, 0.155, 0.0, //green channel
431
+ 0.045, 0.20, 0.715, 0.0, //blue channel
432
+ 0.0, 0.0, 0.0, 1.0 //alpha channel
433
+ );
434
+
435
+ void main() {
436
+ if (color_mode == 1) profile = GBM_sRGB;
437
+ else if (color_mode == 2) profile = GBM_DCI;
438
+ else if (color_mode == 3) profile = GBM_Rec2020;
439
+
440
+ gl_Position = position;
441
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
442
+ }
443
+ [shader]
444
+ name=GB Micro Color
445
+ author=Pokefan531 and hunterk
446
+ description=Shader that replicates the LCD Colorspace from a Gameboy Micro (OXY-001).
447
+ passes=1
448
+
449
+ [pass.0]
450
+ fragmentShader=gb-micro-color.fs
451
+ vertexShader=gb-micro-color.vs
452
+ blend=1
453
+ width=-1
454
+ height=-1
455
+
456
+ [pass.0.uniform.color_mode]
457
+ type=int
458
+ default=1
459
+ min=1
460
+ max=3
461
+ readableName=Color Profile (1=sRGB, 2=DCI, 3=Rec2020)
462
+ // Shader that replicates the LCD Colorspace from Gameboy Advance --
463
+ varying vec2 texCoord;
464
+ varying mat4 profile;
465
+ uniform sampler2D tex;
466
+ uniform vec2 texSize;
467
+
468
+ uniform float darken_screen;
469
+ const float target_gamma = 2.0;
470
+ const float display_gamma = 2.0;
471
+
472
+ void main() {
473
+ // bring out our stored luminance value
474
+ float lum = profile[3].w;
475
+
476
+ // our adjustments need to happen in linear gamma
477
+ vec4 screen = pow(texture2D(tex, texCoord), vec4(target_gamma + darken_screen)).rgba;
478
+
479
+ screen = clamp(screen * lum, 0.0, 1.0);
480
+ screen = profile * screen;
481
+ gl_FragColor = pow(screen, vec4(1.0 / display_gamma));
482
+ }
483
+ uniform int color_mode;
484
+ attribute vec4 position;
485
+ varying vec2 texCoord;
486
+ varying mat4 profile;
487
+
488
+ const mat4 GBA_sRGB = mat4(
489
+ 0.80, 0.135, 0.195, 0.0, //red channel
490
+ 0.275, 0.64, 0.155, 0.0, //green channel
491
+ -0.075, 0.225, 0.65, 0.0, //blue channel
492
+ 0.0, 0.0, 0.0, 0.93 //alpha channel
493
+ );
494
+
495
+ const mat4 GBA_DCI = mat4(
496
+ 0.685, 0.16, 0.20, 0.0, //red channel
497
+ 0.34, 0.629, 0.19, 0.0, //green channel
498
+ -0.025, 0.211, 0.61, 0.0, //blue channel
499
+ 0.0, 0.0, 0.0, 0.975 //alpha channel
500
+ );
501
+
502
+ const mat4 GBA_Rec2020 = mat4(
503
+ 0.555, 0.1825, 0.20, 0.0, //red channel
504
+ 0.395, 0.61, 0.195, 0.0, //green channel
505
+ 0.05, 0.2075, 0.605, 0.0, //blue channel
506
+ 0.0, 0.0, 0.0, 1.0 //alpha channel
507
+ );
508
+
509
+ void main() {
510
+ if (color_mode == 1) profile = GBA_sRGB;
511
+ else if (color_mode == 2) profile = GBA_DCI;
512
+ else if (color_mode == 3) profile = GBA_Rec2020;
513
+
514
+ gl_Position = position;
515
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
516
+ }
517
+ [shader]
518
+ name=GBA Color
519
+ author=Pokefan531 and hunterk
520
+ description=Modifies the color output to simulate the GBA LCD characteristics.
521
+ passes=1
522
+
523
+ [pass.0]
524
+ fragmentShader=gba-color.fs
525
+ vertexShader=gba-color.vs
526
+ blend=1
527
+ width=-1
528
+ height=-1
529
+
530
+ [pass.0.uniform.darken_screen]
531
+ type=float
532
+ default=0.5
533
+ min=0
534
+ max=1
535
+ readableName=Darken Screen
536
+
537
+ [pass.0.uniform.color_mode]
538
+ type=int
539
+ default=1
540
+ min=1
541
+ max=3
542
+ readableName=Color Profile (1=sRGB, 2=DCI, 3=Rec2020)
543
+ // Shader that replicates the LCD Colorspace from Gameboy Color --
544
+ varying vec2 texCoord;
545
+ varying mat4 profile;
546
+ uniform sampler2D tex;
547
+ uniform vec2 texSize;
548
+
549
+ uniform float lighten_screen;
550
+ const float target_gamma = 2.2;
551
+ const float display_gamma = 2.2;
552
+
553
+ void main() {
554
+ // bring out our stored luminance value
555
+ float lum = profile[3].w;
556
+
557
+ // our adjustments need to happen in linear gamma
558
+ vec4 screen = pow(texture2D(tex, texCoord), vec4(target_gamma - lighten_screen)).rgba;
559
+
560
+ screen = clamp(screen * lum, 0.0, 1.0);
561
+ screen = profile * screen;
562
+ gl_FragColor = pow(screen, vec4(1.0 / display_gamma));
563
+ }
564
+ uniform int color_mode;
565
+ attribute vec4 position;
566
+ varying vec2 texCoord;
567
+ varying mat4 profile;
568
+
569
+ const mat4 GBC_sRGB = mat4(
570
+ 0.905, 0.10, 0.1575, 0.0, //red channel
571
+ 0.195, 0.65, 0.1425, 0.0, //green channel
572
+ -0.10, 0.25, 0.70, 0.0, //blue channel
573
+ 0.0, 0.0, 0.0, 0.91 //alpha channel
574
+ );
575
+
576
+ const mat4 GBC_DCI = mat4(
577
+ 0.76, 0.125, 0.16, 0.0, //red channel
578
+ 0.27, 0.6375, 0.18, 0.0, //green channel
579
+ -0.03, 0.2375, 0.66, 0.0, //blue channel
580
+ 0.0, 0.0, 0.0, 0.97 //alpha channel
581
+ );
582
+
583
+ const mat4 GBC_Rec2020 = mat4(
584
+ 0.61, 0.155, 0.16, 0.0, //red channel
585
+ 0.345, 0.615, 0.1875, 0.0, //green channel
586
+ 0.045, 0.23, 0.6525, 0.0, //blue channel
587
+ 0.0, 0.0, 0.0, 1.0 //alpha channel
588
+ );
589
+
590
+ void main() {
591
+ if (color_mode == 1) profile = GBC_sRGB;
592
+ else if (color_mode == 2) profile = GBC_DCI;
593
+ else if (color_mode == 3) profile = GBC_Rec2020;
594
+
595
+ gl_Position = position;
596
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
597
+ }
598
+ [shader]
599
+ name=GBC Color
600
+ author=Pokefan531 and hunterk
601
+ description=Modifies the color output to simulate the GBA LCD characteristics.
602
+ passes=1
603
+
604
+ [pass.0]
605
+ fragmentShader=gbc-color.fs
606
+ vertexShader=gbc-color.vs
607
+ blend=1
608
+ width=-1
609
+ height=-1
610
+
611
+ [pass.0.uniform.lighten_screen]
612
+ type=float
613
+ default=1.0
614
+ min=0
615
+ max=1
616
+ readableName=External Lighten Screen
617
+
618
+ [pass.0.uniform.color_mode]
619
+ type=int
620
+ default=1
621
+ min=1
622
+ max=3
623
+ readableName=Color Profile (1=sRGB, 2=DCI, 3=Rec2020)
624
+ /**
625
+ * This shader creates a backlight bleeding effect,
626
+ * and an internal reflection or ghosting effect.
627
+ */
628
+
629
+ varying vec2 texCoord;
630
+ uniform sampler2D tex;
631
+
632
+ /**
633
+ * Determines the color of the backlight bleed.
634
+ * Lower values produce less, dimmer light.
635
+ * Higher values produce brighter or more colorful light.
636
+ * You'll normally want each of these numbers to be close
637
+ * to 1, and not normally lower than 0.
638
+ */
639
+ uniform vec3 LightColor;
640
+
641
+ /**
642
+ * Affects the shape of the backlight bleed glow.
643
+ * Lower values cause the light bleed to fade out quickly
644
+ * from the edges.
645
+ * Higher values cause the light bleed to fade out more
646
+ * softly and gradually toward the center.
647
+ * You'll normally want this to be a number from 0 to 1.
648
+ */
649
+ uniform float LightSoftness;
650
+
651
+ /**
652
+ * Lower values result in a less visible or intense
653
+ * backlight bleed.
654
+ * Higher values make the backlight bleed more pronounced.
655
+ * You'll normally want this to be a number close to 0,
656
+ * and not normally higher than 1.
657
+ */
658
+ uniform float LightIntensity;
659
+
660
+ /**
661
+ * Lower values cause the internal reflection or ghosting
662
+ * effect to be less visible.
663
+ * Higher values cause the effect to be brighter and more
664
+ * visible.
665
+ * You'll normally want this to be a number close to 0,
666
+ * and not normally higher than 1.
667
+ */
668
+ uniform float ReflectionBrightness;
669
+
670
+ /**
671
+ * Lower values have the internal reflection or ghosting
672
+ * effect appear offset by a lesser distance.
673
+ * Higher values have the effect offset by a greater
674
+ * distance.
675
+ * You'll normally want each of these numbers to be close
676
+ * to 0, and not normally higher than 1.
677
+ */
678
+ uniform vec2 ReflectionDistance;
679
+
680
+ #define M_PI 3.1415926535897932384626433832795
681
+
682
+ const vec2 CENTER = vec2(0.5, 0.5);
683
+ const float INV_SQRT_HALF = 1.4142135623730951; // 1.0 / sqrt(0.5)
684
+
685
+ /**
686
+ * Helper to compute backlight bleed intensity
687
+ * for a texCoord input.
688
+ */
689
+ float getLightIntensity(vec2 coord) {
690
+ vec2 coordCentered = coord - CENTER;
691
+
692
+ // length(coordCentered) / sqrt(0.5) == length(coordCentered) * (1/sqrt(0.5))
693
+ float coordDistCenter = length(coordCentered) * INV_SQRT_HALF;
694
+
695
+ vec2 coordQuadrant = vec2(
696
+ 1.0 - (1.5 * min(coord.x, 1.0 - coord.x)),
697
+ 1.0 - (1.5 * min(coord.y, 1.0 - coord.y))
698
+ );
699
+
700
+ float lightIntensityEdges = (
701
+ pow(coordQuadrant.x, 5.0) +
702
+ pow(coordQuadrant.y, 5.0)
703
+ );
704
+
705
+ float lightIntensity = (
706
+ (1.0 - LightSoftness) * lightIntensityEdges +
707
+ LightSoftness * coordDistCenter
708
+ );
709
+
710
+ return clamp(lightIntensity, 0.0, 1.0);
711
+ }
712
+
713
+ /**
714
+ * Helper to convert an intensity value into a white
715
+ * gray color with that intensity. A radial distortion
716
+ * effect with subtle chromatic abberation is applied that
717
+ * makes it look a little more like a real old or cheap
718
+ * backlight, and also helps to reduce color banding.
719
+ */
720
+ vec3 getWhiteVector(float intensity) {
721
+ const float DeformAmount = 0.0025;
722
+
723
+ vec2 texCoordCentered = texCoord - CENTER;
724
+ float radians = atan(texCoordCentered.y, texCoordCentered.x);
725
+
726
+ float ring = floor(6.0 * length(texCoordCentered));
727
+ float rot = pow(2.0, 4.0 + ring);
728
+
729
+ float deformRed = cos(rot * radians + (2.0 / 3.0 * M_PI));
730
+ float deformGreen = cos(rot * radians);
731
+ float deformBlue = cos(rot * radians + (4.0 / 3.0 * M_PI));
732
+
733
+ return clamp(vec3(
734
+ intensity + (deformRed * DeformAmount),
735
+ intensity + (deformGreen * DeformAmount),
736
+ intensity + (deformBlue * DeformAmount)
737
+ ), 0.0, 1.0);
738
+ }
739
+
740
+ void main() {
741
+ vec3 colorSource = texture2D(tex, texCoord).rgb;
742
+ vec3 lightWhiteVector = getWhiteVector(getLightIntensity(texCoord));
743
+ vec3 colorLight = LightColor * lightWhiteVector;
744
+ vec3 colorReflection = texture2D(tex, texCoord - ReflectionDistance).rgb;
745
+ vec3 colorResult = (
746
+ colorSource +
747
+ (colorLight * LightIntensity) +
748
+ (colorReflection * ReflectionBrightness)
749
+ );
750
+ gl_FragColor = vec4(
751
+ colorResult,
752
+ 1.0
753
+ );
754
+ }
755
+ /**
756
+ * This shader imitates the GameBoy Color subpixel
757
+ * arrangement.
758
+ */
759
+
760
+ varying vec2 texCoord;
761
+ uniform sampler2D tex;
762
+ uniform vec2 texSize;
763
+
764
+ /**
765
+ * Adds a base color to everything.
766
+ * Lower values make black colors darker.
767
+ * Higher values make black colors lighter.
768
+ * You'll normally want each of these numbers to be close
769
+ * to 0, and not normally higher than 1.
770
+ */
771
+ uniform vec3 BaseColor;
772
+
773
+ /**
774
+ * Modifies the contrast or saturation of the image.
775
+ * Lower values make the image more gray and higher values
776
+ * make it more colorful.
777
+ * A value of 1 represents a normal, baseline level of
778
+ * contrast.
779
+ * You'll normally want this to be somewhere around 1.
780
+ */
781
+ uniform float SourceContrast;
782
+
783
+ /**
784
+ * Modifies the luminosity of the image.
785
+ * Lower values make the image darker and higher values make
786
+ * it lighter.
787
+ * A value of 1 represents normal, baseline luminosity.
788
+ * You'll normally want this to be somewhere around 1.
789
+ */
790
+ uniform float SourceLuminosity;
791
+
792
+ /**
793
+ * Lower values look more like a sharp, unshaded image.
794
+ * Higher values look more like an LCD display with subpixels.
795
+ * You'll normally want this to be a number from 0 to 1.
796
+ */
797
+ uniform float SubpixelBlendAmount;
798
+
799
+ /**
800
+ * Lower values make subpixels darker.
801
+ * Higher values make them lighter and over-bright.
802
+ * A value of 1 represents a normal, baseline gamma value.
803
+ * You'll normally want this to be somewhere around 1.
804
+ */
805
+ uniform float SubpixelGamma;
806
+
807
+ /**
808
+ * Higher values allow subpixels to be more blended-together
809
+ * and brighter.
810
+ * Lower values keep subpixel colors more separated.
811
+ * You'll normally want this to be a number from 0 to 1.
812
+ */
813
+ uniform float SubpixelColorBleed;
814
+
815
+ /**
816
+ * Determines the distance between subpixels.
817
+ * Lower values put the red, green, and blue subpixels
818
+ * within a single pixel closer together.
819
+ * Higher values put them farther apart.
820
+ * You'll normally want this to be a number from 0 to 1.
821
+ */
822
+ uniform float SubpixelSpread;
823
+
824
+ /**
825
+ * Determines the vertical offset of subpixels within
826
+ * a pixel.
827
+ * Lower values put the red, green, and blue subpixels
828
+ * within a single pixel higher up.
829
+ * Higher values put them further down.
830
+ * You'll normally want this to be a number from 0 to 1.
831
+ */
832
+ uniform float SubpixelVerticalOffset;
833
+
834
+ /**
835
+ * Lower values make the subpixels horizontally thinner,
836
+ * and higher values make them thicker.
837
+ * You'll normally want this to be a number from 0 to 1.
838
+ */
839
+ uniform float SubpixelLightWidth;
840
+
841
+ /**
842
+ * Lower values make the subpixels vertically taller,
843
+ * and higher values make them shorter.
844
+ * You'll normally want this to be a number from 0 to 1.
845
+ */
846
+ uniform float SubpixelLightHeight;
847
+
848
+ /**
849
+ * Lower values make the subpixels sharper and more
850
+ * individually distinct.
851
+ * Higher values add an increasingly intense glowing
852
+ * effect around each subpixel.
853
+ * You'll normally want this to be a number from 0 to 1.
854
+ */
855
+ uniform float SubpixelLightGlow;
856
+
857
+ /**
858
+ * Scale the size of pixels up or down.
859
+ * Useful for looking at larger than 8x8 subpixel sizes.
860
+ * You'll normally want this number to be exactly 1,
861
+ * meaning that every group of 3 subpixels corresponds
862
+ * to one pixel in the display.
863
+ */
864
+ uniform float SubpixelScale;
865
+
866
+ /**
867
+ * GBC subpixels are roughly rectangular shaped, but
868
+ * with a rectangular gap in the lower-right corner.
869
+ * Lower values make the lower-right gap in each GBC
870
+ * subpixel less distinct. A value of 0 results in no
871
+ * gap being shown at all.
872
+ * Higher values make the gap more distinct.
873
+ * You'll normally want this to be a number from 0 to 1.
874
+ */
875
+ uniform float SubpixelTabHeight;
876
+
877
+ /**
878
+ * The following three uniforms decide the base colors
879
+ * of each of the subpixels.
880
+ *
881
+ * Default subpixel colors are based on this resource:
882
+ * https://gbcc.dev/technology/
883
+ * R: #FF7145 (1.00, 0.44, 0.27)
884
+ * G: #C1D650 (0.75, 0.84, 0.31)
885
+ * B: #3BCEFF (0.23, 0.81, 1.00)
886
+ */
887
+ uniform vec3 SubpixelColorRed; // vec3(1.00, 0.38, 0.22);
888
+ uniform vec3 SubpixelColorGreen; // vec3(0.60, 0.88, 0.30);
889
+ uniform vec3 SubpixelColorBlue; // vec3(0.23, 0.65, 1.00);
890
+
891
+ const vec3 ONE = vec3(1.0, 1.0, 1.0);
892
+
893
+ /**
894
+ * Helper to get luminosity of an RGB color.
895
+ * Used with HCL color space related code.
896
+ */
897
+ float getColorLumosity(in vec3 rgb) {
898
+ return (
899
+ (rgb.r * (5.0 / 16.0)) +
900
+ (rgb.g * (9.0 / 16.0)) +
901
+ (rgb.b * (2.0 / 16.0))
902
+ );
903
+ }
904
+
905
+ /**
906
+ * Helper to convert RGB color to HCL. (Hue, Chroma, Luma)
907
+ */
908
+ vec3 convertRgbToHcl(in vec3 rgb) {
909
+ float xMin = min(rgb.r, min(rgb.g, rgb.b));
910
+ float xMax = max(rgb.r, max(rgb.g, rgb.b));
911
+ float c = xMax - xMin;
912
+ float l = getColorLumosity(rgb);
913
+
914
+ float h = mod((
915
+ c == 0.0 ? 0.0 :
916
+ xMax == rgb.r ? ((rgb.g - rgb.b) / c) :
917
+ xMax == rgb.g ? ((rgb.b - rgb.r) / c) + 2.0 :
918
+ xMax == rgb.b ? ((rgb.r - rgb.g) / c) + 4.0 :
919
+ 0.0
920
+ ), 6.0);
921
+
922
+ return vec3(h, c, l);
923
+ }
924
+
925
+ /**
926
+ * Helper to convert HCL color to RGB. (Hue, Chroma, Luma)
927
+ */
928
+ vec3 convertHclToRgb(in vec3 hcl) {
929
+ vec3 rgb;
930
+ float h = mod(hcl.x, 6.0);
931
+ float c = hcl.y;
932
+ float l = hcl.z;
933
+ float x = c * (1.0 - abs(mod(h, 2.0) - 1.0));
934
+
935
+ if (h <= 1.0) {
936
+ rgb = vec3(c, x, 0.0);
937
+ } else if (h <= 2.0) {
938
+ rgb = vec3(x, c, 0.0);
939
+ } else if (h <= 3.0) {
940
+ rgb = vec3(0.0, c, x);
941
+ } else if (h <= 4.0) {
942
+ rgb = vec3(0.0, x, c);
943
+ } else if (h <= 5.0) {
944
+ rgb = vec3(x, 0.0, c);
945
+ } else {
946
+ rgb = vec3(c, 0.0, x);
947
+ }
948
+
949
+ float lRgb = getColorLumosity(rgb);
950
+ float m = l - lRgb;
951
+
952
+ return clamp(vec3(m, m, m) + rgb, 0.0, 1.0);
953
+ }
954
+
955
+ /**
956
+ * Helper to check if a point is contained within
957
+ * a rectangular area.
958
+ */
959
+ bool getPointInRect(vec2 point, vec2 rectTopLeft, vec2 rectBottomRight) {
960
+ return (
961
+ point.x >= rectTopLeft.x &&
962
+ point.y >= rectTopLeft.y &&
963
+ point.x <= rectBottomRight.x &&
964
+ point.y <= rectBottomRight.y
965
+ );
966
+ }
967
+
968
+ /**
969
+ * Helper to get the nearest offset vector from a
970
+ * point to a line segment.
971
+ * (The length of this offset vector is the nearest
972
+ * distance from the point to the line segment.)
973
+ * Thank you to https://stackoverflow.com/a/1501725
974
+ */
975
+ vec2 getPointLineDistance(vec2 point, vec2 line0, vec2 line1) {
976
+ vec2 lineDelta = line0 - line1;
977
+ float lineLengthSq = dot(lineDelta, lineDelta);
978
+ if (lineLengthSq <= 0.0) {
979
+ return line0 - point;
980
+ }
981
+ float t = dot(point - line0, line1 - line0) / lineLengthSq;
982
+ vec2 projection = line0 + clamp(t, 0.0, 1.0) * (line1 - line0);
983
+ return projection - point;
984
+ }
985
+
986
+ /**
987
+ * Helper to get the nearest offset vector from a
988
+ * point to a rectangle.
989
+ * Returns (0, 0) for points within the rectangle.
990
+ */
991
+ vec2 getPointRectDistance(vec2 point, vec2 rectTopLeft, vec2 rectBottomRight) {
992
+ if (getPointInRect(point, rectTopLeft, rectBottomRight)) {
993
+ return vec2(0.0, 0.0);
994
+ }
995
+
996
+ vec2 rectTopRight = vec2(rectBottomRight.x, rectTopLeft.y);
997
+ vec2 rectBottomLeft = vec2(rectTopLeft.x, rectBottomRight.y);
998
+
999
+ vec2 v0 = getPointLineDistance(point, rectTopLeft, rectTopRight);
1000
+ vec2 v1 = getPointLineDistance(point, rectBottomLeft, rectBottomRight);
1001
+ vec2 v2 = getPointLineDistance(point, rectTopLeft, rectBottomLeft);
1002
+ vec2 v3 = getPointLineDistance(point, rectTopRight, rectBottomRight);
1003
+
1004
+ float v0LengthSq = dot(v0, v0);
1005
+ float v1LengthSq = dot(v1, v1);
1006
+ float v2LengthSq = dot(v2, v2);
1007
+ float v3LengthSq = dot(v3, v3);
1008
+
1009
+ float minLengthSq = min(min(v0LengthSq, v1LengthSq), min(v2LengthSq, v3LengthSq));
1010
+
1011
+ if (minLengthSq == v0LengthSq) return v0;
1012
+ if (minLengthSq == v1LengthSq) return v1;
1013
+ if (minLengthSq == v2LengthSq) return v2;
1014
+ return v3;
1015
+ }
1016
+
1017
+ /**
1018
+ * Helper to get the nearest offset vector from a
1019
+ * point to a subpixel.
1020
+ * GBC subpixels are roughly rectangular in shape,
1021
+ * but have a rectangular gap in their bottom-left
1022
+ * corner.
1023
+ * Returns (0, 0) for points within the subpixel.
1024
+ */
1025
+ vec2 getPointSubpixelDistance(vec2 point, vec2 subpixelCenter, vec2 subpixelSizeHalf) {
1026
+ float rectLeft = subpixelCenter.x - subpixelSizeHalf.x;
1027
+ float rectRight = subpixelCenter.x + subpixelSizeHalf.x;
1028
+ float rectTop = subpixelCenter.y - subpixelSizeHalf.y;
1029
+ float rectBottom = subpixelCenter.y + subpixelSizeHalf.y;
1030
+
1031
+ vec2 offsetLeft = getPointRectDistance(
1032
+ point,
1033
+ vec2(rectLeft, rectTop + SubpixelTabHeight),
1034
+ vec2(subpixelCenter.x, rectBottom)
1035
+ );
1036
+
1037
+ vec2 offsetRight = getPointRectDistance(
1038
+ point,
1039
+ vec2(subpixelCenter.x, rectTop),
1040
+ vec2(rectRight, rectBottom)
1041
+ );
1042
+
1043
+ float offsetLeftLengthSq = dot(offsetLeft, offsetLeft);
1044
+ float offsetRightLengthSq = dot(offsetRight, offsetRight);
1045
+
1046
+ return (offsetLeftLengthSq <= offsetRightLengthSq) ? offsetLeft : offsetRight;
1047
+ }
1048
+
1049
+ /**
1050
+ * Helper to get the intensity of light from a
1051
+ * subpixel.
1052
+ * The pixelPosition argument represents a
1053
+ * fragment's position within a pixel.
1054
+ * Spread represents the subpixel's horizontal
1055
+ * position within the pixel.
1056
+ */
1057
+ float getSubpixelIntensity(vec2 pixelPosition, float spread) {
1058
+ vec2 subpixelCenter = vec2(
1059
+ 0.5 + (spread * SubpixelSpread),
1060
+ 1.0 - SubpixelVerticalOffset
1061
+ );
1062
+
1063
+ vec2 subpixelSizeHalf = 0.5 * vec2(SubpixelLightWidth, SubpixelLightHeight);
1064
+
1065
+ vec2 offset = getPointSubpixelDistance(pixelPosition, subpixelCenter, subpixelSizeHalf);
1066
+
1067
+ if (SubpixelLightGlow <= 0.0) {
1068
+ return (dot(offset, offset) <= 0.0) ? 1.0 : 0.0;
1069
+ }
1070
+
1071
+ float dist = length(offset);
1072
+ float glow = max(0.0, 1.0 - (dist / SubpixelLightGlow));
1073
+ return glow;
1074
+ }
1075
+
1076
+ /**
1077
+ * Helper to apply SubpixelColorBleed to the intensity
1078
+ * value computed for a fragment and subpixel.
1079
+ * Subpixel color bleed allows subpixel colors to be
1080
+ * more strongly coerced to more accurately represent
1081
+ * the underlying pixel color.
1082
+ */
1083
+ float applySubpixelBleed(float subpixelIntensity, float colorSourceChannel) {
1084
+ return subpixelIntensity * (
1085
+ SubpixelColorBleed +
1086
+ ((1.0 - SubpixelColorBleed) * colorSourceChannel)
1087
+ );
1088
+ }
1089
+
1090
+ void main() {
1091
+ // Get base color of the pixel, adjust based on
1092
+ // contrast and luminosity settings.
1093
+ vec3 colorSource = texture2D(tex, texCoord).rgb;
1094
+ vec3 colorSourceHcl = convertRgbToHcl(colorSource);
1095
+ vec3 colorSourceAdjusted = convertHclToRgb(vec3(
1096
+ colorSourceHcl.x,
1097
+ colorSourceHcl.y * SourceContrast,
1098
+ colorSourceHcl.z * SourceLuminosity
1099
+ ));
1100
+ // Determine how much each subpixel's light should
1101
+ // affect this fragment.
1102
+ vec2 pixelPosition = mod(texCoord * texSize * SubpixelScale, 1.0);
1103
+ float subpixelIntensityRed = applySubpixelBleed(
1104
+ getSubpixelIntensity(pixelPosition, -1.0),
1105
+ colorSourceAdjusted.r
1106
+ );
1107
+ float subpixelIntensityGreen = applySubpixelBleed(
1108
+ getSubpixelIntensity(pixelPosition, 0.0),
1109
+ colorSourceAdjusted.g
1110
+ );
1111
+ float subpixelIntensityBlue = applySubpixelBleed(
1112
+ getSubpixelIntensity(pixelPosition, 1.0),
1113
+ colorSourceAdjusted.b
1114
+ );
1115
+ vec3 subpixelLightColor = SubpixelGamma * (
1116
+ (subpixelIntensityRed * SubpixelColorRed) +
1117
+ (subpixelIntensityGreen * SubpixelColorGreen) +
1118
+ (subpixelIntensityBlue * SubpixelColorBlue)
1119
+ );
1120
+ // Compute final color
1121
+ vec3 colorResult = clamp(subpixelLightColor * colorSourceAdjusted, 0.0, 1.0);
1122
+
1123
+ vec3 colorResultBlended =
1124
+ ((1.0 - SubpixelBlendAmount) * colorSourceAdjusted) +
1125
+ (SubpixelBlendAmount * colorResult);
1126
+
1127
+ colorResultBlended = BaseColor + (colorResultBlended * (ONE - BaseColor));
1128
+
1129
+ gl_FragColor = vec4(colorResultBlended, 1.0);
1130
+ }This is free and unencumbered software released into the public domain.
1131
+
1132
+ Anyone is free to copy, modify, publish, use, compile, sell, or
1133
+ distribute this software, either in source code form or as a compiled
1134
+ binary, for any purpose, commercial or non-commercial, and by any
1135
+ means.
1136
+
1137
+ In jurisdictions that recognize copyright laws, the author or authors
1138
+ of this software dedicate any and all copyright interest in the
1139
+ software to the public domain. We make this dedication for the benefit
1140
+ of the public at large and to the detriment of our heirs and
1141
+ successors. We intend this dedication to be an overt act of
1142
+ relinquishment in perpetuity of all present and future rights to this
1143
+ software under copyright law.
1144
+
1145
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1146
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1147
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1148
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1149
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1150
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1151
+ OTHER DEALINGS IN THE SOFTWARE.
1152
+
1153
+ For more information, please refer to <http://unlicense.org/>
1154
+ [shader]
1155
+ name=gbc-lcd
1156
+ author=Sophie Kirschner
1157
+ description=Imitates the GameBoy Color LCD screen subpixel arrangement, with an optional backlight effect.
1158
+ passes=2
1159
+
1160
+ [pass.0]
1161
+ integerScaling=1
1162
+ fragmentShader=gbc-lcd.fs
1163
+ blend=1
1164
+
1165
+ [pass.1]
1166
+ fragmentShader=gbc-lcd-light.fs
1167
+
1168
+ [pass.0.uniform.BaseColor]
1169
+ type=float3
1170
+ default[0]=0.130
1171
+ default[1]=0.128
1172
+ default[2]=0.101
1173
+ readableName=Screen base color
1174
+
1175
+ [pass.0.uniform.SubpixelColorRed]
1176
+ type=float3
1177
+ default[0]=1.00
1178
+ default[1]=0.38
1179
+ default[2]=0.22
1180
+ readableName=Red subpixel color
1181
+
1182
+ [pass.0.uniform.SubpixelColorGreen]
1183
+ type=float3
1184
+ default[0]=0.60
1185
+ default[1]=0.88
1186
+ default[2]=0.30
1187
+ readableName=Green subpixel color
1188
+
1189
+ [pass.0.uniform.SubpixelColorBlue]
1190
+ type=float3
1191
+ default[0]=0.23
1192
+ default[1]=0.65
1193
+ default[2]=1.00
1194
+ readableName=Blue subpixel color
1195
+
1196
+ [pass.0.uniform.SourceContrast]
1197
+ type=float
1198
+ default=0.85
1199
+ readableName=Screen contrast
1200
+
1201
+ [pass.0.uniform.SourceLuminosity]
1202
+ type=float
1203
+ default=0.88
1204
+ readableName=Screen luminosity
1205
+
1206
+ [pass.0.uniform.SubpixelBlendAmount]
1207
+ type=float
1208
+ default=1.0
1209
+ readableName=Subpixel effect amount
1210
+
1211
+ [pass.0.uniform.SubpixelColorBleed]
1212
+ type=float
1213
+ default=0.31
1214
+ readableName=Subpixel color bleeding
1215
+
1216
+ [pass.0.uniform.SubpixelSpread]
1217
+ type=float
1218
+ default=0.333
1219
+ readableName=Subpixel spread X
1220
+
1221
+ [pass.0.uniform.SubpixelVerticalOffset]
1222
+ type=float
1223
+ default=0.48
1224
+ readableName=Subpixel offset Y
1225
+
1226
+ [pass.0.uniform.SubpixelGamma]
1227
+ type=float
1228
+ default=1.040
1229
+ readableName=Subpixel brightness
1230
+
1231
+ [pass.0.uniform.SubpixelLightWidth]
1232
+ type=float
1233
+ default=0.220
1234
+ readableName=Subpixel width
1235
+
1236
+ [pass.0.uniform.SubpixelLightHeight]
1237
+ type=float
1238
+ default=0.850
1239
+ readableName=Subpixel height
1240
+
1241
+ [pass.0.uniform.SubpixelLightGlow]
1242
+ type=float
1243
+ default=0.195
1244
+ readableName=Subpixel glow size
1245
+
1246
+ [pass.0.uniform.SubpixelTabHeight]
1247
+ type=float
1248
+ default=0.175
1249
+ readableName=Subpixel tab shaping
1250
+
1251
+ [pass.0.uniform.SubpixelScale]
1252
+ type=float
1253
+ default=1.0
1254
+ readableName=Subpixel scale
1255
+
1256
+ [pass.1.uniform.LightColor]
1257
+ type=float3
1258
+ default[0]=1.000
1259
+ default[1]=0.968
1260
+ default[2]=0.882
1261
+ readableName=Backlight color
1262
+
1263
+ [pass.1.uniform.LightIntensity]
1264
+ type=float
1265
+ default=0.06
1266
+ readableName=Backlight intensity
1267
+
1268
+ [pass.1.uniform.LightSoftness]
1269
+ type=float
1270
+ default=0.67
1271
+ readableName=Backlight softness
1272
+
1273
+ [pass.1.uniform.ReflectionDistance]
1274
+ type=float2
1275
+ default[0]=0
1276
+ default[1]=0.025
1277
+ readableName=Internal reflection distance
1278
+
1279
+ [pass.1.uniform.ReflectionBrightness]
1280
+ type=float
1281
+ default=0.032
1282
+ readableName=Internal reflection brightness
1283
+ /* MIT License
1284
+ *
1285
+ * Copyright (c) 2015-2023 Lior Halphon
1286
+ *
1287
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
1288
+ * of this software and associated documentation files (the "Software"), to deal
1289
+ * in the Software without restriction, including without limitation the rights
1290
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1291
+ * copies of the Software, and to permit persons to whom the Software is
1292
+ * furnished to do so, subject to the following conditions:
1293
+ *
1294
+ * The above copyright notice and this permission notice shall be included in all
1295
+ * copies or substantial portions of the Software.
1296
+ *
1297
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1298
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1299
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1300
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1301
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1302
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1303
+ * SOFTWARE.
1304
+ */
1305
+ /* Based on this (really good) article: http://blog.pkh.me/p/19-butchering-hqx-scaling-filters.html */
1306
+
1307
+ /* The colorspace used by the HQnx filters is not really YUV, despite the algorithm description claims it is. It is
1308
+ also not normalized. Therefore, we shall call the colorspace used by HQnx "HQ Colorspace" to avoid confusion. */
1309
+
1310
+ varying vec2 texCoord;
1311
+ uniform sampler2D tex;
1312
+ uniform vec2 texSize;
1313
+
1314
+ float _bit(float v, int i)
1315
+ {
1316
+ // v is an integer value stored as float
1317
+ float p = exp2(float(i)); // 2^i, GLSL ES 1.00-friendly
1318
+ return floor(mod(floor(v / p), 2.0));
1319
+ }
1320
+
1321
+ bool _matchMask(float pattern, int mask, int ref)
1322
+ {
1323
+ // (pattern & mask) == ref, implemented without bitwise ops.
1324
+ float m = float(mask);
1325
+ float r = float(ref);
1326
+ float mism = 0.0;
1327
+ for (int i = 0; i < 8; ++i)
1328
+ {
1329
+ float mb = _bit(m, i);
1330
+ if (mb > 0.5)
1331
+ {
1332
+ float pb = _bit(pattern, i);
1333
+ float rb = _bit(r, i);
1334
+ mism += abs(pb - rb);
1335
+ }
1336
+ }
1337
+ return mism < 0.5;
1338
+ }
1339
+
1340
+ vec3 rgb_to_hq_colospace(vec4 rgb)
1341
+ {
1342
+ return vec3(
1343
+ 0.250 * rgb.r + 0.250 * rgb.g + 0.250 * rgb.b,
1344
+ 0.250 * rgb.r - 0.000 * rgb.g - 0.250 * rgb.b,
1345
+ -0.125 * rgb.r + 0.250 * rgb.g - 0.125 * rgb.b
1346
+ );
1347
+ }
1348
+
1349
+ bool is_different(vec4 a, vec4 b)
1350
+ {
1351
+ vec3 diff = abs(rgb_to_hq_colospace(a) - rgb_to_hq_colospace(b));
1352
+ return diff.x > 0.018 || diff.y > 0.002 || diff.z > 0.005;
1353
+ }
1354
+
1355
+ // WebGL1: no bitwise ops in GLSL ES 1.00
1356
+
1357
+ vec4 interp_2px(vec4 c1, float w1, vec4 c2, float w2)
1358
+ {
1359
+ return (c1 * w1 + c2 * w2) / (w1 + w2);
1360
+ }
1361
+
1362
+ vec4 interp_3px(vec4 c1, float w1, vec4 c2, float w2, vec4 c3, float w3)
1363
+ {
1364
+ return (c1 * w1 + c2 * w2 + c3 * w3) / (w1 + w2 + w3);
1365
+ }
1366
+
1367
+ vec4 scale(sampler2D image, vec2 position, vec2 input_resolution)
1368
+ {
1369
+ // o = offset, the width of a pixel
1370
+ vec2 o = vec2(1.0, 1.0) / input_resolution;
1371
+
1372
+ /* We always calculate the top left pixel. If we need a different pixel, we flip the image */
1373
+
1374
+ // p = the position within a pixel [0...1]
1375
+ vec2 p = fract(position * input_resolution);
1376
+
1377
+ if (p.x > 0.5) o.x = -o.x;
1378
+ if (p.y > 0.5) o.y = -o.y;
1379
+
1380
+ vec4 w0 = texture2D(image, position + vec2( -o.x, -o.y));
1381
+ vec4 w1 = texture2D(image, position + vec2( 0.0, -o.y));
1382
+ vec4 w2 = texture2D(image, position + vec2( o.x, -o.y));
1383
+ vec4 w3 = texture2D(image, position + vec2( -o.x, 0.0));
1384
+ vec4 w4 = texture2D(image, position + vec2( 0.0, 0.0));
1385
+ vec4 w5 = texture2D(image, position + vec2( o.x, 0.0));
1386
+ vec4 w6 = texture2D(image, position + vec2( -o.x, o.y));
1387
+ vec4 w7 = texture2D(image, position + vec2( 0.0, o.y));
1388
+ vec4 w8 = texture2D(image, position + vec2( o.x, o.y));
1389
+
1390
+ float pattern = 0.0;
1391
+ if (is_different(w0, w4)) pattern += 1.0;
1392
+ if (is_different(w1, w4)) pattern += 2.0;
1393
+ if (is_different(w2, w4)) pattern += 4.0;
1394
+ if (is_different(w3, w4)) pattern += 8.0;
1395
+ if (is_different(w5, w4)) pattern += 16.0;
1396
+ if (is_different(w6, w4)) pattern += 32.0;
1397
+ if (is_different(w7, w4)) pattern += 64.0;
1398
+ if (is_different(w8, w4)) pattern += 128.0;
1399
+
1400
+ // NOTE: hex literals (0x..) are not GLSL ES 1.00. Converted to decimal.
1401
+
1402
+ if ((_matchMask(pattern, 191, 55) || _matchMask(pattern, 219, 19)) && is_different(w1, w5))
1403
+ {
1404
+ return interp_2px(w4, 3.0, w3, 1.0);
1405
+ }
1406
+ if ((_matchMask(pattern, 219, 73) || _matchMask(pattern, 239, 109)) && is_different(w7, w3))
1407
+ {
1408
+ return interp_2px(w4, 3.0, w1, 1.0);
1409
+ }
1410
+ if ((_matchMask(pattern, 11, 11) || _matchMask(pattern, 254, 74) || _matchMask(pattern, 254, 26)) && is_different(w3, w1))
1411
+ {
1412
+ return w4;
1413
+ }
1414
+ if ((_matchMask(pattern, 111, 42) || _matchMask(pattern, 91, 10) || _matchMask(pattern, 191, 58) || _matchMask(pattern, 223, 90) ||
1415
+ _matchMask(pattern, 159, 138) || _matchMask(pattern, 207, 138) || _matchMask(pattern, 239, 78) || _matchMask(pattern, 63, 14) ||
1416
+ _matchMask(pattern, 251, 90) || _matchMask(pattern, 187, 138) || _matchMask(pattern, 127, 90) || _matchMask(pattern, 175, 138) ||
1417
+ _matchMask(pattern, 235, 138)) && is_different(w3, w1))
1418
+ {
1419
+ return interp_2px(w4, 3.0, w0, 1.0);
1420
+ }
1421
+ if (_matchMask(pattern, 11, 8))
1422
+ {
1423
+ return interp_3px(w4, 2.0, w0, 1.0, w1, 1.0);
1424
+ }
1425
+ if (_matchMask(pattern, 11, 2))
1426
+ {
1427
+ return interp_3px(w4, 2.0, w0, 1.0, w3, 1.0);
1428
+ }
1429
+ if (_matchMask(pattern, 47, 47))
1430
+ {
1431
+ return interp_3px(w4, 4.0, w3, 1.0, w1, 1.0);
1432
+ }
1433
+ if (_matchMask(pattern, 191, 55) || _matchMask(pattern, 219, 19))
1434
+ {
1435
+ return interp_3px(w4, 5.0, w1, 2.0, w3, 1.0);
1436
+ }
1437
+ if (_matchMask(pattern, 219, 73) || _matchMask(pattern, 239, 109))
1438
+ {
1439
+ return interp_3px(w4, 5.0, w3, 2.0, w1, 1.0);
1440
+ }
1441
+ if (_matchMask(pattern, 27, 3) || _matchMask(pattern, 79, 67) || _matchMask(pattern, 139, 131) || _matchMask(pattern, 107, 67))
1442
+ {
1443
+ return interp_2px(w4, 3.0, w3, 1.0);
1444
+ }
1445
+ if (_matchMask(pattern, 75, 9) || _matchMask(pattern, 139, 137) || _matchMask(pattern, 31, 25) || _matchMask(pattern, 59, 25))
1446
+ {
1447
+ return interp_2px(w4, 3.0, w1, 1.0);
1448
+ }
1449
+ if (_matchMask(pattern, 126, 42) || _matchMask(pattern, 239, 171) || _matchMask(pattern, 191, 143) || _matchMask(pattern, 126, 14))
1450
+ {
1451
+ return interp_3px(w4, 2.0, w3, 3.0, w1, 3.0);
1452
+ }
1453
+ if (_matchMask(pattern, 251, 106) || _matchMask(pattern, 111, 110) || _matchMask(pattern, 63, 62) || _matchMask(pattern, 251, 250) ||
1454
+ _matchMask(pattern, 223, 222) || _matchMask(pattern, 223, 30))
1455
+ {
1456
+ return interp_2px(w4, 3.0, w0, 1.0);
1457
+ }
1458
+ if (_matchMask(pattern, 10, 0) || _matchMask(pattern, 79, 75) || _matchMask(pattern, 159, 27) || _matchMask(pattern, 47, 11) ||
1459
+ _matchMask(pattern, 190, 10) || _matchMask(pattern, 238, 10) || _matchMask(pattern, 126, 10) || _matchMask(pattern, 235, 75) ||
1460
+ _matchMask(pattern, 59, 27))
1461
+ {
1462
+ return interp_3px(w4, 2.0, w3, 1.0, w1, 1.0);
1463
+ }
1464
+
1465
+ return interp_3px(w4, 6.0, w3, 1.0, w1, 1.0);
1466
+ }
1467
+
1468
+ void main()
1469
+ {
1470
+ gl_FragColor = scale(tex, texCoord, texSize);
1471
+ }
1472
+ [shader]
1473
+ name=hq2x
1474
+ author=Lior Halphon
1475
+ description="High Quality" 2x scaling
1476
+ passes=1
1477
+
1478
+ [pass.0]
1479
+ fragmentShader=hq2x.fs
1480
+ blend=0
1481
+ width=-2
1482
+ height=-2
1483
+ /*
1484
+ LCD Shader
1485
+
1486
+ Copyright (C) 2017 Dominus Iniquitatis - zerosaiko@gmail.com
1487
+
1488
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1489
+ of this software and associated documentation files (the "Software"), to deal
1490
+ in the Software without restriction, including without limitation the rights
1491
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1492
+ copies of the Software, and to permit persons to whom the Software is
1493
+ furnished to do so, subject to the following conditions:
1494
+ The above copyright notice and this permission notice shall be included in
1495
+ all copies or substantial portions of the Software.
1496
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1497
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1498
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1499
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1500
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1501
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1502
+ THE SOFTWARE.
1503
+ */
1504
+
1505
+ uniform sampler2D tex;
1506
+ uniform vec2 texSize;
1507
+ varying vec2 texCoord;
1508
+
1509
+ uniform float boundBrightness;
1510
+
1511
+ void main()
1512
+ {
1513
+ vec4 color = texture2D(tex, texCoord);
1514
+
1515
+ if (int(mod(texCoord.s * texSize.x * 3.0, 3.0)) == 0 ||
1516
+ int(mod(texCoord.t * texSize.y * 3.0, 3.0)) == 0)
1517
+ {
1518
+ color.rgb *= vec3(1.0, 1.0, 1.0) * boundBrightness;
1519
+ }
1520
+
1521
+ gl_FragColor = color;
1522
+ }
1523
+ [shader]
1524
+ name=LCD
1525
+ author=Dominus Iniquitatis
1526
+ description=Simple LCD emulation.
1527
+ passes=1
1528
+
1529
+ [pass.0]
1530
+ fragmentShader=lcd.fs
1531
+ blend=1
1532
+ width=-3
1533
+ height=-3
1534
+
1535
+ [pass.0.uniform.boundBrightness]
1536
+ type=float
1537
+ readableName=Bound brightness
1538
+ default=0.9
1539
+ min=0.0
1540
+ max=1.0
1541
+ [shader]
1542
+ name=MMPX
1543
+ author=Morgan McGuire & Mara Gagiu
1544
+ description=Style-Preserving Pixel Art Magnification
1545
+ passes=1
1546
+
1547
+ [pass.0]
1548
+ fragmentShader=mmpx.fs
1549
+ blend=1
1550
+ width=-2
1551
+ height=-2
1552
+ // Copyright 2020 Morgan McGuire & Mara Gagiu,
1553
+ // provided under the Open Source MIT license https://opensource.org/licenses/MIT
1554
+
1555
+ varying vec2 texCoord;
1556
+ uniform sampler2D tex;
1557
+ uniform vec2 texSize;
1558
+
1559
+ float luma(vec4 C) {
1560
+ return (C.r + C.g + C.b + 1.) * (1. - C.a);
1561
+ }
1562
+
1563
+ bool all_eq2(vec4 B, vec4 A0, vec4 A1) {
1564
+ return all(bvec2(B == A0, B == A1));
1565
+ }
1566
+
1567
+ bool all_eq3(vec4 B, vec4 A0, vec4 A1, vec4 A2) {
1568
+ return all(bvec3(B == A0, B == A1, B == A2));
1569
+ }
1570
+
1571
+ bool all_eq4(vec4 B, vec4 A0, vec4 A1, vec4 A2, vec4 A3) {
1572
+ return all(bvec4(B == A0, B == A1, B == A2, B == A3));
1573
+ }
1574
+
1575
+ bool any_eq2(vec4 B, vec4 A0, vec4 A1) {
1576
+ return any(bvec2(B == A0, B == A1));
1577
+ }
1578
+
1579
+ bool any_eq3(vec4 B, vec4 A0, vec4 A1, vec4 A2) {
1580
+ return any(bvec3(B == A0, B == A1, B == A2));
1581
+ }
1582
+
1583
+ bool any_eq4(vec4 B, vec4 A0, vec4 A1, vec4 A2, vec4 A3) {
1584
+ return any(bvec4(B == A0, B == A1, B == A2, B == A3));
1585
+ }
1586
+
1587
+ vec4 src(vec2 offset) {
1588
+ vec2 coord = texCoord + offset / texSize;
1589
+ return texture2D(tex, coord);
1590
+ }
1591
+
1592
+ void main() {
1593
+ vec4 A = src(vec2(-1., -1.));
1594
+ vec4 B = src(vec2( 0., -1.));
1595
+ vec4 C = src(vec2(+1., -1.));
1596
+
1597
+ vec4 D = src(vec2(-1., 0.));
1598
+ vec4 E = src(vec2( 0., 0.));
1599
+ vec4 F = src(vec2(+1., 0.));
1600
+
1601
+ vec4 G = src(vec2(-1., +1.));
1602
+ vec4 H = src(vec2( 0., +1.));
1603
+ vec4 I = src(vec2(+1., +1.));
1604
+
1605
+ vec4 J = E;
1606
+ vec4 K = E;
1607
+ vec4 L = E;
1608
+ vec4 M = E;
1609
+
1610
+ bvec3 top = bvec3(A == E, B == E, C == E);
1611
+ bvec3 mid = bvec3(D == E, true, F == E);
1612
+ bvec3 bot = bvec3(G == E, H == E, I == E);
1613
+
1614
+ if (!all(top) || !all(mid) || !all(bot)) {
1615
+ vec4 P = src(vec2(0., -2.));
1616
+ vec4 S = src(vec2(0., +2.));
1617
+ vec4 Q = src(vec2(-2., 0.));
1618
+ vec4 R = src(vec2(+2., 0.));
1619
+ float Bl = luma(B);
1620
+ float Dl = luma(D);
1621
+ float El = luma(E);
1622
+ float Fl = luma(F);
1623
+ float Hl = luma(H);
1624
+
1625
+ // P
1626
+ // A B C
1627
+ // Q D E F R
1628
+ // G H I
1629
+ // R
1630
+
1631
+ // 1:1 slope rules
1632
+ if (
1633
+ (D == B && D != H && D != F) &&
1634
+ (El >= Dl || E == A) &&
1635
+ any_eq3(E, A, C, G) &&
1636
+ ((El < Dl) || A != D || E != P || E != Q)
1637
+ ) J = D;
1638
+ if (
1639
+ (B == F && B != D && B != H) &&
1640
+ (El >= Bl || E == C) &&
1641
+ any_eq3(E, A, C, I) &&
1642
+ ((El < Bl) || C != B || E != P || E != R)
1643
+ ) K = B;
1644
+ if (
1645
+ (H == D && H != F && H != B) &&
1646
+ (El >= Hl || E == G) &&
1647
+ any_eq3(E, A, G, I) &&
1648
+ ((El < Hl) || G != H || E != S || E != Q)
1649
+ ) L = H;
1650
+ if (
1651
+ (F == H && F != B && F != D) &&
1652
+ (El >= Fl || E == I) &&
1653
+ any_eq3(E, C, G, I) &&
1654
+ ((El < Fl) || I != H || E != R || E != S)
1655
+ ) M = F;
1656
+
1657
+ // Intersection rules
1658
+ if (
1659
+ E != F &&
1660
+ all_eq4(E, C, I, D, Q) &&
1661
+ all_eq2(F, B, H) &&
1662
+ F != src(vec2(+3., 0.))
1663
+ ) K = M = F;
1664
+ if (
1665
+ E != D &&
1666
+ all_eq4(E, A, G, F, R) &&
1667
+ all_eq2(D, B, H) &&
1668
+ D != src(vec2(-3., 0.))
1669
+ ) J = L = D;
1670
+ if (
1671
+ E != H &&
1672
+ all_eq4(E, G, I, B, P) &&
1673
+ all_eq2(H, D, F) &&
1674
+ H != src(vec2( 0., +3.))
1675
+ ) L = M = H;
1676
+ if (
1677
+ E != B &&
1678
+ all_eq4(E, A, C, H, S) &&
1679
+ all_eq2(B, D, F) &&
1680
+ B != src(vec2( 0., -3.))
1681
+ ) J = K = B;
1682
+
1683
+ if (
1684
+ Bl < El &&
1685
+ all_eq4(E, G, H, I, S) &&
1686
+ !any_eq4(E, A, D, C, F)
1687
+ ) J = K = B;
1688
+ if (
1689
+ Hl < El &&
1690
+ all_eq4(E, A, B, C, P) &&
1691
+ !any_eq4(E, D, G, I, F)
1692
+ ) L = M = H;
1693
+ if (
1694
+ Fl < El &&
1695
+ all_eq4(E, A, D, G, Q) &&
1696
+ !any_eq4(E, B, C, I, H)
1697
+ ) K = M = F;
1698
+ if (
1699
+ Dl < El &&
1700
+ all_eq4(E, C, F, I, R) &&
1701
+ !any_eq4(E, B, A, G, H)
1702
+ ) J = L = D;
1703
+
1704
+ // 2:1 slope rules
1705
+ if (H != B) {
1706
+ if (H != A && H != E && H != C) {
1707
+ if (all_eq3(H, G, F, R) && !any_eq2(H, D, src(vec2(+2., -1.)))) L = M;
1708
+ if (all_eq3(H, I, D, Q) && !any_eq2(H, F, src(vec2(-2., -1.)))) M = L;
1709
+ }
1710
+
1711
+ if (B != I && B != G && B != E) {
1712
+ if (all_eq3(B, A, F, R) && !any_eq2(B, D, src(vec2(+2., +1.)))) J = K;
1713
+ if (all_eq3(B, C, D, Q) && !any_eq2(B, F, src(vec2(-2., +1.)))) K = J;
1714
+ }
1715
+ }
1716
+
1717
+ if (F != D) {
1718
+ if (D != I && D != E && D != C) {
1719
+ if (all_eq3(D, A, H, S) && !any_eq2(D, B, src(vec2(+1., +2.)))) J = L;
1720
+ if (all_eq3(D, G, B, P) && !any_eq2(D, H, src(vec2(+1., -2.)))) L = J;
1721
+ }
1722
+
1723
+ if (F != E && F != A && F != G) {
1724
+ if (all_eq3(F, C, H, S) && !any_eq2(F, B, src(vec2(-1., +2.)))) K = M;
1725
+ if (all_eq3(F, I, B, P) && !any_eq2(F, H, src(vec2(-1., -2.)))) M = K;
1726
+ }
1727
+ }
1728
+ }
1729
+
1730
+ if (fract((texCoord * texSize).x) < 0.5) {
1731
+ if (fract((texCoord * texSize).y) < 0.5) {
1732
+ gl_FragColor = J;
1733
+ } else {
1734
+ gl_FragColor = L;
1735
+ }
1736
+ } else {
1737
+ if (fract((texCoord * texSize).y) < 0.5) {
1738
+ gl_FragColor = K;
1739
+ } else {
1740
+ gl_FragColor = M;
1741
+ }
1742
+ }
1743
+ }
1744
+ [shader]
1745
+ name=Motion Blur
1746
+ author=Dominus Iniquitatis
1747
+ description=Simple motion blur.
1748
+ passes=1
1749
+
1750
+ [pass.0]
1751
+ fragmentShader=motion_blur.fs
1752
+ blend=1
1753
+ width=-1
1754
+ height=-1
1755
+
1756
+ [pass.0.uniform.amount]
1757
+ type=float
1758
+ readableName=Amount
1759
+ default=0.3
1760
+ min=0.0
1761
+ max=1.0
1762
+ /*
1763
+ Motion Blur Shader
1764
+
1765
+ Copyright (C) 2017 Dominus Iniquitatis - zerosaiko@gmail.com
1766
+
1767
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1768
+ of this software and associated documentation files (the "Software"), to deal
1769
+ in the Software without restriction, including without limitation the rights
1770
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1771
+ copies of the Software, and to permit persons to whom the Software is
1772
+ furnished to do so, subject to the following conditions:
1773
+ The above copyright notice and this permission notice shall be included in
1774
+ all copies or substantial portions of the Software.
1775
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1776
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1777
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1778
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1779
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1780
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1781
+ THE SOFTWARE.
1782
+ */
1783
+
1784
+ uniform sampler2D tex;
1785
+ uniform vec2 texSize;
1786
+ varying vec2 texCoord;
1787
+
1788
+ uniform float amount;
1789
+
1790
+ void main()
1791
+ {
1792
+ vec4 color = texture2D(tex, texCoord);
1793
+ color.a = 1.0 - amount;
1794
+
1795
+ gl_FragColor = color;
1796
+ }
1797
+ [shader]
1798
+ name=Nintendo DS Color
1799
+ author=Pokefan531 and hunterk
1800
+ description=Shader that replicates the LCD Colorspace from a Nintendo DS Phat.
1801
+ passes=1
1802
+
1803
+ [pass.0]
1804
+ fragmentShader=nds-color.fs
1805
+ vertexShader=nds-color.vs
1806
+ blend=1
1807
+ width=-1
1808
+ height=-1
1809
+
1810
+ [pass.0.uniform.color_mode]
1811
+ type=int
1812
+ default=1
1813
+ min=1
1814
+ max=3
1815
+ readableName=Color Profile (1=sRGB, 2=DCI, 3=Rec2020)
1816
+ // Shader that replicates the LCD Colorspace from a Nintendo DS Phat --
1817
+ varying vec2 texCoord;
1818
+ varying mat4 profile;
1819
+ uniform sampler2D tex;
1820
+ uniform vec2 texSize;
1821
+
1822
+ const float target_gamma = 2.2;
1823
+ const float display_gamma = 2.2;
1824
+
1825
+ void main() {
1826
+ // bring out our stored luminance value
1827
+ float lum = profile[3].w;
1828
+
1829
+ // our adjustments need to happen in linear gamma
1830
+ vec4 screen = pow(texture2D(tex, texCoord), vec4(target_gamma)).rgba;
1831
+
1832
+ screen = clamp(screen * lum, 0.0, 1.0);
1833
+ screen = profile * screen;
1834
+ gl_FragColor = pow(screen, vec4(1.0 / display_gamma));
1835
+ }
1836
+ uniform int color_mode;
1837
+ attribute vec4 position;
1838
+ varying vec2 texCoord;
1839
+ varying mat4 profile;
1840
+
1841
+ const mat4 NDS_sRGB = mat4(
1842
+ 0.835, 0.10, 0.105, 0.0, //red channel
1843
+ 0.27, 0.6375, 0.175, 0.0, //green channel
1844
+ -0.105, 0.2625, 0.72, 0.0, //blue channel
1845
+ 0.0, 0.0, 0.0, 0.905 //alpha channel
1846
+ );
1847
+
1848
+ const mat4 NDS_DCI = mat4(
1849
+ 0.70, 0.125, 0.12, 0.0, //red channel
1850
+ 0.34, 0.625, 0.20, 0.0, //green channel
1851
+ -0.04, 0.25, 0.68, 0.0, //blue channel
1852
+ 0.0, 0.0, 0.0, 0.96 //alpha channel
1853
+ );
1854
+
1855
+ const mat4 NDS_Rec2020 = mat4(
1856
+ 0.555, 0.1475, 0.1175, 0.0, //red channel
1857
+ 0.39, 0.6075, 0.2075, 0.0, //green channel
1858
+ 0.055, 0.245, 0.675, 0.0, //blue channel
1859
+ 0.0, 0.0, 0.0, 1.0 //alpha channel
1860
+ );
1861
+
1862
+ void main() {
1863
+ if (color_mode == 1) profile = NDS_sRGB;
1864
+ else if (color_mode == 2) profile = NDS_DCI;
1865
+ else if (color_mode == 3) profile = NDS_Rec2020;
1866
+
1867
+ gl_Position = position;
1868
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
1869
+ }
1870
+ [shader]
1871
+ name=NSO GBA Color
1872
+ author=Pokefan531 and hunterk
1873
+ description=Shader that replicates the Nintendo Switch Online's GBA color filter.
1874
+ passes=1
1875
+
1876
+ [pass.0]
1877
+ fragmentShader=nso-gba-color.fs
1878
+ vertexShader=nso-gba-color.vs
1879
+ blend=1
1880
+ width=-1
1881
+ height=-1
1882
+
1883
+ [pass.0.uniform.darken_screen]
1884
+ type=float
1885
+ default=0.8
1886
+ min=0
1887
+ max=1
1888
+ readableName=Darken Screen
1889
+
1890
+ [pass.0.uniform.color_mode]
1891
+ type=int
1892
+ default=1
1893
+ min=1
1894
+ max=3
1895
+ readableName=Color Profile (1=sRGB, 2=DCI, 3=Rec2020)
1896
+ // Shader that replicates the LCD Colorspace from Gameboy Advance --
1897
+ varying vec2 texCoord;
1898
+ varying mat4 profile;
1899
+ uniform sampler2D tex;
1900
+ uniform vec2 texSize;
1901
+
1902
+ uniform float darken_screen;
1903
+ const float target_gamma = 2.2;
1904
+ const float display_gamma = 2.2;
1905
+
1906
+ void main() {
1907
+ // bring out our stored luminance value
1908
+ float lum = profile[3].w;
1909
+
1910
+ // our adjustments need to happen in linear gamma
1911
+ vec4 screen = pow(texture2D(tex, texCoord), vec4(target_gamma + darken_screen)).rgba;
1912
+
1913
+ screen = clamp(screen * lum, 0.0, 1.0);
1914
+ screen = profile * screen;
1915
+ gl_FragColor = pow(screen, vec4(1.0 / display_gamma));
1916
+ }
1917
+ uniform int color_mode;
1918
+ attribute vec4 position;
1919
+ varying vec2 texCoord;
1920
+ varying mat4 profile;
1921
+
1922
+ const mat4 GBA_sRGB = mat4(
1923
+ 0.865, 0.0575, 0.0575, 0.0, //red channel
1924
+ 0.1225, 0.925, 0.1225, 0.0, //green channel
1925
+ 0.0125, 0.0125, 0.82, 0.0, //blue channel
1926
+ 0.0, 0.0, 0.0, 1.0 //alpha channel
1927
+ );
1928
+
1929
+ const mat4 GBA_DCI = mat4(
1930
+ 0.72, 0.0875, 0.0725, 0.0, //red channel
1931
+ 0.2675, 0.9, 0.185, 0.0, //green channel
1932
+ 0.0125, 0.0125, 0.7425, 0.0, //blue channel
1933
+ 0.0, 0.0, 0.0, 1.0 //alpha channel
1934
+ );
1935
+
1936
+ const mat4 GBA_Rec2020 = mat4(
1937
+ 0.57, 0.115, 0.0725, 0.0, //red channel
1938
+ 0.3825, 0.8625, 0.195, 0.0, //green channel
1939
+ 0.0475, 0.0225, 0.7325, 0.0, //blue channel
1940
+ 0.0, 0.0, 0.0, 1.0 //alpha channel
1941
+ );
1942
+
1943
+ void main() {
1944
+ if (color_mode == 1) profile = GBA_sRGB;
1945
+ else if (color_mode == 2) profile = GBA_DCI;
1946
+ else if (color_mode == 3) profile = GBA_Rec2020;
1947
+
1948
+ gl_Position = position;
1949
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
1950
+ }
1951
+ [shader]
1952
+ name=NSO GBC Color
1953
+ author=Pokefan531 and hunterk
1954
+ description=Shader that replicates the Nintendo Switch Online's GBC color filter.
1955
+ passes=1
1956
+
1957
+ [pass.0]
1958
+ fragmentShader=nso-gbc-color.fs
1959
+ vertexShader=nso-gbc-color.vs
1960
+ blend=1
1961
+ width=-1
1962
+ height=-1
1963
+
1964
+ [pass.0.uniform.lighten_screen]
1965
+ type=float
1966
+ default=0.0
1967
+ min=0
1968
+ max=1
1969
+ readableName=Lighten Screen
1970
+
1971
+ [pass.0.uniform.color_mode]
1972
+ type=int
1973
+ default=1
1974
+ min=1
1975
+ max=3
1976
+ readableName=Color Profile (1=sRGB, 2=DCI, 3=Rec2020)
1977
+ // Shader that replicates the Nintendo Switch Online's GBC color filter --
1978
+ varying vec2 texCoord;
1979
+ varying mat4 profile;
1980
+ uniform sampler2D tex;
1981
+ uniform vec2 texSize;
1982
+
1983
+ uniform float lighten_screen;
1984
+
1985
+ void main() {
1986
+ // bring out our stored luminance value
1987
+ float lum = profile[3].w;
1988
+
1989
+ // our adjustments need to happen in linear gamma
1990
+ vec4 screen = pow(texture2D(tex, texCoord), vec4(1.24, 0.8, 0.7, 1.0)).rgba;
1991
+
1992
+ screen = clamp(screen * lum, 0.0, 1.0);
1993
+ screen = profile * screen;
1994
+ gl_FragColor = pow(screen, vec4(1.0));
1995
+ }
1996
+ uniform int color_mode;
1997
+ attribute vec4 position;
1998
+ varying vec2 texCoord;
1999
+ varying mat4 profile;
2000
+
2001
+ const mat4 GBC_sRGB = mat4(
2002
+ 0.84, 0.105, 0.15, 0.0, //red channel
2003
+ 0.265, 0.67, 0.30, 0.0, //green channel
2004
+ 0.0, 0.24, 0.525, 0.0, //blue channel
2005
+ 0.175, 0.18, 0.18, 0.85 //alpha channel
2006
+ );
2007
+
2008
+ const mat4 GBC_DCI = mat4(
2009
+ 0.84, 0.105, 0.15, 0.0, //red channel
2010
+ 0.265, 0.67, 0.30, 0.0, //green channel
2011
+ 0.0, 0.24, 0.525, 0.0, //blue channel
2012
+ 0.175, 0.18, 0.18, 1.0 //alpha channel
2013
+ );
2014
+
2015
+ const mat4 GBC_Rec2020 = mat4(
2016
+ 0.84, 0.105, 0.15, 0.0, //red channel
2017
+ 0.265, 0.67, 0.30, 0.0, //green channel
2018
+ 0.0, 0.24, 0.525, 0.0, //blue channel
2019
+ 0.175, 0.18, 0.18, 1.0 //alpha channel
2020
+ );
2021
+
2022
+ void main() {
2023
+ if (color_mode == 1) profile = GBC_sRGB;
2024
+ else if (color_mode == 2) profile = GBC_DCI;
2025
+ else if (color_mode == 3) profile = GBC_Rec2020;
2026
+
2027
+ gl_Position = position;
2028
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
2029
+ }
2030
+ [shader]
2031
+ name=OmniScale
2032
+ author=Lior Halphon
2033
+ description=Resolution-indepedent scaler inspired by the hqx family scalers
2034
+ passes=1
2035
+
2036
+ [pass.0]
2037
+ fragmentShader=omniscale.fs
2038
+ blend=0
2039
+ /* MIT License
2040
+ *
2041
+ * Copyright (c) 2015-2023 Lior Halphon
2042
+ *
2043
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
2044
+ * of this software and associated documentation files (the "Software"), to deal
2045
+ * in the Software without restriction, including without limitation the rights
2046
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2047
+ * copies of the Software, and to permit persons to whom the Software is
2048
+ * furnished to do so, subject to the following conditions:
2049
+ *
2050
+ * The above copyright notice and this permission notice shall be included in all
2051
+ * copies or substantial portions of the Software.
2052
+ *
2053
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2054
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2055
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2056
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2057
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2058
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2059
+ * SOFTWARE.
2060
+ */
2061
+ /* OmniScale is derived from the pattern based design of HQnx, but with the following general differences:
2062
+ - The actual output calculating was completely redesigned as resolution independent graphic generator. This allows
2063
+ scaling to any factor.
2064
+ - HQnx approximations that were good enough for a 2x/3x/4x factor were refined, creating smoother gradients.
2065
+ - "Quarters" can be interpolated in more ways than in the HQnx filters
2066
+ - If a pattern does not provide enough information to determine the suitable scaling interpolation, up to 16 pixels
2067
+ per quarter are sampled (in contrast to the usual 9) in order to determine the best interpolation.
2068
+ */
2069
+
2070
+ varying vec2 texCoord;
2071
+ uniform sampler2D tex;
2072
+ uniform vec2 texSize;
2073
+ uniform vec2 outputSize;
2074
+
2075
+ float _bit(float v, int i)
2076
+ {
2077
+ // v is an integer value stored as float
2078
+ float p = exp2(float(i)); // 2^i, GLSL ES 1.00-friendly
2079
+ return floor(mod(floor(v / p), 2.0));
2080
+ }
2081
+
2082
+ bool _matchMask(float pattern, int mask, int ref)
2083
+ {
2084
+ // (pattern & mask) == ref, implemented without bitwise ops.
2085
+ float m = float(mask);
2086
+ float r = float(ref);
2087
+ float mism = 0.0;
2088
+ for (int i = 0; i < 15; ++i)
2089
+ {
2090
+ float mb = _bit(m, i);
2091
+ if (mb > 0.5)
2092
+ {
2093
+ float pb = _bit(pattern, i);
2094
+ float rb = _bit(r, i);
2095
+ mism += abs(pb - rb);
2096
+ }
2097
+ }
2098
+ return mism < 0.5;
2099
+ }
2100
+
2101
+ /* We use the same colorspace as the HQ algorithms. */
2102
+ vec3 rgb_to_hq_colospace(vec4 rgb)
2103
+ {
2104
+ return vec3(
2105
+ 0.250 * rgb.r + 0.250 * rgb.g + 0.250 * rgb.b,
2106
+ 0.250 * rgb.r - 0.000 * rgb.g - 0.250 * rgb.b,
2107
+ -0.125 * rgb.r + 0.250 * rgb.g - 0.125 * rgb.b
2108
+ );
2109
+ }
2110
+
2111
+ bool is_different(vec4 a, vec4 b)
2112
+ {
2113
+ vec3 diff = abs(rgb_to_hq_colospace(a) - rgb_to_hq_colospace(b));
2114
+ return diff.x > 0.018 || diff.y > 0.002 || diff.z > 0.005;
2115
+ }
2116
+
2117
+ // WebGL1: no bitwise ops in GLSL ES 1.00
2118
+
2119
+ vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 output_resolution)
2120
+ {
2121
+ // o = offset, the width of a pixel
2122
+ vec2 o = vec2(1.0, 1.0) / input_resolution;
2123
+
2124
+ /* We always calculate the top left quarter. If we need a different quarter, we flip our co-ordinates */
2125
+
2126
+ // p = the position within a pixel [0...1]
2127
+ vec2 p = fract(position * input_resolution);
2128
+
2129
+ if (p.x > 0.5)
2130
+ {
2131
+ o.x = -o.x;
2132
+ p.x = 1.0 - p.x;
2133
+ }
2134
+ if (p.y > 0.5)
2135
+ {
2136
+ o.y = -o.y;
2137
+ p.y = 1.0 - p.y;
2138
+ }
2139
+
2140
+ vec4 w0 = texture2D(image, position + vec2(-o.x, -o.y));
2141
+ vec4 w1 = texture2D(image, position + vec2( 0.0, -o.y));
2142
+ vec4 w2 = texture2D(image, position + vec2( o.x, -o.y));
2143
+ vec4 w3 = texture2D(image, position + vec2(-o.x, 0.0));
2144
+ vec4 w4 = texture2D(image, position + vec2( 0.0, 0.0));
2145
+ vec4 w5 = texture2D(image, position + vec2( o.x, 0.0));
2146
+ vec4 w6 = texture2D(image, position + vec2(-o.x, o.y));
2147
+ vec4 w7 = texture2D(image, position + vec2( 0.0, o.y));
2148
+ vec4 w8 = texture2D(image, position + vec2( o.x, o.y));
2149
+
2150
+ float pattern = 0.0;
2151
+ if (is_different(w0, w4)) pattern += 1.0;
2152
+ if (is_different(w1, w4)) pattern += 2.0;
2153
+ if (is_different(w2, w4)) pattern += 4.0;
2154
+ if (is_different(w3, w4)) pattern += 8.0;
2155
+ if (is_different(w5, w4)) pattern += 16.0;
2156
+ if (is_different(w6, w4)) pattern += 32.0;
2157
+ if (is_different(w7, w4)) pattern += 64.0;
2158
+ if (is_different(w8, w4)) pattern += 128.0;
2159
+
2160
+ // NOTE: hex literals (0x..) are not GLSL ES 1.00. Converted to decimal.
2161
+
2162
+ if ((_matchMask(pattern, 191, 55) || _matchMask(pattern, 219, 19)) && is_different(w1, w5))
2163
+ {
2164
+ return mix(w4, w3, 0.5 - p.x);
2165
+ }
2166
+ if ((_matchMask(pattern, 219, 73) || _matchMask(pattern, 239, 109)) && is_different(w7, w3))
2167
+ {
2168
+ return mix(w4, w1, 0.5 - p.y);
2169
+ }
2170
+ if ((_matchMask(pattern, 11, 11) || _matchMask(pattern, 254, 74) || _matchMask(pattern, 254, 26)) && is_different(w3, w1))
2171
+ {
2172
+ return w4;
2173
+ }
2174
+ if ((_matchMask(pattern, 111, 42) || _matchMask(pattern, 91, 10) || _matchMask(pattern, 191, 58) || _matchMask(pattern, 223, 90) ||
2175
+ _matchMask(pattern, 159, 138) || _matchMask(pattern, 207, 138) || _matchMask(pattern, 239, 78) || _matchMask(pattern, 63, 14) ||
2176
+ _matchMask(pattern, 251, 90) || _matchMask(pattern, 187, 138) || _matchMask(pattern, 127, 90) || _matchMask(pattern, 175, 138) ||
2177
+ _matchMask(pattern, 235, 138)) && is_different(w3, w1))
2178
+ {
2179
+ return mix(w4, mix(w4, w0, 0.5 - p.x), 0.5 - p.y);
2180
+ }
2181
+ if (_matchMask(pattern, 11, 8))
2182
+ {
2183
+ return mix(mix(w0 * 0.375 + w1 * 0.25 + w4 * 0.375, w4 * 0.5 + w1 * 0.5, p.x * 2.0), w4, p.y * 2.0);
2184
+ }
2185
+ if (_matchMask(pattern, 11, 2))
2186
+ {
2187
+ return mix(mix(w0 * 0.375 + w3 * 0.25 + w4 * 0.375, w4 * 0.5 + w3 * 0.5, p.y * 2.0), w4, p.x * 2.0);
2188
+ }
2189
+ if (_matchMask(pattern, 47, 47))
2190
+ {
2191
+ float dist = length(p - vec2(0.5));
2192
+ float pixel_size = length(1.0 / (output_resolution / input_resolution));
2193
+ if (dist < 0.5 - pixel_size / 2.0)
2194
+ {
2195
+ return w4;
2196
+ }
2197
+ vec4 r;
2198
+ if (is_different(w0, w1) || is_different(w0, w3))
2199
+ {
2200
+ r = mix(w1, w3, p.y - p.x + 0.5);
2201
+ }
2202
+ else
2203
+ {
2204
+ r = mix(mix(w1 * 0.375 + w0 * 0.25 + w3 * 0.375, w3, p.y * 2.0), w1, p.x * 2.0);
2205
+ }
2206
+
2207
+ if (dist > 0.5 + pixel_size / 2.0)
2208
+ {
2209
+ return r;
2210
+ }
2211
+ return mix(w4, r, (dist - 0.5 + pixel_size / 2.0) / pixel_size);
2212
+ }
2213
+ if (_matchMask(pattern, 191, 55) || _matchMask(pattern, 219, 19))
2214
+ {
2215
+ float dist = p.x - 2.0 * p.y;
2216
+ float pixel_size = length(1.0 / (output_resolution / input_resolution)) * sqrt(5.0);
2217
+ if (dist > pixel_size / 2.0)
2218
+ {
2219
+ return w1;
2220
+ }
2221
+ vec4 r = mix(w3, w4, p.x + 0.5);
2222
+ if (dist < -pixel_size / 2.0)
2223
+ {
2224
+ return r;
2225
+ }
2226
+ return mix(r, w1, (dist + pixel_size / 2.0) / pixel_size);
2227
+ }
2228
+ if (_matchMask(pattern, 219, 73) || _matchMask(pattern, 239, 109))
2229
+ {
2230
+ float dist = p.y - 2.0 * p.x;
2231
+ float pixel_size = length(1.0 / (output_resolution / input_resolution)) * sqrt(5.0);
2232
+ if (dist > pixel_size / 2.0)
2233
+ {
2234
+ return w3;
2235
+ }
2236
+ vec4 r = mix(w1, w4, p.x + 0.5);
2237
+ if (dist < -pixel_size / 2.0)
2238
+ {
2239
+ return r;
2240
+ }
2241
+ return mix(r, w3, (dist + pixel_size / 2.0) / pixel_size);
2242
+ }
2243
+ if (_matchMask(pattern, 191, 143) || _matchMask(pattern, 126, 14))
2244
+ {
2245
+ float dist = p.x + 2.0 * p.y;
2246
+ float pixel_size = length(1.0 / (output_resolution / input_resolution)) * sqrt(5.0);
2247
+
2248
+ if (dist > 1.0 + pixel_size / 2.0)
2249
+ {
2250
+ return w4;
2251
+ }
2252
+
2253
+ vec4 r;
2254
+ if (is_different(w0, w1) || is_different(w0, w3))
2255
+ {
2256
+ r = mix(w1, w3, p.y - p.x + 0.5);
2257
+ }
2258
+ else
2259
+ {
2260
+ r = mix(mix(w1 * 0.375 + w0 * 0.25 + w3 * 0.375, w3, p.y * 2.0), w1, p.x * 2.0);
2261
+ }
2262
+
2263
+ if (dist < 1.0 - pixel_size / 2.0)
2264
+ {
2265
+ return r;
2266
+ }
2267
+
2268
+ return mix(r, w4, (dist + pixel_size / 2.0 - 1.0) / pixel_size);
2269
+ }
2270
+
2271
+ if (_matchMask(pattern, 126, 42) || _matchMask(pattern, 239, 171))
2272
+ {
2273
+ float dist = p.y + 2.0 * p.x;
2274
+ float pixel_size = length(1.0 / (output_resolution / input_resolution)) * sqrt(5.0);
2275
+
2276
+ if (dist > 1.0 + pixel_size / 2.0)
2277
+ {
2278
+ return w4;
2279
+ }
2280
+
2281
+ vec4 r;
2282
+
2283
+ if (is_different(w0, w1) || is_different(w0, w3))
2284
+ {
2285
+ r = mix(w1, w3, p.y - p.x + 0.5);
2286
+ }
2287
+ else
2288
+ {
2289
+ r = mix(mix(w1 * 0.375 + w0 * 0.25 + w3 * 0.375, w3, p.y * 2.0), w1, p.x * 2.0);
2290
+ }
2291
+
2292
+ if (dist < 1.0 - pixel_size / 2.0)
2293
+ {
2294
+ return r;
2295
+ }
2296
+
2297
+ return mix(r, w4, (dist + pixel_size / 2.0 - 1.0) / pixel_size);
2298
+ }
2299
+
2300
+ if (_matchMask(pattern, 27, 3) || _matchMask(pattern, 79, 67) || _matchMask(pattern, 139, 131) || _matchMask(pattern, 107, 67))
2301
+ {
2302
+ return mix(w4, w3, 0.5 - p.x);
2303
+ }
2304
+
2305
+ if (_matchMask(pattern, 75, 9) || _matchMask(pattern, 139, 137) || _matchMask(pattern, 31, 25) || _matchMask(pattern, 59, 25))
2306
+ {
2307
+ return mix(w4, w1, 0.5 - p.y);
2308
+ }
2309
+
2310
+ if (_matchMask(pattern, 251, 106) || _matchMask(pattern, 111, 110) || _matchMask(pattern, 63, 62) || _matchMask(pattern, 251, 250) ||
2311
+ _matchMask(pattern, 223, 222) || _matchMask(pattern, 223, 30))
2312
+ {
2313
+ return mix(w4, w0, (1.0 - p.x - p.y) / 2.0);
2314
+ }
2315
+
2316
+ if (_matchMask(pattern, 79, 75) || _matchMask(pattern, 159, 27) || _matchMask(pattern, 47, 11) ||
2317
+ _matchMask(pattern, 190, 10) || _matchMask(pattern, 238, 10) || _matchMask(pattern, 126, 10) || _matchMask(pattern, 235, 75) ||
2318
+ _matchMask(pattern, 59, 27))
2319
+ {
2320
+ float dist = p.x + p.y;
2321
+ float pixel_size = length(1.0 / (output_resolution / input_resolution));
2322
+
2323
+ if (dist > 0.5 + pixel_size / 2.0)
2324
+ {
2325
+ return w4;
2326
+ }
2327
+
2328
+ vec4 r;
2329
+ if (is_different(w0, w1) || is_different(w0, w3))
2330
+ {
2331
+ r = mix(w1, w3, p.y - p.x + 0.5);
2332
+ }
2333
+ else
2334
+ {
2335
+ r = mix(mix(w1 * 0.375 + w0 * 0.25 + w3 * 0.375, w3, p.y * 2.0), w1, p.x * 2.0);
2336
+ }
2337
+
2338
+ if (dist < 0.5 - pixel_size / 2.0)
2339
+ {
2340
+ return r;
2341
+ }
2342
+
2343
+ return mix(r, w4, (dist + pixel_size / 2.0 - 0.5) / pixel_size);
2344
+ }
2345
+
2346
+ if (_matchMask(pattern, 11, 1))
2347
+ {
2348
+ return mix(mix(w4, w3, 0.5 - p.x), mix(w1, (w1 + w3) / 2.0, 0.5 - p.x), 0.5 - p.y);
2349
+ }
2350
+
2351
+ if (_matchMask(pattern, 11, 0))
2352
+ {
2353
+ return mix(mix(w4, w3, 0.5 - p.x), mix(w1, w0, 0.5 - p.x), 0.5 - p.y);
2354
+ }
2355
+
2356
+ float dist = p.x + p.y;
2357
+ float pixel_size = length(1.0 / (output_resolution / input_resolution));
2358
+
2359
+ if (dist > 0.5 + pixel_size / 2.0)
2360
+ {
2361
+ return w4;
2362
+ }
2363
+
2364
+ /* We need more samples to "solve" this diagonal */
2365
+ vec4 x0 = texture2D(image, position + vec2(-o.x * 2.0, -o.y * 2.0));
2366
+ vec4 x1 = texture2D(image, position + vec2(-o.x , -o.y * 2.0));
2367
+ vec4 x2 = texture2D(image, position + vec2( 0.0 , -o.y * 2.0));
2368
+ vec4 x3 = texture2D(image, position + vec2( o.x , -o.y * 2.0));
2369
+ vec4 x4 = texture2D(image, position + vec2(-o.x * 2.0, -o.y ));
2370
+ vec4 x5 = texture2D(image, position + vec2(-o.x * 2.0, 0.0 ));
2371
+ vec4 x6 = texture2D(image, position + vec2(-o.x * 2.0, o.y ));
2372
+
2373
+ if (is_different(x0, w4)) pattern += exp2(8.0);
2374
+ if (is_different(x1, w4)) pattern += exp2(9.0);
2375
+ if (is_different(x2, w4)) pattern += exp2(10.0);
2376
+ if (is_different(x3, w4)) pattern += exp2(11.0);
2377
+ if (is_different(x4, w4)) pattern += exp2(12.0);
2378
+ if (is_different(x5, w4)) pattern += exp2(13.0);
2379
+ if (is_different(x6, w4)) pattern += exp2(14.0);
2380
+
2381
+ float diagonal_bias = -7.0;
2382
+ for (int i = 0; i < 15; ++i)
2383
+ {
2384
+ diagonal_bias += _bit(pattern, i);
2385
+ }
2386
+
2387
+ if (diagonal_bias <= 0.0)
2388
+ {
2389
+ vec4 r = mix(w1, w3, p.y - p.x + 0.5);
2390
+ if (dist < 0.5 - pixel_size / 2.0)
2391
+ {
2392
+ return r;
2393
+ }
2394
+ return mix(r, w4, (dist + pixel_size / 2.0 - 0.5) / pixel_size);
2395
+ }
2396
+
2397
+ return w4;
2398
+ }
2399
+
2400
+ void main()
2401
+ {
2402
+ gl_FragColor = scale(tex, texCoord, texSize, outputSize);
2403
+ }
2404
+ [shader]
2405
+ name=Pixelate
2406
+ author=endrift
2407
+ description=Only scale up the screen at an integer ratio
2408
+ passes=1
2409
+
2410
+ [pass.0]
2411
+ blend=1
2412
+ integerScaling=1
2413
+ [shader]
2414
+ name=Scale2x
2415
+ author=singron
2416
+ description=AdvanceMAME's Scale2x algorithm
2417
+ passes=1
2418
+
2419
+ [pass.0]
2420
+ fragmentShader=scale2x.fs
2421
+ blend=1
2422
+ width=-2
2423
+ height=-2
2424
+ /* Shader implementation of Scale2x is adapted from https://gist.github.com/singron/3161079 */
2425
+ varying vec2 texCoord;
2426
+ uniform sampler2D tex;
2427
+ uniform vec2 texSize;
2428
+
2429
+ void main() {
2430
+ // o = offset, the width of a pixel
2431
+ vec2 o = 1.0 / texSize;
2432
+
2433
+ // texel arrangement
2434
+ // A B C
2435
+ // D E F
2436
+ // G H I
2437
+ vec4 B = texture2D(tex, texCoord + vec2( 0.0, o.y));
2438
+ vec4 D = texture2D(tex, texCoord + vec2( -o.x, 0.0));
2439
+ vec4 E = texture2D(tex, texCoord + vec2( 0.0, 0.0));
2440
+ vec4 F = texture2D(tex, texCoord + vec2( o.x, 0.0));
2441
+ vec4 H = texture2D(tex, texCoord + vec2( 0.0, -o.y));
2442
+ vec2 p = texCoord * texSize;
2443
+ // p = the texCoord within a pixel [0...1]
2444
+ p = fract(p);
2445
+ if (p.x > .5) {
2446
+ if (p.y > .5) {
2447
+ // Top Right
2448
+ gl_FragColor = B == F && B != D && F != H ? F : E;
2449
+ } else {
2450
+ // Bottom Right
2451
+ gl_FragColor = H == F && D != H && B != F ? F : E;
2452
+ }
2453
+ } else {
2454
+ if (p.y > .5) {
2455
+ // Top Left
2456
+ gl_FragColor = D == B && B != F && D != H ? D : E;
2457
+ } else {
2458
+ // Bottom Left
2459
+ gl_FragColor = D == H && D != B && H != F ? D : E;
2460
+ }
2461
+ }
2462
+ }
2463
+ [shader]
2464
+ name=Scale4x
2465
+ author=singron, endrift
2466
+ description=AdvanceMAME's Scale4x algorithm
2467
+ passes=1
2468
+
2469
+ [pass.0]
2470
+ fragmentShader=scale4x.fs
2471
+ blend=1
2472
+ width=-4
2473
+ height=-4
2474
+ /* Shader implementation of Scale2x is adapted from https://gist.github.com/singron/3161079 */
2475
+ varying vec2 texCoord;
2476
+ uniform sampler2D tex;
2477
+ uniform vec2 texSize;
2478
+
2479
+ vec4 scale2x(vec4 pixels[5], vec2 p) {
2480
+ // texel arrangement
2481
+ // x 0 x
2482
+ // 1 2 3
2483
+ // x 4 x
2484
+ // p = the texCoord within a pixel [0...1]
2485
+ p = fract(p);
2486
+ if (p.x > .5) {
2487
+ if (p.y > .5) {
2488
+ // Top Right
2489
+ return pixels[0] == pixels[3] && pixels[0] != pixels[1] && pixels[3] != pixels[4] ? pixels[3] : pixels[2];
2490
+ } else {
2491
+ // Bottom Right
2492
+ return pixels[4] == pixels[3] && pixels[1] != pixels[4] && pixels[0] != pixels[3] ? pixels[3] : pixels[2];
2493
+ }
2494
+ } else {
2495
+ if (p.y > .5) {
2496
+ // Top Left
2497
+ return pixels[1] == pixels[0] && pixels[0] != pixels[3] && pixels[1] != pixels[4] ? pixels[1] : pixels[2];
2498
+ } else {
2499
+ // Bottom Left
2500
+ return pixels[1] == pixels[4] && pixels[1] != pixels[0] && pixels[4] != pixels[3] ? pixels[1] : pixels[2];
2501
+ }
2502
+ }
2503
+ }
2504
+
2505
+ vec4 scaleNeighborhood(vec2 p, vec2 x, vec2 o) {
2506
+ vec4 neighborhood[5];
2507
+ neighborhood[0] = texture2D(tex, texCoord + x + vec2( 0.0, o.y));
2508
+ neighborhood[1] = texture2D(tex, texCoord + x + vec2(-o.x, 0.0));
2509
+ neighborhood[2] = texture2D(tex, texCoord + x + vec2( 0.0, 0.0));
2510
+ neighborhood[3] = texture2D(tex, texCoord + x + vec2( o.x, 0.0));
2511
+ neighborhood[4] = texture2D(tex, texCoord + x + vec2( 0.0, -o.y));
2512
+ return scale2x(neighborhood, p + x * texSize);
2513
+ }
2514
+
2515
+ void main() {
2516
+ // o = offset, the width of a pixel
2517
+ vec2 o = 1.0 / texSize;
2518
+
2519
+ vec2 p = texCoord * texSize;
2520
+ vec4 pixels[5];
2521
+ pixels[0] = scaleNeighborhood(p, vec2( 0.0, o.y / 2.0), o);
2522
+ pixels[1] = scaleNeighborhood(p, vec2(-o.x / 2.0, 0.0), o);
2523
+ pixels[2] = scaleNeighborhood(p, vec2( 0.0, 0.0), o);
2524
+ pixels[3] = scaleNeighborhood(p, vec2( o.x / 2.0, 0.0), o);
2525
+ pixels[4] = scaleNeighborhood(p, vec2( 0.0, -o.y / 2.0), o);
2526
+ gl_FragColor = scale2x(pixels, p * 2.0);
2527
+ }
2528
+ [shader]
2529
+ name=Scanlines
2530
+ author=Dominus Iniquitatis
2531
+ description=Simple scanlines.
2532
+ passes=1
2533
+
2534
+ [pass.0]
2535
+ fragmentShader=scanlines.fs
2536
+ blend=1
2537
+ width=-2
2538
+ height=-2
2539
+
2540
+ [pass.0.uniform.lineBrightness]
2541
+ type=float
2542
+ readableName=Line brightness
2543
+ default=0.5
2544
+ min=0.0
2545
+ max=1.0
2546
+ /*
2547
+ Scanlines Shader
2548
+
2549
+ Copyright (C) 2017 Dominus Iniquitatis - zerosaiko@gmail.com
2550
+
2551
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2552
+ of this software and associated documentation files (the "Software"), to deal
2553
+ in the Software without restriction, including without limitation the rights
2554
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2555
+ copies of the Software, and to permit persons to whom the Software is
2556
+ furnished to do so, subject to the following conditions:
2557
+ The above copyright notice and this permission notice shall be included in
2558
+ all copies or substantial portions of the Software.
2559
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2560
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2561
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2562
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2563
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2564
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2565
+ THE SOFTWARE.
2566
+ */
2567
+
2568
+ uniform sampler2D tex;
2569
+ uniform vec2 texSize;
2570
+ varying vec2 texCoord;
2571
+
2572
+ uniform float lineBrightness;
2573
+
2574
+ void main() {
2575
+ vec4 color = texture2D(tex, texCoord);
2576
+
2577
+ // The pass is 2x high, so alternate output rows as the desktop shader does.
2578
+ float y = floor(texCoord.y * texSize.y * 2.0);
2579
+
2580
+ if (mod(y, 2.0) == 0.0) {
2581
+ color.rgb *= lineBrightness;
2582
+ }
2583
+
2584
+ gl_FragColor = color;
2585
+ }
2586
+ [shader]
2587
+ name=Soften
2588
+ author=Dominus Iniquitatis
2589
+ description=Soft image blurring.
2590
+ passes=1
2591
+
2592
+ [pass.0]
2593
+ fragmentShader=soften.fs
2594
+ blend=1
2595
+ width=-1
2596
+ height=-1
2597
+
2598
+ [pass.0.uniform.amount]
2599
+ type=float
2600
+ readableName=Amount
2601
+ default=0.5
2602
+ min=0.0
2603
+ max=1.0
2604
+ /*
2605
+ Soften Shader
2606
+
2607
+ Copyright (C) 2017 Dominus Iniquitatis - zerosaiko@gmail.com
2608
+
2609
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2610
+ of this software and associated documentation files (the "Software"), to deal
2611
+ in the Software without restriction, including without limitation the rights
2612
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2613
+ copies of the Software, and to permit persons to whom the Software is
2614
+ furnished to do so, subject to the following conditions:
2615
+ The above copyright notice and this permission notice shall be included in
2616
+ all copies or substantial portions of the Software.
2617
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2618
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2619
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2620
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2621
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2622
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2623
+ THE SOFTWARE.
2624
+ */
2625
+
2626
+ uniform sampler2D tex;
2627
+ uniform vec2 texSize;
2628
+ varying vec2 texCoord;
2629
+
2630
+ uniform float amount;
2631
+
2632
+ vec2 GetTexelSize()
2633
+ {
2634
+ return vec2(1.0 / texSize.x, 1.0 / texSize.y);
2635
+ }
2636
+
2637
+ void main()
2638
+ {
2639
+ vec4 color = texture2D(tex, texCoord);
2640
+
2641
+ vec4 northColor = texture2D(tex, texCoord + vec2(0.0, GetTexelSize().y));
2642
+ vec4 southColor = texture2D(tex, texCoord - vec2(0.0, GetTexelSize().y));
2643
+ vec4 eastColor = texture2D(tex, texCoord + vec2(GetTexelSize().x, 0.0));
2644
+ vec4 westColor = texture2D(tex, texCoord - vec2(GetTexelSize().x, 0.0));
2645
+
2646
+ if (abs(length(color) - length(northColor)) > 0.0)
2647
+ {
2648
+ color = mix(color, northColor, amount / 4.0);
2649
+ }
2650
+
2651
+ if (abs(length(color) - length(southColor)) > 0.0)
2652
+ {
2653
+ color = mix(color, southColor, amount / 4.0);
2654
+ }
2655
+
2656
+ if (abs(length(color) - length(eastColor)) > 0.0)
2657
+ {
2658
+ color = mix(color, eastColor, amount / 4.0);
2659
+ }
2660
+
2661
+ if (abs(length(color) - length(westColor)) > 0.0)
2662
+ {
2663
+ color = mix(color, westColor, amount / 4.0);
2664
+ }
2665
+
2666
+ gl_FragColor = color;
2667
+ }
2668
+ [shader]
2669
+ name=GBA SP 101 Color
2670
+ author=Pokefan531 and hunterk
2671
+ description=Shader that replicates the LCD Colorspace from a Gameboy SP 101 (backlit version).
2672
+ passes=1
2673
+
2674
+ [pass.0]
2675
+ fragmentShader=sp101-color.fs
2676
+ vertexShader=sp101-color.vs
2677
+ blend=1
2678
+ width=-1
2679
+ height=-1
2680
+
2681
+ [pass.0.uniform.color_mode]
2682
+ type=int
2683
+ default=1
2684
+ min=1
2685
+ max=3
2686
+ readableName=Color Profile (1=sRGB, 2=DCI, 3=Rec2020)
2687
+ // Shader that replicates the LCD Colorspace from a Gameboy SP 101 (backlit version) --
2688
+ varying vec2 texCoord;
2689
+ varying mat4 profile;
2690
+ uniform sampler2D tex;
2691
+ uniform vec2 texSize;
2692
+
2693
+ const float target_gamma = 2.2;
2694
+ const float display_gamma = 2.2;
2695
+
2696
+ void main() {
2697
+ // bring out our stored luminance value
2698
+ float lum = profile[3].w;
2699
+
2700
+ // our adjustments need to happen in linear gamma
2701
+ vec4 screen = pow(texture2D(tex, texCoord), vec4(target_gamma)).rgba;
2702
+
2703
+ screen = clamp(screen * lum, 0.0, 1.0);
2704
+ screen = profile * screen;
2705
+ gl_FragColor = pow(screen, vec4(1.0 / display_gamma));
2706
+ }
2707
+ uniform int color_mode;
2708
+ attribute vec4 position;
2709
+ varying vec2 texCoord;
2710
+ varying mat4 profile;
2711
+
2712
+ const mat4 SP1_sRGB = mat4(
2713
+ 0.96, 0.0325, 0.001, 0.0, //red channel
2714
+ 0.11, 0.89, -0.03, 0.0, //green channel
2715
+ -0.07, 0.0775, 1.029, 0.0, //blue channel
2716
+ 0.0, 0.0, 0.0, 0.935 //alpha channel
2717
+ );
2718
+
2719
+ const mat4 SP1_DCI = mat4(
2720
+ 0.805, 0.0675, 0.017, 0.0, //red channel
2721
+ 0.24, 0.86, 0.02, 0.0, //green channel
2722
+ -0.045, 0.0725, 0.963, 0.0, //blue channel
2723
+ 0.0, 0.0, 0.0, 0.955 //alpha channel
2724
+ );
2725
+
2726
+ const mat4 SP1_Rec2020 = mat4(
2727
+ 0.625, 0.10, 0.015, 0.0, //red channel
2728
+ 0.35, 0.82, 0.0325, 0.0, //green channel
2729
+ 0.025, 0.08, 0.9525, 0.0, //blue channel
2730
+ 0.0, 0.0, 0.0, 1.0 //alpha channel
2731
+ );
2732
+
2733
+ void main() {
2734
+ if (color_mode == 1) profile = SP1_sRGB;
2735
+ else if (color_mode == 2) profile = SP1_DCI;
2736
+ else if (color_mode == 3) profile = SP1_Rec2020;
2737
+
2738
+ gl_Position = position;
2739
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
2740
+ }
2741
+ [shader]
2742
+ name=TV Mode
2743
+ author=Dominus Iniquitatis
2744
+ description=Scanlines along with a subtle blurring.
2745
+ passes=1
2746
+
2747
+ [pass.0]
2748
+ fragmentShader=tv.fs
2749
+ blend=1
2750
+ width=-2
2751
+ height=-2
2752
+
2753
+ [pass.0.uniform.lineBrightness]
2754
+ type=float
2755
+ readableName=Line brightness
2756
+ default=0.75
2757
+ min=0.0
2758
+ max=1.0
2759
+
2760
+ [pass.0.uniform.blurring]
2761
+ type=float
2762
+ readableName=Blurring
2763
+ default=1.0
2764
+ min=0.0
2765
+ max=1.0
2766
+ /*
2767
+ TV Mode Shader
2768
+
2769
+ Copyright (C) 2022 Dominus Iniquitatis - zerosaiko@gmail.com
2770
+
2771
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2772
+ of this software and associated documentation files (the "Software"), to deal
2773
+ in the Software without restriction, including without limitation the rights
2774
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2775
+ copies of the Software, and to permit persons to whom the Software is
2776
+ furnished to do so, subject to the following conditions:
2777
+ The above copyright notice and this permission notice shall be included in
2778
+ all copies or substantial portions of the Software.
2779
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2780
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2781
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2782
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2783
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2784
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2785
+ THE SOFTWARE.
2786
+ */
2787
+
2788
+ uniform sampler2D tex;
2789
+ uniform vec2 texSize;
2790
+ varying vec2 texCoord;
2791
+
2792
+ uniform float lineBrightness;
2793
+ uniform float blurring;
2794
+
2795
+ void main()
2796
+ {
2797
+ vec4 c = texture2D(tex, texCoord);
2798
+ vec4 n = texture2D(tex, texCoord + vec2(1.0 / texSize.x * 0.5, 0.0));
2799
+
2800
+ vec4 color = mix(c, (c + n) / 2.0, blurring);
2801
+ color.a = c.a;
2802
+
2803
+ if (int(mod(texCoord.t * texSize.y * 2.0, 2.0)) == 0)
2804
+ {
2805
+ color.rgb *= lineBrightness;
2806
+ }
2807
+
2808
+ gl_FragColor = color;
2809
+ }
2810
+ [shader]
2811
+ name=VBA Pixelate
2812
+ author=Dominus Iniquitatis
2813
+ description=VisualBoyAdvance-style pixelation.
2814
+ passes=1
2815
+
2816
+ [pass.0]
2817
+ fragmentShader=vba_pixelate.fs
2818
+ blend=1
2819
+ width=-2
2820
+ height=-2
2821
+
2822
+ [pass.0.uniform.boundBrightness]
2823
+ type=float
2824
+ readableName=Bound brightness
2825
+ default=0.5
2826
+ min=0.0
2827
+ max=1.0
2828
+ /*
2829
+ VBA Pixelate Shader
2830
+
2831
+ Copyright (C) 2017 Dominus Iniquitatis - zerosaiko@gmail.com
2832
+
2833
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2834
+ of this software and associated documentation files (the "Software"), to deal
2835
+ in the Software without restriction, including without limitation the rights
2836
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2837
+ copies of the Software, and to permit persons to whom the Software is
2838
+ furnished to do so, subject to the following conditions:
2839
+ The above copyright notice and this permission notice shall be included in
2840
+ all copies or substantial portions of the Software.
2841
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2842
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2843
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2844
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2845
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2846
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2847
+ THE SOFTWARE.
2848
+ */
2849
+
2850
+ uniform sampler2D tex;
2851
+ uniform vec2 texSize;
2852
+ varying vec2 texCoord;
2853
+
2854
+ uniform float boundBrightness;
2855
+
2856
+ void main()
2857
+ {
2858
+ vec4 color = texture2D(tex, texCoord);
2859
+
2860
+ // The pass is 2x in each dimension, so alternate output pixels.
2861
+ float x = floor(texCoord.s * texSize.x * 2.0);
2862
+ float y = floor(texCoord.t * texSize.y * 2.0);
2863
+
2864
+ bool onVerticalLine = mod(x, 2.0) == 0.0;
2865
+ bool onHorizontalLine = mod(y, 2.0) == 0.0;
2866
+
2867
+ if (onVerticalLine || onHorizontalLine)
2868
+ {
2869
+ color.rgb *= boundBrightness;
2870
+ }
2871
+
2872
+ gl_FragColor = color;
2873
+ }
2874
+ [shader]
2875
+ name=Vignette
2876
+ author=Dominus Iniquitatis
2877
+ description=Configurable vignette effect.
2878
+ passes=1
2879
+
2880
+ [pass.0]
2881
+ fragmentShader=vignette.fs
2882
+ blend=1
2883
+ width=-1
2884
+ height=-1
2885
+
2886
+ [pass.0.uniform.intensity]
2887
+ type=float
2888
+ readableName=Intensity
2889
+ default=1.0
2890
+ min=0.0
2891
+ max=1.0
2892
+ /*
2893
+ Vignette Shader
2894
+
2895
+ Copyright (C) 2017 Dominus Iniquitatis - zerosaiko@gmail.com
2896
+
2897
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2898
+ of this software and associated documentation files (the "Software"), to deal
2899
+ in the Software without restriction, including without limitation the rights
2900
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2901
+ copies of the Software, and to permit persons to whom the Software is
2902
+ furnished to do so, subject to the following conditions:
2903
+ The above copyright notice and this permission notice shall be included in
2904
+ all copies or substantial portions of the Software.
2905
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2906
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2907
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2908
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2909
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2910
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2911
+ THE SOFTWARE.
2912
+ */
2913
+
2914
+ uniform sampler2D tex;
2915
+ uniform vec2 texSize;
2916
+ varying vec2 texCoord;
2917
+
2918
+ uniform float intensity;
2919
+
2920
+ void main()
2921
+ {
2922
+ vec4 color = texture2D(tex, texCoord);
2923
+ color = mix(color, vec4(0.0, 0.0, 0.0, 1.0), length(texCoord - 0.5) * intensity);
2924
+
2925
+ gl_FragColor = color;
2926
+ }
2927
+ [shader]
2928
+ name=Wii U
2929
+ author=Prof. 9
2930
+ description=Uses the color palette from the Wii U Virtual Console. Enable bilinear filtering to further mimic Wii U output.
2931
+ passes=1
2932
+
2933
+ [pass.0]
2934
+ fragmentShader=wiiu.fs
2935
+ blend=1
2936
+ width=-4
2937
+ height=-4
2938
+ varying vec2 texCoord;
2939
+ uniform sampler2D tex;
2940
+ uniform vec2 texSize;
2941
+
2942
+ float wiiuLut31(float x) {
2943
+ int i = int(floor(x * 31.0 + 0.5));
2944
+
2945
+ if (i < 0) i = 0;
2946
+ if (i > 31) i = 31;
2947
+
2948
+ if (i == 0) return 0.0 / 255.0;
2949
+ if (i == 1) return 6.0 / 255.0;
2950
+ if (i == 2) return 12.0 / 255.0;
2951
+ if (i == 3) return 18.0 / 255.0;
2952
+ if (i == 4) return 24.0 / 255.0;
2953
+ if (i == 5) return 31.0 / 255.0;
2954
+ if (i == 6) return 37.0 / 255.0;
2955
+ if (i == 7) return 43.0 / 255.0;
2956
+ if (i == 8) return 49.0 / 255.0;
2957
+ if (i == 9) return 55.0 / 255.0;
2958
+ if (i == 10) return 61.0 / 255.0;
2959
+ if (i == 11) return 67.0 / 255.0;
2960
+ if (i == 12) return 73.0 / 255.0;
2961
+ if (i == 13) return 79.0 / 255.0;
2962
+ if (i == 14) return 86.0 / 255.0;
2963
+ if (i == 15) return 92.0 / 255.0;
2964
+ if (i == 16) return 98.0 / 255.0;
2965
+ if (i == 17) return 104.0 / 255.0;
2966
+ if (i == 18) return 111.0 / 255.0;
2967
+ if (i == 19) return 117.0 / 255.0;
2968
+ if (i == 20) return 123.0 / 255.0;
2969
+ if (i == 21) return 129.0 / 255.0;
2970
+ if (i == 22) return 135.0 / 255.0;
2971
+ if (i == 23) return 141.0 / 255.0;
2972
+ if (i == 24) return 148.0 / 255.0;
2973
+ if (i == 25) return 154.0 / 255.0;
2974
+ if (i == 26) return 159.0 / 255.0;
2975
+ if (i == 27) return 166.0 / 255.0;
2976
+ if (i == 28) return 172.0 / 255.0;
2977
+ if (i == 29) return 178.0 / 255.0;
2978
+ if (i == 30) return 184.0 / 255.0;
2979
+ // i == 31
2980
+ return 191.0 / 255.0;
2981
+ }
2982
+
2983
+ void main() {
2984
+ vec4 color = texture2D(tex, texCoord);
2985
+
2986
+ color.r = wiiuLut31(color.r);
2987
+ color.g = wiiuLut31(color.g);
2988
+ color.b = wiiuLut31(color.b);
2989
+
2990
+ gl_FragColor = color;
2991
+ }
2992
+ [shader]
2993
+ name=xBR-lv2
2994
+ author=Hyllian
2995
+ description=xBR-lv2 upsampling filter
2996
+ passes=1
2997
+
2998
+ [pass.0]
2999
+ integerScaling=1
3000
+ vertexShader=xbr.vs
3001
+ fragmentShader=xbr.fs
3002
+
3003
+ [pass.0.uniform.XBR_Y_WEIGHT]
3004
+ type=float
3005
+ default=48
3006
+ readableName=Y Weight
3007
+ min=0
3008
+ max=100
3009
+
3010
+ [pass.0.uniform.XBR_EQ_THRESHOLD]
3011
+ type=float
3012
+ readableName=Eq Threshold
3013
+ default=25.0
3014
+ min=0.0
3015
+ max=50.0
3016
+
3017
+ [pass.0.uniform.XBR_SCALE]
3018
+ type=float
3019
+ readableName=xBR Scale
3020
+ default=4.0
3021
+ min=1.0
3022
+ max=5.0
3023
+
3024
+ [pass.0.uniform.XBR_LV2_COEFFICIENT]
3025
+ type=float
3026
+ readableName=Lv2 Coefficient
3027
+ default=2.0
3028
+ min=1.0
3029
+ max=3.0
3030
+ /*
3031
+ Hyllian's xBR-lv2 Shader
3032
+
3033
+ Copyright (C) 2011-2015 Hyllian - sergiogdb@gmail.com
3034
+
3035
+ Permission is hereby granted, free of charge, to any person obtaining a copy
3036
+ of this software and associated documentation files (the "Software"), to deal
3037
+ in the Software without restriction, including without limitation the rights
3038
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3039
+ copies of the Software, and to permit persons to whom the Software is
3040
+ furnished to do so, subject to the following conditions:
3041
+
3042
+ The above copyright notice and this permission notice shall be included in
3043
+ all copies or substantial portions of the Software.
3044
+
3045
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3046
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3047
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3048
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3049
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3050
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3051
+ THE SOFTWARE.
3052
+
3053
+
3054
+ Incorporates some of the ideas from SABR shader. Thanks to Joshua Street.
3055
+ */
3056
+
3057
+ uniform float XBR_Y_WEIGHT;
3058
+ uniform float XBR_EQ_THRESHOLD;
3059
+ uniform float XBR_SCALE;
3060
+ uniform float XBR_LV2_COEFFICIENT;
3061
+
3062
+ uniform sampler2D tex;
3063
+ uniform vec2 texSize;
3064
+
3065
+ varying vec2 texCoord;
3066
+ varying vec4 TEX1;
3067
+ varying vec4 TEX2;
3068
+ varying vec4 TEX3;
3069
+ varying vec4 TEX4;
3070
+ varying vec4 TEX5;
3071
+ varying vec4 TEX6;
3072
+ varying vec4 TEX7;
3073
+
3074
+ const vec4 Ao = vec4( 1.0, -1.0, -1.0, 1.0 );
3075
+ const vec4 Bo = vec4( 1.0, 1.0, -1.0, -1.0 );
3076
+ const vec4 Co = vec4( 1.5, 0.5, -0.5, 0.5 );
3077
+ const vec4 Ax = vec4( 1.0, -1.0, -1.0, 1.0 );
3078
+ const vec4 Bx = vec4( 0.5, 2.0, -0.5, -2.0 );
3079
+ const vec4 Cx = vec4( 1.0, 1.0, -0.5, 0.0 );
3080
+ const vec4 Ay = vec4( 1.0, -1.0, -1.0, 1.0 );
3081
+ const vec4 By = vec4( 2.0, 0.5, -2.0, -0.5 );
3082
+ const vec4 Cy = vec4( 2.0, 0.0, -1.0, 0.5 );
3083
+ const vec4 Ci = vec4( 0.25, 0.25, 0.25, 0.25 );
3084
+
3085
+ const vec3 Y = vec3(0.2126, 0.7152, 0.0722);
3086
+
3087
+ vec4 df4(vec4 A, vec4 B) {
3088
+ return abs(A - B);
3089
+ }
3090
+
3091
+ float c_df(vec3 c1, vec3 c2) {
3092
+ vec3 d = abs(c1 - c2);
3093
+ return d.r + d.g + d.b;
3094
+ }
3095
+
3096
+ bvec4 eq4(vec4 A, vec4 B) {
3097
+ return lessThan(df4(A, B), vec4(XBR_EQ_THRESHOLD));
3098
+ }
3099
+
3100
+ bvec4 and4(bvec4 A, bvec4 B) {
3101
+ return bvec4(A.x && B.x, A.y && B.y, A.z && B.z, A.w && B.w);
3102
+ }
3103
+
3104
+ bvec4 nand4(bvec4 A, bvec4 B) {
3105
+ return bvec4(!(A.x && B.x), !(A.y && B.y), !(A.z && B.z), !(A.w && B.w));
3106
+ }
3107
+
3108
+ vec4 weighted_distance(vec4 a, vec4 b, vec4 c, vec4 d, vec4 e, vec4 f, vec4 g, vec4 h) {
3109
+ return (df4(a,b) + df4(a,c) + df4(d,e) + df4(d,f) + 4.0 * df4(g,h));
3110
+ }
3111
+
3112
+ float lum(vec3 rgb) {
3113
+ return dot(rgb, Y) * XBR_Y_WEIGHT;
3114
+ }
3115
+
3116
+ void main() {
3117
+ // fractional position inside the source pixel (in source-pixel space)
3118
+ vec2 fp = fract(texCoord * texSize);
3119
+
3120
+ // Sample neighborhood
3121
+ vec3 A1 = texture2D(tex, TEX1.xw).rgb;
3122
+ vec3 B1 = texture2D(tex, TEX1.yw).rgb;
3123
+ vec3 C1 = texture2D(tex, TEX1.zw).rgb;
3124
+
3125
+ vec3 A = texture2D(tex, TEX2.xw).rgb;
3126
+ vec3 B = texture2D(tex, TEX2.yw).rgb;
3127
+ vec3 C = texture2D(tex, TEX2.zw).rgb;
3128
+
3129
+ vec3 D = texture2D(tex, TEX3.xw).rgb;
3130
+ vec3 E = texture2D(tex, TEX3.yw).rgb;
3131
+ vec3 F = texture2D(tex, TEX3.zw).rgb;
3132
+
3133
+ vec3 G = texture2D(tex, TEX4.xw).rgb;
3134
+ vec3 H = texture2D(tex, TEX4.yw).rgb;
3135
+ vec3 I = texture2D(tex, TEX4.zw).rgb;
3136
+
3137
+ vec3 G5 = texture2D(tex, TEX5.xw).rgb;
3138
+ vec3 H5 = texture2D(tex, TEX5.yw).rgb;
3139
+ vec3 I5 = texture2D(tex, TEX5.zw).rgb;
3140
+
3141
+ vec3 A0 = texture2D(tex, TEX6.xy).rgb;
3142
+ vec3 D0 = texture2D(tex, TEX6.xz).rgb;
3143
+ vec3 G0 = texture2D(tex, TEX6.xw).rgb;
3144
+
3145
+ vec3 C4 = texture2D(tex, TEX7.xy).rgb;
3146
+ vec3 F4 = texture2D(tex, TEX7.xz).rgb;
3147
+ vec3 I4 = texture2D(tex, TEX7.xw).rgb;
3148
+
3149
+ // Replace mat4x3/transpose with explicit luma packing (GLSL ES 1.00 safe)
3150
+ vec4 b = vec4(lum(B), lum(D), lum(H), lum(F));
3151
+ vec4 c = vec4(lum(C), lum(A), lum(G), lum(I));
3152
+ vec4 e = vec4(lum(E), lum(E), lum(E), lum(E));
3153
+ vec4 d = b.yzwx;
3154
+ vec4 f = b.wxyz;
3155
+ vec4 g = c.zwxy;
3156
+ vec4 h = b.zwxy;
3157
+ vec4 i = c.wxyz;
3158
+
3159
+ vec4 i4v = vec4(lum(I4), lum(C1), lum(A0), lum(G5));
3160
+ vec4 i5v = vec4(lum(I5), lum(C4), lum(A1), lum(G0));
3161
+ vec4 h5v = vec4(lum(H5), lum(F4), lum(B1), lum(D0));
3162
+ vec4 f4v = h5v.yzwx;
3163
+
3164
+ // Edge detection math
3165
+ vec4 fx = (Ao * fp.y + Bo * fp.x);
3166
+ vec4 fx_left = (Ax * fp.y + Bx * fp.x);
3167
+ vec4 fx_up = (Ay * fp.y + By * fp.x);
3168
+
3169
+ bvec4 interp_restriction_lv0 = and4(notEqual(e, f), notEqual(e, h));
3170
+ bvec4 interp_restriction_lv1 = interp_restriction_lv0;
3171
+
3172
+ bvec4 interp_restriction_lv2_left = and4(notEqual(e, g), notEqual(d, g));
3173
+ bvec4 interp_restriction_lv2_up = and4(notEqual(e, c), notEqual(b, c));
3174
+
3175
+ vec4 delta = vec4(1.0 / XBR_SCALE);
3176
+ vec4 deltaL = vec4(0.5 / XBR_SCALE, 1.0 / XBR_SCALE, 0.5 / XBR_SCALE, 1.0 / XBR_SCALE);
3177
+ vec4 deltaU = deltaL.yxwz;
3178
+
3179
+ vec4 fx45i = clamp((fx + delta - Co - Ci) / (2.0 * delta ), 0.0, 1.0);
3180
+ vec4 fx45 = clamp((fx + delta - Co ) / (2.0 * delta ), 0.0, 1.0);
3181
+ vec4 fx30 = clamp((fx_left + deltaL - Co ) / (2.0 * deltaL), 0.0, 1.0);
3182
+ vec4 fx60 = clamp((fx_up + deltaU - Co ) / (2.0 * deltaU), 0.0, 1.0);
3183
+
3184
+ vec4 wd1 = weighted_distance(e, c, g, i, h5v, f4v, h, f);
3185
+ vec4 wd2 = weighted_distance(h, d, i5v, f, i4v, b, e, i);
3186
+
3187
+ bvec4 edri = and4(lessThanEqual(wd1, wd2), interp_restriction_lv0);
3188
+ bvec4 edr = and4(lessThan(wd1, wd2), interp_restriction_lv1);
3189
+
3190
+ bvec4 edr_left = and4(
3191
+ lessThanEqual((XBR_LV2_COEFFICIENT * df4(f, g)), df4(h, c)),
3192
+ interp_restriction_lv2_left
3193
+ );
3194
+ bvec4 edr_up = and4(
3195
+ greaterThanEqual(df4(f, g), (XBR_LV2_COEFFICIENT * df4(h, c))),
3196
+ interp_restriction_lv2_up
3197
+ );
3198
+
3199
+ edr = and4(edr, nand4(edri.yzwx, edri.wxyz));
3200
+ edr_left = and4(and4(edr_left, edr), eq4(e, c));
3201
+ edr_up = and4(and4(edr_up, edr), eq4(e, g));
3202
+
3203
+ fx45 *= vec4(edr);
3204
+ fx30 *= vec4(edr_left);
3205
+ fx60 *= vec4(edr_up);
3206
+ fx45i *= vec4(edri);
3207
+
3208
+ vec4 px = vec4(lessThanEqual(df4(e, f), df4(e, h)));
3209
+
3210
+ vec4 maximos = max(max(fx30, fx60), max(fx45, fx45i));
3211
+
3212
+ vec3 res1 = E;
3213
+ res1 = mix(res1, mix(H, F, px.x), maximos.x);
3214
+ res1 = mix(res1, mix(B, D, px.z), maximos.z);
3215
+
3216
+ vec3 res2 = E;
3217
+ res2 = mix(res1, mix(F, B, px.y), maximos.y);
3218
+ res2 = mix(res1, mix(D, H, px.w), maximos.w);
3219
+
3220
+ vec3 res = mix(res1, res2, step(c_df(E, res1), c_df(E, res2)));
3221
+
3222
+ gl_FragColor = vec4(res, 1.0);
3223
+ }/*
3224
+ Hyllian's xBR-lv3 Shader
3225
+
3226
+ Copyright (C) 2011-2015 Hyllian - sergiogdb@gmail.com
3227
+
3228
+ Permission is hereby granted, free of charge, to any person obtaining a copy
3229
+ of this software and associated documentation files (the "Software"), to deal
3230
+ in the Software without restriction, including without limitation the rights
3231
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3232
+ copies of the Software, and to permit persons to whom the Software is
3233
+ furnished to do so, subject to the following conditions:
3234
+
3235
+ The above copyright notice and this permission notice shall be included in
3236
+ all copies or substantial portions of the Software.
3237
+
3238
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3239
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3240
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3241
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3242
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3243
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3244
+ THE SOFTWARE.
3245
+
3246
+ Incorporates some of the ideas from SABR shader. Thanks to Joshua Street.
3247
+ */
3248
+
3249
+ attribute vec4 position;
3250
+
3251
+ uniform vec2 texSize;
3252
+
3253
+ varying vec2 texCoord;
3254
+ varying vec4 TEX1;
3255
+ varying vec4 TEX2;
3256
+ varying vec4 TEX3;
3257
+ varying vec4 TEX4;
3258
+ varying vec4 TEX5;
3259
+ varying vec4 TEX6;
3260
+ varying vec4 TEX7;
3261
+
3262
+ void main() {
3263
+ gl_Position = position;
3264
+
3265
+ vec2 ps = vec2(1.0) / texSize;
3266
+ float dx = ps.x;
3267
+ float dy = ps.y;
3268
+
3269
+ // A1 B1 C1
3270
+ // A0 A B C C4
3271
+ // D0 D E F F4
3272
+ // G0 G H I I4
3273
+ // G5 H5 I5
3274
+
3275
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
3276
+
3277
+ // IMPORTANT: use 0.0 (float literal) for strict GLSL ES 1.00 compilers
3278
+ TEX1 = texCoord.xxxy + vec4(-dx, 0.0, dx, -2.0 * dy); // A1 B1 C1
3279
+ TEX2 = texCoord.xxxy + vec4(-dx, 0.0, dx, -1.0 * dy); // A B C
3280
+ TEX3 = texCoord.xxxy + vec4(-dx, 0.0, dx, 0.0 ); // D E F
3281
+ TEX4 = texCoord.xxxy + vec4(-dx, 0.0, dx, 1.0 * dy); // G H I
3282
+ TEX5 = texCoord.xxxy + vec4(-dx, 0.0, dx, 2.0 * dy); // G5 H5 I5
3283
+ TEX6 = texCoord.xyyy + vec4(-2.0 * dx, -dy, 0.0, dy); // A0 D0 G0
3284
+ TEX7 = texCoord.xyyy + vec4( 2.0 * dx, -dy, 0.0, dy); // C4 F4 I4
3285
+ }[shader]
3286
+ name=xBR-lv3
3287
+ author=Hyllian
3288
+ description=xBR-lv3 upsampling filter
3289
+ passes=1
3290
+
3291
+ [pass.0]
3292
+ integerScaling=1
3293
+ vertexShader=xbr.vs
3294
+ fragmentShader=xbr.fs
3295
+
3296
+ [pass.0.uniform.XBR_Y_WEIGHT]
3297
+ type=float
3298
+ default=48
3299
+ readableName=Y Weight
3300
+ min=0
3301
+ max=100
3302
+
3303
+ [pass.0.uniform.XBR_EQ_THRESHOLD]
3304
+ type=float
3305
+ readableName=Eq Threshold
3306
+ default=10.0
3307
+ min=0.0
3308
+ max=50.0
3309
+
3310
+ [pass.0.uniform.XBR_EQ_THRESHOLD2]
3311
+ type=float
3312
+ readableName=Eq Threshold2
3313
+ default=2.0
3314
+ min=0.0
3315
+ max=4.0
3316
+
3317
+ [pass.0.uniform.XBR_LV2_COEFFICIENT]
3318
+ type=float
3319
+ readableName=Lv2 Coefficient
3320
+ default=2.0
3321
+ min=1.0
3322
+ max=3.0
3323
+ /*
3324
+ Hyllian's xBR-lv3 Shader
3325
+
3326
+ Copyright (C) 2011-2015 Hyllian - sergiogdb@gmail.com
3327
+
3328
+ Permission is hereby granted, free of charge, to any person obtaining a copy
3329
+ of this software and associated documentation files (the "Software"), to deal
3330
+ in the Software without restriction, including without limitation the rights
3331
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3332
+ copies of the Software, and to permit persons to whom the Software is
3333
+ furnished to do so, subject to the following conditions:
3334
+
3335
+ The above copyright notice and this permission notice shall be included in
3336
+ all copies or substantial portions of the Software.
3337
+
3338
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3339
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3340
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3341
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3342
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3343
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3344
+ THE SOFTWARE.
3345
+
3346
+
3347
+ Incorporates some of the ideas from SABR shader. Thanks to Joshua Street.
3348
+ */
3349
+
3350
+ uniform float XBR_Y_WEIGHT;
3351
+ uniform float XBR_EQ_THRESHOLD;
3352
+ uniform float XBR_EQ_THRESHOLD2;
3353
+ uniform float XBR_LV2_COEFFICIENT;
3354
+
3355
+ uniform sampler2D tex;
3356
+ uniform vec2 texSize;
3357
+
3358
+ varying vec2 texCoord;
3359
+ varying vec4 TEX1;
3360
+ varying vec4 TEX2;
3361
+ varying vec4 TEX3;
3362
+ varying vec4 TEX4;
3363
+ varying vec4 TEX5;
3364
+ varying vec4 TEX6;
3365
+ varying vec4 TEX7;
3366
+
3367
+ const mat3 yuv = mat3(
3368
+ 0.299, 0.587, 0.114,
3369
+ -0.169, -0.331, 0.499,
3370
+ 0.499, -0.418, -0.0813
3371
+ );
3372
+
3373
+ // keep same delta
3374
+ const vec4 delta = vec4(0.4, 0.4, 0.4, 0.4);
3375
+
3376
+ vec4 df4(vec4 A, vec4 B) {
3377
+ return abs(A - B);
3378
+ }
3379
+
3380
+ float c_df(vec3 c1, vec3 c2) {
3381
+ vec3 d = abs(c1 - c2);
3382
+ return d.r + d.g + d.b;
3383
+ }
3384
+
3385
+ bvec4 eq4(vec4 A, vec4 B) {
3386
+ return lessThan(df4(A, B), vec4(XBR_EQ_THRESHOLD));
3387
+ }
3388
+
3389
+ bvec4 eq24(vec4 A, vec4 B) {
3390
+ return lessThan(df4(A, B), vec4(XBR_EQ_THRESHOLD2));
3391
+ }
3392
+
3393
+ bvec4 and4(bvec4 A, bvec4 B) {
3394
+ return bvec4(A.x && B.x, A.y && B.y, A.z && B.z, A.w && B.w);
3395
+ }
3396
+
3397
+ bvec4 or4(bvec4 A, bvec4 B) {
3398
+ return bvec4(A.x || B.x, A.y || B.y, A.z || B.z, A.w || B.w);
3399
+ }
3400
+
3401
+ vec4 weighted_distance(vec4 a, vec4 b, vec4 c, vec4 d, vec4 e, vec4 f, vec4 g, vec4 h) {
3402
+ return (df4(a,b) + df4(a,c) + df4(d,e) + df4(d,f) + 4.0 * df4(g,h));
3403
+ }
3404
+
3405
+ void main() {
3406
+ bvec4 edr, edr_left, edr_up, edr3_left, edr3_up, px;
3407
+ bvec4 interp_restriction_lv1, interp_restriction_lv2_left, interp_restriction_lv2_up;
3408
+ bvec4 interp_restriction_lv3_left, interp_restriction_lv3_up;
3409
+ bvec4 nc, nc30, nc60, nc45, nc15, nc75;
3410
+ vec4 fx, fx_left, fx_up, fx3_left, fx3_up;
3411
+ vec3 res1, res2, pix1, pix2;
3412
+ float blend1, blend2;
3413
+
3414
+ // IMPORTANT: initialize to avoid undefined reads on some compilers
3415
+ pix1 = vec3(0.0);
3416
+ pix2 = vec3(0.0);
3417
+ blend1 = 0.0;
3418
+ blend2 = 0.0;
3419
+
3420
+ vec2 fp = fract(texCoord * texSize);
3421
+
3422
+ vec3 A1 = texture2D(tex, TEX1.xw).rgb;
3423
+ vec3 B1 = texture2D(tex, TEX1.yw).rgb;
3424
+ vec3 C1 = texture2D(tex, TEX1.zw).rgb;
3425
+
3426
+ vec3 A = texture2D(tex, TEX2.xw).rgb;
3427
+ vec3 B = texture2D(tex, TEX2.yw).rgb;
3428
+ vec3 C = texture2D(tex, TEX2.zw).rgb;
3429
+
3430
+ vec3 D = texture2D(tex, TEX3.xw).rgb;
3431
+ vec3 E = texture2D(tex, TEX3.yw).rgb;
3432
+ vec3 F = texture2D(tex, TEX3.zw).rgb;
3433
+
3434
+ vec3 G = texture2D(tex, TEX4.xw).rgb;
3435
+ vec3 H = texture2D(tex, TEX4.yw).rgb;
3436
+ vec3 I = texture2D(tex, TEX4.zw).rgb;
3437
+
3438
+ vec3 G5 = texture2D(tex, TEX5.xw).rgb;
3439
+ vec3 H5 = texture2D(tex, TEX5.yw).rgb;
3440
+ vec3 I5 = texture2D(tex, TEX5.zw).rgb;
3441
+
3442
+ vec3 A0 = texture2D(tex, TEX6.xy).rgb;
3443
+ vec3 D0 = texture2D(tex, TEX6.xz).rgb;
3444
+ vec3 G0 = texture2D(tex, TEX6.xw).rgb;
3445
+
3446
+ vec3 C4 = texture2D(tex, TEX7.xy).rgb;
3447
+ vec3 F4 = texture2D(tex, TEX7.xz).rgb;
3448
+ vec3 I4 = texture2D(tex, TEX7.xw).rgb;
3449
+
3450
+ // Replace mat4x3 + transpose with explicit dot products (GLSL ES 1.00 safe)
3451
+ // Original: transpose(mat4x3(...)) * (XBR_Y_WEIGHT * yuv[0])
3452
+ vec3 Yw = (XBR_Y_WEIGHT * yuv[0]);
3453
+
3454
+ vec4 b = vec4(dot(B, Yw), dot(D, Yw), dot(H, Yw), dot(F, Yw));
3455
+ vec4 c = vec4(dot(C, Yw), dot(A, Yw), dot(G, Yw), dot(I, Yw));
3456
+ vec4 e = vec4(dot(E, Yw), dot(E, Yw), dot(E, Yw), dot(E, Yw));
3457
+ vec4 d = b.yzwx;
3458
+ vec4 f = b.wxyz;
3459
+ vec4 g = c.zwxy;
3460
+ vec4 h = b.zwxy;
3461
+ vec4 i = c.wxyz;
3462
+
3463
+ vec4 i4v = vec4(dot(I4, Yw), dot(C1, Yw), dot(A0, Yw), dot(G5, Yw));
3464
+ vec4 i5v = vec4(dot(I5, Yw), dot(C4, Yw), dot(A1, Yw), dot(G0, Yw));
3465
+ vec4 h5v = vec4(dot(H5, Yw), dot(F4, Yw), dot(B1, Yw), dot(D0, Yw));
3466
+ vec4 f4v = h5v.yzwx;
3467
+
3468
+ vec4 c1 = i4v.yzwx;
3469
+ vec4 g0 = i5v.wxyz;
3470
+ vec4 b1 = h5v.zwxy;
3471
+ vec4 d0 = h5v.wxyz;
3472
+
3473
+ // same constants as original
3474
+ vec4 Ao = vec4( 1.0, -1.0, -1.0, 1.0 );
3475
+ vec4 Bo = vec4( 1.0, 1.0, -1.0, -1.0 );
3476
+ vec4 Co = vec4( 1.5, 0.5, -0.5, 0.5 );
3477
+ vec4 Ax = vec4( 1.0, -1.0, -1.0, 1.0 );
3478
+ vec4 Bx = vec4( 0.5, 2.0, -0.5, -2.0 );
3479
+ vec4 Cx = vec4( 1.0, 1.0, -0.5, 0.0 );
3480
+ vec4 Ay = vec4( 1.0, -1.0, -1.0, 1.0 );
3481
+ vec4 By = vec4( 2.0, 0.5, -2.0, -0.5 );
3482
+ vec4 Cy = vec4( 2.0, 0.0, -1.0, 0.5 );
3483
+
3484
+ vec4 Az = vec4( 6.0, -2.0, -6.0, 2.0 );
3485
+ vec4 Bz = vec4( 2.0, 6.0, -2.0, -6.0 );
3486
+ vec4 Cz = vec4( 5.0, 3.0, -3.0, -1.0 );
3487
+ vec4 Aw = vec4( 2.0, -6.0, -2.0, 6.0 );
3488
+ vec4 Bw = vec4( 6.0, 2.0, -6.0, -2.0 );
3489
+ vec4 Cw = vec4( 5.0, -1.0, -3.0, 3.0 );
3490
+
3491
+ fx = (Ao * fp.y + Bo * fp.x);
3492
+ fx_left = (Ax * fp.y + Bx * fp.x);
3493
+ fx_up = (Ay * fp.y + By * fp.x);
3494
+ fx3_left = (Az * fp.y + Bz * fp.x);
3495
+ fx3_up = (Aw * fp.y + Bw * fp.x);
3496
+
3497
+ // Keep CORNER_* behavior EXACTLY. Default path is CORNER_C branch (the else).
3498
+ #ifdef CORNER_A
3499
+ interp_restriction_lv1 = and4(notEqual(e, f), notEqual(e, h));
3500
+ #elif defined(CORNER_B)
3501
+ interp_restriction_lv1 = ((e!=f) && (e!=h) && ( !eq4(f,b) && !eq4(h,d) || eq4(e,i) && !eq4(f,i4v) && !eq4(h,i5v) || eq4(e,g) || eq4(e,c) ) );
3502
+ #elif defined(CORNER_D)
3503
+ interp_restriction_lv1 = ((e!=f) && (e!=h) && ( !eq4(f,b) && !eq4(h,d) || eq4(e,i) && !eq4(f,i4v) && !eq4(h,i5v) || eq4(e,g) || eq4(e,c) ) && (f!=f4v && f!=i || h!=h5v && h!=i || h!=g || f!=c || eq4(b,c1) && eq4(d,g0)));
3504
+ #else
3505
+ interp_restriction_lv1 = and4(
3506
+ and4(notEqual(e, f), notEqual(e, h)),
3507
+ or4(
3508
+ or4(
3509
+ and4(not(eq4(f,b)), not(eq4(f,c))),
3510
+ and4(not(eq4(h,d)), not(eq4(h,g)))
3511
+ ),
3512
+ or4(
3513
+ and4(
3514
+ eq4(e,i),
3515
+ or4(
3516
+ and4(not(eq4(f,f4v)), not(eq4(f,i4v))),
3517
+ and4(not(eq4(h,h5v)), not(eq4(h,i5v)))
3518
+ )
3519
+ ),
3520
+ or4(eq4(e,g), eq4(e,c))
3521
+ )
3522
+ )
3523
+ );
3524
+ #endif
3525
+
3526
+ interp_restriction_lv2_left = and4(notEqual(e, g), notEqual(d, g));
3527
+ interp_restriction_lv2_up = and4(notEqual(e, c), notEqual(b, c));
3528
+ interp_restriction_lv3_left = and4(eq24(g, g0), not(eq24(d0, g0)));
3529
+ interp_restriction_lv3_up = and4(eq24(c, c1), not(eq24(b1, c1)));
3530
+
3531
+ vec4 fx45 = smoothstep(Co - delta, Co + delta, fx);
3532
+ vec4 fx30 = smoothstep(Cx - delta, Cx + delta, fx_left);
3533
+ vec4 fx60 = smoothstep(Cy - delta, Cy + delta, fx_up);
3534
+ vec4 fx15 = smoothstep(Cz - delta, Cz + delta, fx3_left);
3535
+ vec4 fx75 = smoothstep(Cw - delta, Cw + delta, fx3_up);
3536
+
3537
+ edr = and4(
3538
+ lessThan(
3539
+ weighted_distance(e, c, g, i, h5v, f4v, h, f),
3540
+ weighted_distance(h, d, i5v, f, i4v, b, e, i)
3541
+ ),
3542
+ interp_restriction_lv1
3543
+ );
3544
+
3545
+ edr_left = and4(lessThanEqual((XBR_LV2_COEFFICIENT * df4(f,g)), df4(h,c)), interp_restriction_lv2_left);
3546
+ edr_up = and4(greaterThanEqual(df4(f,g), (XBR_LV2_COEFFICIENT * df4(h,c))), interp_restriction_lv2_up);
3547
+ edr3_left = interp_restriction_lv3_left;
3548
+ edr3_up = interp_restriction_lv3_up;
3549
+
3550
+ nc45 = and4(edr, bvec4(fx45));
3551
+ nc30 = and4(edr, and4(edr_left, bvec4(fx30)));
3552
+ nc60 = and4(edr, and4(edr_up, bvec4(fx60)));
3553
+ nc15 = and4(and4(edr, edr_left), and4(edr3_left, bvec4(fx15)));
3554
+ nc75 = and4(and4(edr, edr_up), and4(edr3_up, bvec4(fx75)));
3555
+
3556
+ px = lessThanEqual(df4(e, f), df4(e, h));
3557
+
3558
+ nc = bvec4(
3559
+ (nc75.x || nc15.x || nc30.x || nc60.x || nc45.x),
3560
+ (nc75.y || nc15.y || nc30.y || nc60.y || nc45.y),
3561
+ (nc75.z || nc15.z || nc30.z || nc60.z || nc45.z),
3562
+ (nc75.w || nc15.w || nc30.w || nc60.w || nc45.w)
3563
+ );
3564
+
3565
+ vec4 final45 = vec4(nc45) * fx45;
3566
+ vec4 final30 = vec4(nc30) * fx30;
3567
+ vec4 final60 = vec4(nc60) * fx60;
3568
+ vec4 final15 = vec4(nc15) * fx15;
3569
+ vec4 final75 = vec4(nc75) * fx75;
3570
+
3571
+ vec4 maximo = max(max(max(final15, final75), max(final30, final60)), final45);
3572
+
3573
+ if (nc.x) { pix1 = px.x ? F : H; blend1 = maximo.x; }
3574
+ else if (nc.y) { pix1 = px.y ? B : F; blend1 = maximo.y; }
3575
+ else if (nc.z) { pix1 = px.z ? D : B; blend1 = maximo.z; }
3576
+ else if (nc.w) { pix1 = px.w ? H : D; blend1 = maximo.w; }
3577
+
3578
+ if (nc.w) { pix2 = px.w ? H : D; blend2 = maximo.w; }
3579
+ else if (nc.z) { pix2 = px.z ? D : B; blend2 = maximo.z; }
3580
+ else if (nc.y) { pix2 = px.y ? B : F; blend2 = maximo.y; }
3581
+ else if (nc.x) { pix2 = px.x ? F : H; blend2 = maximo.x; }
3582
+
3583
+ res1 = mix(E, pix1, blend1);
3584
+ res2 = mix(E, pix2, blend2);
3585
+
3586
+ vec3 res = mix(res1, res2, step(c_df(E, res1), c_df(E, res2)));
3587
+
3588
+ gl_FragColor = vec4(res, 1.0);
3589
+ }/*
3590
+ Hyllian's xBR-lv3 Shader
3591
+
3592
+ Copyright (C) 2011-2015 Hyllian - sergiogdb@gmail.com
3593
+
3594
+ Permission is hereby granted, free of charge, to any person obtaining a copy
3595
+ of this software and associated documentation files (the "Software"), to deal
3596
+ in the Software without restriction, including without limitation the rights
3597
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3598
+ copies of the Software, and to permit persons to whom the Software is
3599
+ furnished to do so, subject to the following conditions:
3600
+
3601
+ The above copyright notice and this permission notice shall be included in
3602
+ all copies or substantial portions of the Software.
3603
+
3604
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3605
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3606
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3607
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3608
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3609
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3610
+ THE SOFTWARE.
3611
+
3612
+ Incorporates some of the ideas from SABR shader. Thanks to Joshua Street.
3613
+ */
3614
+
3615
+ attribute vec4 position;
3616
+
3617
+ uniform vec2 texSize;
3618
+
3619
+ varying vec2 texCoord;
3620
+ varying vec4 TEX1;
3621
+ varying vec4 TEX2;
3622
+ varying vec4 TEX3;
3623
+ varying vec4 TEX4;
3624
+ varying vec4 TEX5;
3625
+ varying vec4 TEX6;
3626
+ varying vec4 TEX7;
3627
+
3628
+ void main() {
3629
+ gl_Position = position;
3630
+
3631
+ vec2 ps = vec2(1.0) / texSize;
3632
+ float dx = ps.x;
3633
+ float dy = ps.y;
3634
+
3635
+ texCoord = (position.st + vec2(1.0, 1.0)) * vec2(0.5, 0.5);
3636
+
3637
+ // use 0.0 (float literals) for strict GLSL ES 1.00 compilers
3638
+ TEX1 = texCoord.xxxy + vec4(-dx, 0.0, dx, -2.0 * dy); // A1 B1 C1
3639
+ TEX2 = texCoord.xxxy + vec4(-dx, 0.0, dx, -1.0 * dy); // A B C
3640
+ TEX3 = texCoord.xxxy + vec4(-dx, 0.0, dx, 0.0 ); // D E F
3641
+ TEX4 = texCoord.xxxy + vec4(-dx, 0.0, dx, 1.0 * dy); // G H I
3642
+ TEX5 = texCoord.xxxy + vec4(-dx, 0.0, dx, 2.0 * dy); // G5 H5 I5
3643
+ TEX6 = texCoord.xyyy + vec4(-2.0 * dx, -dy, 0.0, dy); // A0 D0 G0
3644
+ TEX7 = texCoord.xyyy + vec4( 2.0 * dx, -dy, 0.0, dy); // C4 F4 I4
3645
+ }