View difference between Paste ID: S4rEgVvp and JMJ3iEiv
SHOW: | | - or go back to the newest paste.
1
/*
2
3
	CRT - Guest - NTSC
4
5
	Copyright (C) 2018-2025 guest(r)
6
7
	Incorporates many good ideas and suggestions from Dr. Venom.
8
9
	I would also like give thanks to many Libretro forums members for continuous feedback, suggestions and using the shader.
10
11
	This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
12
	as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
13
14
	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
	See the GNU General Public License for more details.
17
18
	You should have received a copy of the GNU General Public License along with this program; if not,
19
	write to the Free Software Foundation, Inc, 59 Temple Place - STE 330, Boston, MA 02111-1307, USA.
20
21
	Ported to ReShade by DevilSingh with some help from guest(r)
22
23
*/
24
25
uniform float internal_res <
26
	ui_type = "drag";
27
	ui_min = 0.5;
28
	ui_max = 8.0;
29
	ui_step = 0.1;
30
	ui_label = "Internal Resolution";
31
> = 1.0;
32
33
uniform float cust_artifacting <
34
	ui_type = "drag";
35
	ui_min = 0.0;
36
	ui_max = 5.0;
37
	ui_step = 0.1;
38
	ui_label = "NTSC Custom Artifacting Value";
39
> = 1.0;
40
41
uniform float cust_fringing <
42
	ui_type = "drag";
43
	ui_min = 0.0;
44
	ui_max = 5.0;
45
	ui_step = 0.1;
46
	ui_label = "NTSC Custom Fringing Value";
47
> = 1.0;
48
49
uniform float ntsc_fields <
50
	ui_type = "drag";
51
	ui_min = 1.0;
52
	ui_max = 3.0;
53
	ui_step = 1.0;
54
	ui_label = "NTSC Merge Fields: Auto | No | Yes";
55
> = 1.0;
56
57
uniform float ntsc_phase <
58
	ui_type = "drag";
59
	ui_min = 1.0;
60
	ui_max = 4.0;
61
	ui_step = 1.0;
62
	ui_label = "NTSC Phase: Auto | 2 Phase | 3 Phase | Mixed";
63
> = 1.0;
64
65
uniform float ntsc_scale <
66
	ui_type = "drag";
67
	ui_min = 0.2;
68
	ui_max = 2.5;
69
	ui_step = 0.025;
70
	ui_label = "NTSC Resolution Scaling";
71
> = 1.0;
72
73
uniform float ntsc_taps <
74
	ui_type = "drag";
75
	ui_min = 6.0;
76
	ui_max = 32.0;
77
	ui_step = 1.0;
78
	ui_label = "NTSC # of Taps (Filter Width)";
79
> = 32.0;
80
81
uniform float ntsc_cscale1 <
82
	ui_type = "drag";
83
	ui_min = 0.5;
84
	ui_max = 4.00;
85
	ui_step = 0.05;
86
	ui_label = "NTSC Chroma Scaling/Bleeding (2 Phase)";
87
> = 1.0;
88
89
uniform float ntsc_cscale2 <
90
	ui_type = "drag";
91
	ui_min = 0.2;
92
	ui_max = 2.25;
93
	ui_step = 0.05;
94
	ui_label = "NTSC Chroma Scaling/Bleeding (3 Phase)";
95
> = 1.0;
96
97
uniform float ntsc_sat <
98
	ui_type = "drag";
99
	ui_min = 0.0;
100
	ui_max = 2.0;
101
	ui_step = 0.01;
102
	ui_label = "NTSC Color Saturation";
103
> = 1.0;
104
105
uniform float ntsc_brt <
106
	ui_type = "drag";
107
	ui_min = 0.0;
108
	ui_max = 1.5;
109
	ui_step = 0.01;
110
	ui_label = "NTSC Brightness";
111
> = 1.0;
112
113
uniform float ntsc_gamma <
114
	ui_type = "drag";
115
	ui_min = 0.25;
116
	ui_max = 2.5;
117
	ui_step = 0.025;
118
	ui_label = "NTSC Filtering Gamma Correction";
119
> = 1.0;
120
121
uniform float ntsc_rainbow <
122
	ui_type = "drag";
123
	ui_min = 0.0;
124
	ui_max = 3.0;
125
	ui_step = 1.0;
126
	ui_label = "NTSC Coloring/Rainbow Effect (2 Phase)";
127
> = 0.0;
128
129
uniform float ntsc_ring <
130
	ui_type = "drag";
131
	ui_min = 0.0;
132
	ui_max = 1.0;
133
	ui_step = 0.1;
134
	ui_label = "NTSC Anti-Ringing";
135
> = 0.5;
136
137
uniform float ntsc_shrp <
138
	ui_type = "drag";
139
	ui_min = -10.0;
140
	ui_max = 10.0;
141
	ui_step = 0.5;
142
	ui_label = "NTSC Sharpness (Adaptive)";
143
> = 0.0;
144
145
uniform float ntsc_shpe <
146
	ui_type = "drag";
147
	ui_min = 0.5;
148
	ui_max = 1.0;
149
	ui_step = 0.025;
150
	ui_label = "NTSC Sharpness Shape";
151
> = 0.8;
152
153
uniform float ntsc_charp1 <
154
	ui_type = "drag";
155
	ui_min = 0.0;
156
	ui_max = 10.0;
157
	ui_step = 0.5;
158
	ui_label = "NTSC Preserve 'Edge' Colors (2 Phase)";
159
> = 0.0;
160
161
uniform float ntsc_charp2 <
162
	ui_type = "drag";
163
	ui_min = 0.0;
164
	ui_max = 10.0;
165
	ui_step = 0.5;
166
	ui_label = "NTSC Preserve 'Edge' Colors (3 Phase)";
167
> = 0.0;
168
169
uniform float CSHARPEN <
170
	ui_type = "drag";
171
	ui_min = 0.0;
172
	ui_max = 5.0;
173
	ui_step = 0.1;
174
	ui_label = "FSharpen - Sharpen Strength";
175
> = 0.0;
176
177
uniform float CCONTR <
178
	ui_type = "drag";
179
	ui_min = 0.0;
180
	ui_max = 0.25;
181
	ui_step = 0.01;
182
	ui_label = "FSharpen - Sharpen (+ Deblur) Contrast";
183
> = 0.05;
184
185
uniform float CDETAILS <
186
	ui_type = "drag";
187
	ui_min = 0.0;
188
	ui_max = 1.0;
189
	ui_step = 0.05;
190
	ui_label = "FSharpen - Sharpen Details";
191
> = 1.0;
192
193
uniform float DEBLUR <
194
	ui_type = "drag";
195
	ui_min = 1.0;
196
	ui_max = 7.0;
197
	ui_step = 0.25;
198
	ui_label = "FSharpen - Deblur Strength";
199
> = 1.0;
200
201
uniform float DREDGE <
202
	ui_type = "drag";
203
	ui_min = 0.7;
204
	ui_max = 1.0;
205
	ui_step = 0.01;
206
	ui_label = "FSharpen - Deblur Edges Falloff";
207
> = 0.9;
208
209
uniform float DSHARP <
210
	ui_type = "drag";
211
	ui_min = 0.0;
212
	ui_max = 4.0;
213
	ui_step = 0.2;
214
	ui_label = "FSharpen - Deblur Extra Sharpen";
215
> = 0.0;
216
217
uniform float vigstr <
218
	ui_type = "drag";
219
	ui_min = 0.0;
220
	ui_max = 2.0;
221
	ui_step = 0.05;
222
	ui_label = "Vignette Strength";
223
> = 0.0;
224
225
uniform float vigdef <
226
	ui_type = "drag";
227
	ui_min = 0.5;
228
	ui_max = 3.0;
229
	ui_step = 0.1;
230
	ui_label = "Vignette Size";
231
> = 1.0;
232
233
uniform float lsmooth <
234
	ui_type = "drag";
235
	ui_min = 0.5;
236
	ui_max = 1.0;
237
	ui_step = 0.01;
238
	ui_label = "Raster Bloom Effect Smoothing";
239
> = 0.7;
240
241
uniform float gamma_i <
242
	ui_type = "drag";
243
	ui_min = 1.0;
244
	ui_max = 5.0;
245
	ui_step = 0.05;
246
	ui_label = "Gamma Input";
247
> = 2.00;
248
249
uniform float gamma_o <
250
	ui_type = "drag";
251
	ui_min = 1.0;
252
	ui_max = 5.0;
253
	ui_step = 0.05;
254
	ui_label = "Gamma Out";
255
> = 1.95;
256
257
uniform float interr <
258
	ui_type = "drag";
259
	ui_min = 0.0;
260
	ui_max = 800.0;
261
	ui_step = 25.0;
262
	ui_label = "Interlace Trigger Resolution";
263
> = 400.0;
264
265
uniform float interm <
266
	ui_type = "drag";
267
	ui_min = 0.0;
268
	ui_max = 5.0;
269
	ui_step = 1.0;
270
	ui_label = "Interlace Mode: 0:OFF | 1-3:Normal | 4-5:Interpolation";
271
> = 4.0;
272
273
uniform float iscanb <
274
	ui_type = "drag";
275
	ui_min = 0.0;
276
	ui_max = 1.0;
277
	ui_step = 0.05;
278
	ui_label = "Interlacing Scanlines Effect (Interlaced Brightness)";
279
> = 0.2;
280
281
uniform float iscans <
282
	ui_type = "drag";
283
	ui_min = 0.0;
284
	ui_max = 1.0;
285
	ui_step = 0.05;
286
	ui_label = "Interlacing Scanlines Saturation";
287
> = 0.25;
288
289
uniform float hiscan <
290
	ui_type = "drag";
291
	ui_min = 0.0;
292
	ui_max = 1.0;
293
	ui_step = 1.0;
294
	ui_label = "High Resolution Scanlines (Prepend A Scaler)";
295
> = 0.0;
296
297
uniform float intres <
298
	ui_type = "drag";
299
	ui_min = 0.0;
300
	ui_max = 10.0;
301
	ui_step = 0.5;
302
	ui_label = "Internal Resolution Y: 0.5 | Y-Dowsample";
303
> = 0.0;
304
305
uniform float downsample_levelx <
306
	ui_type = "drag";
307
	ui_min = 0.0;
308
	ui_max = 2.0;
309
	ui_step = 0.05;
310
	ui_label = "Downsampling-X (High-Res Content, Pre-Scalers)";
311
> = 0.0;
312
313
uniform float downsample_levely <
314
	ui_type = "drag";
315
	ui_min = 0.0;
316
	ui_max = 2.0;
317
	ui_step = 0.05;
318
	ui_label = "Downsampling-Y (High-Res Content, Pre-Scalers)";
319
> = 0.0;
320
321
uniform float HSHARPNESS <
322
	ui_type = "drag";
323
	ui_min = 1.0;
324
	ui_max = 8.0;
325
	ui_step = 0.05;
326
	ui_label = "Horizontal Filter Range";
327
> = 1.6;
328
329
uniform float LIGMA_H <
330
	ui_type = "drag";
331
	ui_min = 0.1;
332
	ui_max = 7.0;
333
	ui_step = 0.025;
334
	ui_label = "Horizontal Blur Sigma";
335
> = 0.8;
336
337
uniform float S_SHARP <
338
	ui_type = "drag";
339
	ui_min = 0.0;
340
	ui_max = 3.0;
341
	ui_step = 0.05;
342
	ui_label = "Substractive Sharpness";
343
> = 1.1;
344
345
uniform float SHARP <
346
	ui_type = "drag";
347
	ui_min = 0.0;
348
	ui_max = 2.0;
349
	ui_step = 0.1;
350
	ui_label = "Sharpness Definition";
351
> = 1.2;
352
353
uniform float MAXS <
354
	ui_type = "drag";
355
	ui_min = 0.0;
356
	ui_max = 0.3;
357
	ui_step = 0.01;
358
	ui_label = "Maximum Sharpness";
359
> = 0.18;
360
361
uniform float SSRNG <
362
	ui_type = "drag";
363
	ui_min = 0.0;
364
	ui_max = 4.0;
365
	ui_step = 0.05;
366
	ui_label = "Substractive Sharpness Ringing";
367
> = 0.3;
368
369
uniform float m_glow <
370
	ui_type = "drag";
371
	ui_min = 0.0;
372
	ui_max = 2.0;
373
	ui_step = 1.0;
374
	ui_label = "Ordinary Glow | Magic Glow";
375
> = 0.0;
376
377
uniform float m_glow_cutoff <
378
	ui_type = "drag";
379
	ui_min = 0.0;
380
	ui_max = 0.4;
381
	ui_step = 0.01;
382
	ui_label = "Magic Glow Cutoff";
383
> = 0.12;
384
385
uniform float m_glow_low <
386
	ui_type = "drag";
387
	ui_min = 0.0;
388
	ui_max = 7.0;
389
	ui_step = 0.05;
390
	ui_label = "Magic Glow Low Strength";
391
> = 0.35;
392
393
uniform float m_glow_high <
394
	ui_type = "drag";
395
	ui_min = 0.0;
396
	ui_max = 7.0;
397
	ui_step = 0.1;
398
	ui_label = "Magic Glow High Strength";
399
> = 5.0;
400
401
uniform float m_glow_dist <
402
	ui_type = "drag";
403
	ui_min = 0.2;
404
	ui_max = 4.0;
405
	ui_step = 0.05;
406
	ui_label = "Magic Glow Distribution";
407
> = 1.0;
408
409
uniform float m_glow_mask <
410
	ui_type = "drag";
411
	ui_min = 0.0;
412
	ui_max = 2.0;
413
	ui_step = 0.025;
414
	ui_label = "Magic Glow Mask Strength";
415
> = 1.0;
416
417
uniform float FINE_GAUSS <
418
	ui_type = "drag";
419
	ui_min = -1.0;
420
	ui_max = 5.0;
421
	ui_step = 1.0;
422
	ui_label = "Fine (Magic) Glow Sampling";
423
> = 1.0;
424
425
uniform float SIZEH <
426
	ui_type = "drag";
427
	ui_min = 1.0;
428
	ui_max = 50.0;
429
	ui_step = 1.0;
430
	ui_label = "Horizontal Glow Radius";
431
> = 6.0;
432
433
uniform float SIGMA_H <
434
	ui_type = "drag";
435
	ui_min = 0.2;
436
	ui_max = 15.0;
437
	ui_step = 0.05;
438
	ui_label = "Horizontal Glow Sigma";
439
> = 1.2;
440
441
uniform float SIZEV <
442
	ui_type = "drag";
443
	ui_min = 1.0;
444
	ui_max = 50.0;
445
	ui_step = 1.0;
446
	ui_label = "Vertical Glow Radius";
447
> = 6.0;
448
449
uniform float SIGMA_V <
450
	ui_type = "drag";
451
	ui_min = 0.2;
452
	ui_max = 15.0;
453
	ui_step = 0.05;
454
	ui_label = "Vertical Glow Sigma";
455
> = 1.2;
456
457
uniform float FINE_BLOOM <
458
	ui_type = "drag";
459
	ui_min = -1.0;
460
	ui_max = 5.0;
461
	ui_step = 1.0;
462
	ui_label = "Fine Bloom/Halation Sampling";
463
> = 1.0;
464
465
uniform float SIZEX <
466
	ui_type = "drag";
467
	ui_min = 1.0;
468
	ui_max = 50.0;
469
	ui_step = 1.0;
470
	ui_label = "Horizontal Bloom/Halation Radius";
471
> = 3.0;
472
473
uniform float SIGMA_X <
474
	ui_type = "drag";
475
	ui_min = 0.25;
476
	ui_max = 15.0;
477
	ui_step = 0.025;
478
	ui_label = "Horizontal Bloom/Halation Sigma";
479
> = 0.75;
480
481
uniform float SIZEY <
482
	ui_type = "drag";
483
	ui_min = 1.0;
484
	ui_max = 50.0;
485
	ui_step = 1.0;
486
	ui_label = "Vertical Bloom/Halation Radius";
487
> = 3.0;
488
489
uniform float SIGMA_Y <
490
	ui_type = "drag";
491
	ui_min = 0.25;
492
	ui_max = 15.0;
493
	ui_step = 0.025;
494
	ui_label = "Vertical Bloom/Halation Sigma";
495
> = 0.60;
496
497
uniform float glow <
498
	ui_type = "drag";
499
	ui_min = -2.0;
500
	ui_max = 2.0;
501
	ui_step = 0.01;
502
	ui_label = "(Magic) Glow Strength";
503
> = 0.08;
504
505
uniform float blm_1 <
506
	ui_type = "drag";
507
	ui_min = -2.0;
508
	ui_max = 2.0;
509
	ui_step = 0.05;
510
	ui_label = "Bloom Strength";
511
> = 0.0;
512
513
uniform float b_mask <
514
	ui_type = "drag";
515
	ui_min = -1.0;
516
	ui_max = 1.0;
517
	ui_step = 0.025;
518
	ui_label = "Bloom Mask Strength";
519
> = 0.0;
520
521
uniform float mask_bloom <
522
	ui_type = "drag";
523
	ui_min = -2.0;
524
	ui_max = 2.0;
525
	ui_step = 0.05;
526
	ui_label = "Mask Bloom";
527
> = 0.0;
528
529
uniform float bloom_dist <
530
	ui_type = "drag";
531
	ui_min = -2.0;
532
	ui_max = 3.0;
533
	ui_step = 0.05;
534
	ui_label = "Bloom Distribution";
535
> = 0.0;
536
537
uniform float halation <
538
	ui_type = "drag";
539
	ui_min = -2.0;
540
	ui_max = 2.0;
541
	ui_step = 0.025;
542
	ui_label = "Halation Strength";
543
> = 0.0;
544
545
uniform float h_mask <
546
	ui_type = "drag";
547
	ui_min = -1.0;
548
	ui_max = 1.0;
549
	ui_step = 0.025;
550
	ui_label = "Halation Mask Strength";
551
> = 0.5;
552
553
uniform float gamma_c <
554
	ui_type = "drag";
555
	ui_min = 0.5;
556
	ui_max = 2.0;
557
	ui_step = 0.025;
558
	ui_label = "Gamma Correct";
559
> = 1.0;
560
561
uniform float gamma_d <
562
	ui_type = "drag";
563
	ui_min = 1.0;
564
	ui_max = 2.0;
565
	ui_step = 0.025;
566
	ui_label = "Complementary Gamma Correct";
567
> = 1.0;
568
569
uniform float brightboost1 <
570
	ui_type = "drag";
571
	ui_min = 0.25;
572
	ui_max = 10.0;
573
	ui_step = 0.05;
574
	ui_label = "Bright Boost Dark Pixels";
575
> = 1.4;
576
577
uniform float brightboost2 <
578
	ui_type = "drag";
579
	ui_min = 0.25;
580
	ui_max = 3.0;
581
	ui_step = 0.025;
582
	ui_label = "Bright Boost Bright Pixels";
583
> = 1.1;
584
585
uniform float clp <
586
	ui_type = "drag";
587
	ui_min = -1.0;
588
	ui_max = 1.0;
589
	ui_step = 0.05;
590
	ui_label = "Clip Saturated Color Beams";
591
> = 0.0;
592
593
uniform float gsl <
594
	ui_type = "drag";
595
	ui_min = -1.0;
596
	ui_max = 2.0;
597
	ui_step = 1.0;
598
	ui_label = "Scanlines Type";
599
> = 0.0;
600
601
uniform float scanline1 <
602
	ui_type = "drag";
603
	ui_min = -20.0;
604
	ui_max = 40.0;
605
	ui_step = 0.5;
606
	ui_label = "Scanlines Beam Shape Center";
607
> = 6.0;
608
609
uniform float scanline2 <
610
	ui_type = "drag";
611
	ui_min = 0.0;
612
	ui_max = 70.0;
613
	ui_step = 1.0;
614
	ui_label = "Scanlines Beam Shape Edges";
615
> = 8.0;
616
617
uniform float beam_min <
618
	ui_type = "drag";
619
	ui_min = 0.25;
620
	ui_max = 10.0;
621
	ui_step = 0.05;
622
	ui_label = "Scanlines Shape Dark Pixels";
623
> = 1.3;
624
625
uniform float beam_max <
626
	ui_type = "drag";
627
	ui_min = 0.2;
628
	ui_max = 3.5;
629
	ui_step = 0.025;
630
	ui_label = "Scanlines Shape Bright Pixels";
631
> = 1.0;
632
633
uniform float tds <
634
	ui_type = "drag";
635
	ui_min = 0.0;
636
	ui_max = 1.0;
637
	ui_step = 1.0;
638
	ui_label = "Thinner Dark Scanlines";
639
> = 0.0;
640
641
uniform float beam_size <
642
	ui_type = "drag";
643
	ui_min = 0.0;
644
	ui_max = 1.0;
645
	ui_step = 0.05;
646
	ui_label = "Increased Bright Scanlines Beam";
647
> = 0.6;
648
649
uniform float scans <
650
	ui_type = "drag";
651
	ui_min = 0.0;
652
	ui_max = 6.0;
653
	ui_step = 0.1;
654
	ui_label = "Scanlines Saturation / Mask Falloff";
655
> = 0.5;
656
657
uniform float scan_falloff <
658
	ui_type = "drag";
659
	ui_min = 0.1;
660
	ui_max = 2.0;
661
	ui_step = 0.025;
662
	ui_label = "Scanlines Falloff";
663
> = 1.0;
664
665
uniform float spike <
666
	ui_type = "drag";
667
	ui_min = 0.0;
668
	ui_max = 2.0;
669
	ui_step = 0.1;
670
	ui_label = "Scanlines Spike Removal";
671
> = 1.0;
672
673
uniform float scangamma <
674
	ui_type = "drag";
675
	ui_min = 0.5;
676
	ui_max = 5.0;
677
	ui_step = 0.05;
678
	ui_label = "Scanlines Gamma";
679
> = 2.4;
680
681
uniform float rolling_scan <
682
	ui_type = "drag";
683
	ui_min = -1.0;
684
	ui_max = 1.0;
685
	ui_step = 0.01;
686
	ui_label = "Rolling Scanlines";
687
> = 0.0;
688
689
uniform float no_scanlines <
690
	ui_type = "drag";
691
	ui_min = 0.0;
692
	ui_max = 1.5;
693
	ui_step = 0.05;
694
	ui_label = "No-Scanlines Mode";
695
> = 0.0;
696
697
uniform float IOS <
698
	ui_type = "drag";
699
	ui_min = 0.0;
700
	ui_max = 4.0;
701
	ui_step = 1.0;
702
	ui_label = "Integer Scaling: Odd:Y | Even:X+Y";
703
> = 0.0;
704
705
uniform float OS <
706
	ui_type = "drag";
707
	ui_min = 0.0;
708
	ui_max = 2.0;
709
	ui_step = 1.0;
710
	ui_label = "Raster Bloom Overscan Mode";
711
> = 1.0;
712
713
uniform float blm_2 <
714
	ui_type = "drag";
715
	ui_min = 0.0;
716
	ui_max = 20.0;
717
	ui_step = 1.0;
718
	ui_label = "Raster Bloom %";
719
> = 0.0;
720
721
uniform float csize <
722
	ui_type = "drag";
723
	ui_min = 0.0;
724
	ui_max = 0.35;
725
	ui_step = 0.01;
726
	ui_label = "Corner Size";
727
> = 0.0;
728
729
uniform float bsize <
730
	ui_type = "drag";
731
	ui_min = 0.0;
732
	ui_max = 2.0;
733
	ui_step = 0.01;
734
	ui_label = "Border Size";
735
> = 0.0;
736
737
uniform float sborder <
738
	ui_type = "drag";
739
	ui_min = 0.25;
740
	ui_max = 2.0;
741
	ui_step = 0.05;
742
	ui_label = "Border Intensity";
743
> = 0.75;
744
745
uniform float barspeed <
746
	ui_type = "drag";
747
	ui_min = 5.0;
748
	ui_max = 200.0;
749
	ui_step = 1.0;
750
	ui_label = "Hum Bar Speed";
751
> = 50.0;
752
753
uniform float barintensity <
754
	ui_type = "drag";
755
	ui_min = -1.0;
756
	ui_max = 1.0;
757
	ui_step = 0.01;
758
	ui_label = "Hum Bar Intensity";
759
> = 0.0;
760
761
uniform float bardir <
762
	ui_type = "drag";
763
	ui_min = 0.0;
764
	ui_max = 1.0;
765
	ui_step = 1.0;
766
	ui_label = "Hum Bar Direction";
767
> = 0.0;
768
769
uniform float warpx <
770
	ui_type = "drag";
771
	ui_min = 0.0;
772
	ui_max = 0.25;
773
	ui_step = 0.01;
774
	ui_label = "Curvature X (Default 0.03)";
775
> = 0.0;
776
777
uniform float warpy <
778
	ui_type = "drag";
779
	ui_min = 0.0;
780
	ui_max = 0.25;
781
	ui_step = 0.01;
782
	ui_label = "Curvature Y (Default 0.04)";
783
> = 0.0;
784
785
uniform float c_shape <
786
	ui_type = "drag";
787
	ui_min = 0.05;
788
	ui_max = 0.6;
789
	ui_step = 0.05;
790
	ui_label = "Curvature Shape";
791
> = 0.25;
792
793
uniform float overscanx <
794
	ui_type = "drag";
795
	ui_min = -200.0;
796
	ui_max = 200.0;
797
	ui_step = 1.0;
798
	ui_label = "Overscan X Original Pixels";
799
> = 0.0;
800
801
uniform float overscany <
802
	ui_type = "drag";
803
	ui_min = -200.0;
804
	ui_max = 200.0;
805
	ui_step = 1.0;
806
	ui_label = "Overscan Y Original Pixels";
807
> = 0.0;
808
809
uniform float shadow_msk <
810
	ui_type = "drag";
811
	ui_min = 0.0;
812
	ui_max = 14.0;
813
	ui_step = 1.0;
814
	ui_label = "CRT Mask: 1:CGWG | 2-5:Lottes | 6-14:Trinitron";
815
> = 1.0;
816
817
uniform float maskstr <
818
	ui_type = "drag";
819
	ui_min = -0.5;
820
	ui_max = 1.0;
821
	ui_step = 0.025;
822
	ui_label = "Mask Strength (1, 6-14)";
823
> = 0.3;
824
825
uniform float mcut <
826
	ui_type = "drag";
827
	ui_min = 0.0;
828
	ui_max = 2.0;
829
	ui_step = 0.05;
830
	ui_label = "Mask 6-14 Low Strength";
831
> = 1.1;
832
833
uniform float maskboost <
834
	ui_type = "drag";
835
	ui_min = 1.0;
836
	ui_max = 3.0;
837
	ui_step = 0.05;
838
	ui_label = "CRT Mask Boost";
839
> = 1.0;
840
841
uniform float masksize <
842
	ui_type = "drag";
843
	ui_min = 1.0;
844
	ui_max = 4.0;
845
	ui_step = 1.0;
846
	ui_label = "CRT Mask Size";
847
> = 1.0;
848
849
uniform float mask_zoom <
850
	ui_type = "drag";
851
	ui_min = -10.0;
852
	ui_max = 6.0;
853
	ui_step = 1.0;
854
	ui_label = "CRT Mask Zoom (+ Mask Width)";
855
> = 0.0;
856
857
uniform float zoom_mask <
858
	ui_type = "drag";
859
	ui_min = 0.0;
860
	ui_max = 1.0;
861
	ui_step = 0.05;
862
	ui_label = "CRT Mask Zoom Sharpen";
863
> = 0.0;
864
865
uniform float mshift <
866
	ui_type = "drag";
867
	ui_min = 0.0;
868
	ui_max = 1.0;
869
	ui_step = 0.5;
870
	ui_label = "(Transform to) Shadow Mask";
871
> = 0.0;
872
873
uniform float mask_layout <
874
	ui_type = "drag";
875
	ui_min = 0.0;
876
	ui_max = 1.0;
877
	ui_step = 1.0;
878
	ui_label = "Mask Layout: RGB or BGR (Check LCD Panel)";
879
> = 0.0;
880
881
uniform float mask_drk <
882
	ui_type = "drag";
883
	ui_min = 0.0;
884
	ui_max = 2.0;
885
	ui_step = 0.05;
886
	ui_label = "Lottes Mask Dark";
887
> = 0.5;
888
889
uniform float mask_lgt <
890
	ui_type = "drag";
891
	ui_min = 0.0;
892
	ui_max = 2.0;
893
	ui_step = 0.05;
894
	ui_label = "Lottes Mask Bright";
895
> = 1.5;
896
897
uniform float mask_gamma <
898
	ui_type = "drag";
899
	ui_min = 1.0;
900
	ui_max = 5.0;
901
	ui_step = 0.05;
902
	ui_label = "Mask Gamma";
903
> = 2.4;
904
905
uniform float slotmask1 <
906
	ui_type = "drag";
907
	ui_min = 0.0;
908
	ui_max = 1.0;
909
	ui_step = 0.05;
910
	ui_label = "Slot Mask Strength Bright Pixels";
911
> = 0.0;
912
913
uniform float slotmask2 <
914
	ui_type = "drag";
915
	ui_min = 0.0;
916
	ui_max = 1.0;
917
	ui_step = 0.05;
918
	ui_label = "Slot Mask Strength Dark Pixels";
919
> = 0.0;
920
921
uniform float slotwidth <
922
	ui_type = "drag";
923
	ui_min = 0.0;
924
	ui_max = 16.0;
925
	ui_step = 1.0;
926
	ui_label = "Slot Mask Width (0:Auto)";
927
> = 0.0;
928
929
uniform float double_slot <
930
	ui_type = "drag";
931
	ui_min = 1.0;
932
	ui_max = 4.0;
933
	ui_step = 1.0;
934
	ui_label = "Slot Mask Height: 2x1 or 4x1";
935
> = 2.0;
936
937
uniform float slotms <
938
	ui_type = "drag";
939
	ui_min = 1.0;
940
	ui_max = 4.0;
941
	ui_step = 1.0;
942
	ui_label = "Slot Mask Thickness";
943
> = 1.0;
944
945
uniform float smoothmask <
946
	ui_type = "drag";
947
	ui_min = 0.0;
948
	ui_max = 2.0;
949
	ui_step = 0.25;
950
	ui_label = "Smooth Masks In Bright Scanlines";
951
> = 0.0;
952
953
uniform float smask_mit <
954
	ui_type = "drag";
955
	ui_min = 0.0;
956
	ui_max = 1.0;
957
	ui_step = 0.05;
958
	ui_label = "Mitigate Slot Mask Interaction";
959
> = 0.0;
960
961
uniform float bmask <
962
	ui_type = "drag";
963
	ui_min = 0.0;
964
	ui_max = 0.25;
965
	ui_step = 0.01;
966
	ui_label = "Base (Black) Mask Strength";
967
> = 0.0;
968
969
uniform float mclip <
970
	ui_type = "drag";
971
	ui_min = 0.0;
972
	ui_max = 1.0;
973
	ui_step = 0.025;
974
	ui_label = "Preserve Mask Strength";
975
> = 0.0;
976
977
uniform float pr_scan <
978
	ui_type = "drag";
979
	ui_min = 0.0;
980
	ui_max = 1.0;
981
	ui_step = 0.025;
982
	ui_label = "Preserve Scanlines Strength";
983
> = 0.1;
984
985
uniform float maskmid <
986
	ui_type = "drag";
987
	ui_min = 0.0;
988
	ui_max = 1.0;
989
	ui_step = 0.05;
990
	ui_label = "Mitigate Mask on Mid-Colors";
991
> = 0.0;
992
993
uniform float edgemask <
994
	ui_type = "drag";
995
	ui_min = 0.0;
996
	ui_max = 1.0;
997
	ui_step = 0.1;
998
	ui_label = "Mitigate Mask on Edges";
999
> = 0.0;
1000
1001
uniform float dctypex <
1002
	ui_type = "drag";
1003
	ui_min = 0.0;
1004
	ui_max = 0.75;
1005
	ui_step = 0.05;
1006
	ui_label = "Deconvergence Type X: 0:Static | Other:Dynamic";
1007
> = 0.0;
1008
1009
uniform float dctypey <
1010
	ui_type = "drag";
1011
	ui_min = 0.0;
1012
	ui_max = 0.75;
1013
	ui_step = 0.05;
1014
	ui_label = "Deconvergence Type Y: 0:Static | Other:Dynamic";
1015
> = 0.0;
1016
1017
uniform float deconrx <
1018
	ui_type = "drag";
1019
	ui_min = -15.0;
1020
	ui_max = 15.0;
1021
	ui_step = 0.25;
1022
	ui_label = "Horizontal Deconvergence 'R' Range";
1023
> = 0.0;
1024
1025
uniform float decongx <
1026
	ui_type = "drag";
1027
	ui_min = -15.0;
1028
	ui_max = 15.0;
1029
	ui_step = 0.25;
1030
	ui_label = "Horizontal Deconvergence 'G' Range";
1031
> = 0.0;
1032
1033
uniform float deconbx <
1034
	ui_type = "drag";
1035
	ui_min = -15.0;
1036
	ui_max = 15.0;
1037
	ui_step = 0.25;
1038
	ui_label = "Horizontal Deconvergence 'B' Range";
1039
> = 0.0;
1040
1041
uniform float deconry <
1042
	ui_type = "drag";
1043
	ui_min = -15.0;
1044
	ui_max = 15.0;
1045
	ui_step = 0.25;
1046
	ui_label = "Vertical Deconvergence 'R' Range";
1047
> = 0.0;
1048
1049
uniform float decongy <
1050
	ui_type = "drag";
1051
	ui_min = -15.0;
1052
	ui_max = 15.0;
1053
	ui_step = 0.25;
1054
	ui_label = "Vertical Deconvergence 'G' Range";
1055
> = 0.0;
1056
1057
uniform float deconby <
1058
	ui_type = "drag";
1059
	ui_min = -15.0;
1060
	ui_max = 15.0;
1061
	ui_step = 0.25;
1062
	ui_label = "Vertical Deconvergence 'B' Range";
1063
> = 0.0;
1064
1065
uniform float decons <
1066
	ui_type = "drag";
1067
	ui_min = 0.0;
1068
	ui_max = 3.0;
1069
	ui_step = 0.1;
1070
	ui_label = "Deconvergence Strength";
1071
> = 1.0;
1072
1073
uniform float addnoised <
1074
	ui_type = "drag";
1075
	ui_min = -1.0;
1076
	ui_max = 1.0;
1077
	ui_step = 0.02;
1078
	ui_label = "Add Noise";
1079
> = 0.0;
1080
1081
uniform float noiseresd <
1082
	ui_type = "drag";
1083
	ui_min = 1.0;
1084
	ui_max = 10.0;
1085
	ui_step = 1.0;
1086
	ui_label = "Noise Resolution";
1087
> = 2.0;
1088
1089
uniform float noisetype <
1090
	ui_type = "drag";
1091
	ui_min = 0.0;
1092
	ui_max = 1.0;
1093
	ui_step = 1.0;
1094
	ui_label = "Noise Type: Colored | Luma";
1095
> = 0.0;
1096
1097
uniform float post_br <
1098
	ui_type = "drag";
1099
	ui_min = 0.25;
1100
	ui_max = 5.0;
1101
	ui_step = 0.01;
1102
	ui_label = "Post Brightness";
1103
> = 1.0;
1104
1105
#include "ReShade.fxh"
1106
1107
#define TexSize float2(Resolution_X,Resolution_Y)
1108
#define IptSize float2(800.00000000,600.00000000)
1109
#define BoxSize float2(AspectSize_X,AspectSize_Y)
1110
#define OptSize float4(BUFFER_SCREEN_SIZE,1.0/BUFFER_SCREEN_SIZE)
1111
#define OrgSize float4(TexSize,1.0/TexSize)
1112
#define SrcSize float4(IptSize,1.0/IptSize)
1113
#define NewSize float4(BoxSize,1.0/BoxSize)
1114
#define fuxcoord (texcoord*1.00001)
1115
#define scans 1.5*scans
1116
#define eps 1e-8
1117
#define pii 3.14159265
1118
#define fracoord (fuxcoord*NewSize.xy)
1119
#define texCD(c,d) tex2Dlod(c,float4(d,0,0))
1120
#define LumSize float4(2.0*TexSize.x,1.0*TexSize.y,1.0/(2.0*TexSize.x),1.0/(1.0*TexSize.y))
1121
#define mix_m float3x3(BRIGHTNESS,ARTIFACT,ARTIFACT,FRINGING,2.0*SATURATION,0.0,FRINGING,0.0,2.0*SATURATION)
1122
#define rgb_m float3x3(0.299,0.587,0.114,0.596,-0.274,-0.322,0.211,-0.523,0.312)
1123
#define yiq_m float3x3(1.000,0.956,0.621,1.000,-0.272,-0.647,1.000,-1.106,1.703)
1124
#define fetch_offset1(dx)  texCD(NTSC_S02,tex_c+dx).xyz+texCD(NTSC_S02,tex_c-dx).xyz
1125
#define fetch_offset2(dx) float3(texCD(NTSC_S02,tex_c+dx.xz).x+texCD(NTSC_S02,tex_c-dx.xz).x,texCD(NTSC_S02,tex_c+dx.yz).yz+texCD(NTSC_S02,tex_c-dx.yz).yz)
1126
1127
#ifndef Resolution_X
1128
#define Resolution_X 320
1129
#endif
1130
1131
#ifndef Resolution_Y
1132
#define Resolution_Y 240
1133
#endif
1134
1135
#ifndef AspectSize_X
1136
#define AspectSize_X BUFFER_SCREEN_SIZE.x
1137
#endif
1138
1139
#ifndef AspectSize_Y
1140
#define AspectSize_Y BUFFER_SCREEN_SIZE.y
1141
#endif
1142
1143
#define NTSC_S00 ReShade::BackBuffer
1144
1145
texture NTSC_T01{Width=1.0*Resolution_X;Height=Resolution_Y;Format=RGBA16F;};
1146
sampler NTSC_S01{Texture=NTSC_T01;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=POINT ;MinFilter=POINT ;MipFilter=POINT ;};
1147
1148
texture NTSC_T02{Width=4.0*Resolution_X;Height=Resolution_Y;Format=RGBA16F;};
1149
sampler NTSC_S02{Texture=NTSC_T02;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1150
1151
texture NTSC_T03{Width=2.0*Resolution_X;Height=Resolution_Y;Format=RGBA16F;};
1152
sampler NTSC_S03{Texture=NTSC_T03;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1153
1154
texture NTSC_T04{Width=2.0*Resolution_X;Height=Resolution_Y;Format=RGBA16F;};
1155
sampler NTSC_S04{Texture=NTSC_T04;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1156
1157
texture NTSC_T05{Width=2.0*Resolution_X;Height=Resolution_Y;Format=RGBA16F;};
1158
sampler NTSC_S05{Texture=NTSC_T05;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1159
1160
texture NTSC_T06{Width=2.0*Resolution_X;Height=Resolution_Y;Format=RGBA16F;};
1161
sampler NTSC_S06{Texture=NTSC_T06;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1162
1163
texture NTSC_T07{Width=2.0*Resolution_X;Height=Resolution_Y;Format=RGBA16F;};
1164
sampler NTSC_S07{Texture=NTSC_T07;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1165
1166
texture NTSC_T08{Width=1.0*AspectSize_X;Height=Resolution_Y;Format=RGBA16F;};
1167
sampler NTSC_S08{Texture=NTSC_T08;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1168
1169
texture NTSC_T09{Width=1.0*800.00000000;Height=Resolution_Y;Format=RGBA16F;};
1170
sampler NTSC_S09{Texture=NTSC_T09;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1171
1172
texture NTSC_T10{Width=1.0*800.00000000;Height=600.00000000;Format=RGBA16F;};
1173
sampler NTSC_S10{Texture=NTSC_T10;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1174
1175
texture NTSC_T11{Width=1.0*800.00000000;Height=600.00000000;Format=RGBA16F;};
1176
sampler NTSC_S11{Texture=NTSC_T11;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1177
1178
texture NTSC_T12{Width=1.0*800.00000000;Height=600.00000000;Format=RGBA16F;};
1179
sampler NTSC_S12{Texture=NTSC_T12;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1180
1181
texture NTSC_T13{Width=1.0*AspectSize_X;Height=AspectSize_Y;Format=RGBA16F;};
1182
sampler NTSC_S13{Texture=NTSC_T13;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1183
1184
texture NTSC_T14{Width=1.0*AspectSize_X;Height=AspectSize_Y;Format=RGBA16F;};
1185
sampler NTSC_S14{Texture=NTSC_T14;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
1186
1187
uniform int framecount<source="framecount";>;
1188
1189
float vignette(float2 pos)
1190
{
1191
	float2 b=vigdef*float2(1.0,OrgSize.x/OrgSize.y)*0.125;
1192
	pos=clamp(pos,0.0,1.0);
1193
	pos=abs(2.0*(pos-0.5));
1194
	float2 res=lerp(0.0.xx,1.0.xx,smoothstep(1.0.xx,1.0.xx-b,sqrt(pos)));
1195
	res=pow(res,0.70.xx);
1196
	return max(lerp(1.0,sqrt(res.x*res.y),vigstr),0.0);
1197
}
1198
1199
float dist(float3 A,float3 B)
1200
{
1201
	float r=0.5*(A.r+B.r);
1202
	float3 d=A-B;
1203
	float3 c=float3(2.+r,4.,3.-r);
1204
	return sqrt(dot(c*d,d))/3.;
1205
}
1206
1207
float3 plant(float3 tar,float r)
1208
{
1209
	float t=max(max(tar.r,tar.g),tar.b)+0.00001;
1210
	return tar*r/t;
1211
}
1212
1213
float3 fetch_pixel(float2 coord)
1214
{
1215
	float2 dx=float2(LumSize.z,0.0)*downsample_levelx;
1216
	float2 dy=float2(0.0,LumSize.w)*downsample_levely;
1217
	float2 d1=dx+dy;
1218
	float2 d2=dx-dy;
1219
	float sum=15.0;
1220
	float3 result=
1221
	3.0*texCD(NTSC_S05,coord   ).rgb+2.0*texCD(NTSC_S05,coord+dx).rgb+2.0*texCD(NTSC_S05,coord-dx).rgb+
1222
	2.0*texCD(NTSC_S05,coord+dy).rgb+2.0*texCD(NTSC_S05,coord-dy).rgb+    texCD(NTSC_S05,coord+d1).rgb+
1223
		texCD(NTSC_S05,coord-d1).rgb+    texCD(NTSC_S05,coord+d2).rgb+    texCD(NTSC_S05,coord-d2).rgb;
1224
	return result/sum;
1225
}
1226
1227
float gauss_h(float x)
1228
{
1229
	float sigma=1.0/(2.0*SIGMA_H*SIGMA_H);
1230
	return exp(-x*x*sigma);
1231
}
1232
1233
float gauss_v(float x)
1234
{
1235
	float sigma=1.0/(2.0*SIGMA_V*SIGMA_V);
1236
	return exp(-x*x*sigma);
1237
}
1238
1239
float bloom_h(float x)
1240
{
1241
	float sigma=1.0/(2.0*SIGMA_X*SIGMA_X);
1242
	return exp(-x*x*sigma);
1243
}
1244
1245
float bloom_v(float x)
1246
{
1247
	float sigma=1.0/(2.0*SIGMA_Y*SIGMA_Y);
1248
	return exp(-x*x*sigma);
1249
}
1250
1251
float crthd_h(float x,float y)
1252
{
1253
	float sigma=1.0/(2.0*LIGMA_H*LIGMA_H*y*y*internal_res*internal_res);
1254
	return exp(-x*x*sigma);
1255
}
1256
1257
float mod(float x,float y)
1258
{
1259
	return x-y* floor(x/y);
1260
}
1261
1262
float st0(float x)
1263
{
1264
	return exp2(-10.0*x*x);
1265
}
1266
1267
float3 sw0(float x,float color,float scanline,float3 c)
1268
{
1269
	float3 xe=lerp(1.0.xxx+scans,1.0.xxx,c);
1270
	float tmp=lerp(beam_min,beam_max,color);
1271
	float ex=x*tmp;
1272
	ex=(gsl>-0.5)?ex*ex:lerp(ex*ex,ex*ex*ex,0.4);
1273
	return exp2(-scanline*ex*xe);
1274
}
1275
1276
float3 sw1(float x,float color,float scanline,float3 c)
1277
{
1278
	float3 xe=lerp(1.0.xxx+scans,1.0.xxx,c);
1279
	x=lerp(x,beam_min*x,max(x-0.4*color,0.0));
1280
	float tmp=lerp(1.2*beam_min,beam_max,color);
1281
	float ex=x*tmp;
1282
	return exp2(-scanline*ex*ex*xe);
1283
}
1284
1285
float3 sw2(float x,float color,float scanline,float3 c)
1286
{
1287
	float3 xe=lerp(1.0.xxx+scans,1.0.xxx,c);
1288
	float tmp=lerp((2.5-0.5*color)*beam_min,beam_max,color);
1289
	tmp=lerp(beam_max,tmp,pow(x,color+0.3));
1290
	float ex=x*tmp;
1291
	return exp2(-scanline*ex*ex*xe);
1292
}
1293
1294
float2 overscan(float2 pos,float dx,float dy)
1295
{
1296
	pos=pos*2.0-1.0;
1297
	pos*=float2(dx,dy);
1298
	return pos*0.5+0.5;
1299
}
1300
1301
float2 warp(float2 pos)
1302
{
1303
	pos=pos*2.0-1.0;
1304
	pos=lerp(pos,float2(pos.x*rsqrt(1.0-c_shape*pos.y*pos.y),pos.y*rsqrt(1.0-c_shape*pos.x*pos.x)),float2(warpx,warpy)/c_shape);
1305
	return pos*0.5+0.5;
1306
}
1307
1308
float3 gc1(float3 c)
1309
{
1310
	float mc=max(max(c.r,c.g),c.b);
1311
	float mg=pow(mc,1.0/gamma_c);
1312
	return c*mg/(mc+eps);
1313
}
1314
1315
float3 rgb2yiq(float3 r)
1316
{
1317
	return mul(rgb_m, r);
1318
}
1319
1320
float3 yiq2rgb(float3 y)
1321
{
1322
	return mul(yiq_m, y);
1323
}
1324
1325
float get_luma(float3 c)
1326
{
1327
	return dot(c,float3(0.299,0.587,0.114));
1328
}
1329
1330
float swoothstep(float e0,float e1,float x)
1331
{
1332
	return clamp((x-e0)/(e1-e0),0.0,1.0);
1333
}
1334
1335
float3 crt_mask(float2 pos,float mx,float mb)
1336
{
1337
	float3 mask=mask_drk;
1338
	float3 one=1.0;
1339
	if(shadow_msk== 1.0)
1340
	{
1341
	float mc=1.0-max(maskstr,0.0);
1342
	pos.x=frac(pos.x*0.5);
1343
	if(pos.x<0.49)
1344
	{
1345
	mask.r=1.0;mask.g= mc;mask.b=1.0;
1346
	}else
1347
	{
1348
	mask.r= mc;mask.g=1.0;mask.b= mc;
1349
	}
1350
	}else
1351
	if(shadow_msk== 2.0)
1352
	{
1353
	float lane=mask_lgt;
1354
	float odd=0.0;
1355
	if(frac(pos.x/6.0)<0.49)odd=1.0;
1356
	if(frac((pos.y+odd)/2.0)<0.49)lane=mask_drk;
1357
	pos.x=floor(mod(pos.x,3.0));
1358
	if(pos.x<0.5)mask.r=mask_lgt;else
1359
	if(pos.x<1.5)mask.g=mask_lgt;else
1360
	mask.b= mask_lgt;
1361
	mask*=lane;
1362
	}else
1363
	if(shadow_msk== 3.0)
1364
	{
1365
	pos.x=floor(mod(pos.x,3.0));
1366
	if(pos.x<0.5)mask.r=mask_lgt;else
1367
	if(pos.x<1.5)mask.g=mask_lgt;else
1368
	mask.b= mask_lgt;
1369
	}else
1370
	if(shadow_msk== 4.0)
1371
	{
1372
	pos.x+=pos.y*3.0;
1373
	pos.x=frac(pos.x/6.0);
1374
	if(pos.x<0.3)mask.r=mask_lgt;else
1375
	if(pos.x<0.6)mask.g=mask_lgt;else
1376
	mask.b= mask_lgt;
1377
	}else
1378
	if(shadow_msk== 5.0)
1379
	{
1380
	pos.xy=floor(pos.xy*float2(1.0,0.5));
1381
	pos.x+=pos.y*3.0;
1382
	pos.x=frac(pos.x/6.0);
1383
	if(pos.x<0.3)mask.r=mask_lgt;else
1384
	if(pos.x<0.6)mask.g=mask_lgt;else
1385
	mask.b= mask_lgt;
1386
	}else
1387
	if(shadow_msk== 6.0)
1388
	{
1389
	mask=0.0;
1390
	pos.x=frac(pos.x/2.0);
1391
	if(pos.x<0.49)
1392
	{
1393
	mask.r=1.0;
1394
	mask.b=1.0;
1395
	}else
1396
	mask.g=1.0;
1397
	mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
1398
	}else
1399
	if(shadow_msk== 7.0)
1400
	{
1401
	mask=0.0;
1402
	pos.x=floor(mod(pos.x,3.0));
1403
	if(pos.x<0.5)mask.r=1.0;else
1404
	if(pos.x<1.5)mask.g=1.0;else
1405
	mask.b=1.0;
1406
	mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
1407
	}else
1408
	if(shadow_msk== 8.0)
1409
	{
1410
	mask=0.0;
1411
	pos.x=frac(pos.x/2.0);
1412
	if(pos.x<0.49)
1413
	{
1414
	mask=0.0.xxx;
1415
	}else
1416
	mask=1.0.xxx;
1417
	mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
1418
	}else
1419
	if(shadow_msk== 9.0)
1420
	{
1421
	mask=0.0;
1422
	pos.x=frac(pos.x/3.0);
1423
	if(pos.x<0.3)mask=0.0.xxx;else
1424
	if(pos.x<0.6)mask=1.0.xxx;else
1425
	mask=1.0.xxx;
1426
	mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
1427
	}else
1428
	if(shadow_msk==10.0)
1429
	{
1430
	mask=0.0;
1431
	pos.x=frac(pos.x/3.0);
1432
	if(pos.x<0.3)mask   =0.0.xxx;else
1433
	if(pos.x<0.6)mask.rb=1.0.xx ;else
1434
	mask.g=1.0;
1435
	mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
1436
	}else
1437
	if(shadow_msk==11.0)
1438
	{
1439
	mask=0.0;
1440
	pos.x=frac(pos.x*0.25);
1441
	if(pos.x<0.2)mask  =0.0.xxx;else
1442
	if(pos.x<0.4)mask.r=1.0    ;else
1443
	if(pos.x<0.7)mask.g=1.0    ;else
1444
	mask.b=1.0;
1445
	mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
1446
	}else
1447
	if(shadow_msk==12.0)
1448
	{
1449
	mask=0.0;
1450
	pos.x=frac(pos.x*0.25);
1451
	if(pos.x<0.2)mask.r =1.0   ;else
1452
	if(pos.x<0.4)mask.rg=1.0.xx;else
1453
	if(pos.x<0.7)mask.gb=1.0.xx;else
1454
	mask.b=1.0;mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
1455
	}else
1456
	if(shadow_msk==13.0)
1457
	{
1458
	mask=0.0;
1459
	pos.x=floor(mod(pos.x,7.0));
1460
	if(pos.x<0.5)mask  =0.0.xxx;else
1461
	if(pos.x<2.5)mask.r=1.0    ;else
1462
	if(pos.x<4.5)mask.g=1.0    ;else
1463
	mask.b=1.0;
1464
	mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
1465
	}else
1466
	{
1467
	mask=0.0;
1468
	pos.x=floor(mod(pos.x,6.0));
1469
	if(pos.x<0.5)mask    =0.0.xxx;else
1470
	if(pos.x<1.5)mask.r  =1.0    ;else
1471
	if(pos.x<2.5)mask.rg =1.0.xx ;else
1472
	if(pos.x<3.5)mask.rgb=1.0.xxx;else
1473
	if(pos.x<4.5)mask.gb =1.0.xx ;else
1474
	mask.b=1.0;
1475
	mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
1476
	}
1477
	if(mask_layout>0.5)mask=mask.rbg;
1478
	float maskmin=min(min(mask.r,mask.g),mask.b);
1479
	return (mask-maskmin)*(1.0+(maskboost-1.0)*mb)+maskmin;
1480
}
1481
1482
float slt_mask(float2 pos,float m,float swidth)
1483
{
1484
	if  ((slotmask1+slotmask2)==0.0)return 1.0;else
1485
	{
1486
	pos.y=floor(pos.y/slotms);
1487
	float mlen=swidth*2.0;
1488
	float px=floor( mod(pos.x, 0.99999*mlen));
1489
	float py=floor(frac(pos.y/(2.0*double_slot))*2.0*double_slot);
1490
	float slot_dark=lerp(1.0-slotmask2,1.0-slotmask1,m);
1491
	float slot=1.0;
1492
	if(py==0.0&&px<swidth) slot=slot_dark;else
1493
	if(py==double_slot&&px>=swidth) slot=slot_dark;
1494
	return slot;
1495
	}
1496
}
1497
1498
float humbars(float pos)
1499
{
1500
	if  (barintensity==0.0)return 1.0;else
1501
	{
1502
	pos=(barintensity>=0.0)?pos:(1.0-pos);
1503
	pos=frac(pos+ mod(float(framecount),barspeed)/(barspeed-1.0));
1504
	pos=(barintensity< 0.0)?pos:(1.0-pos);
1505
	return (1.0-barintensity)+barintensity*pos;
1506
	}
1507
}
1508
1509
float corner(float2 pos)
1510
{
1511
	pos=abs(2.0*(pos-0.50));
1512
	float2 aspect=float2(1.0,NewSize.x/NewSize.y);
1513
	float b=bsize*0.05+0.0005;pos.y=pos.y+b*(aspect.y-1.0);
1514
	float2 crn=max(csize.xx,2.0*b+0.0015);
1515
	float2 crp=max(pos-(1.0-crn*aspect),0.0)/aspect;float cd=sqrt(dot(crp,crp));
1516
	pos=max(pos,1.0-crn+cd);
1517
	float res=lerp(1.0,0.0,smoothstep(1.0-b,1.0,sqrt(max(pos.x,pos.y))));
1518
	return pow(res,sborder);
1519
}
1520
1521
float3 declip(float3 c,float b)
1522
{
1523
	float m=max(max(c.r,c.g),c.b);
1524
	if(m>b)c=c*b/m;
1525
	return c;
1526
}
1527
1528
float igc(float mc)
1529
{
1530
	return pow(mc,gamma_c);
1531
}
1532
1533
float3 gc2(float3 c,float w3)
1534
{
1535
	float mc=max(max(c.r,c.g),c.b);
1536
	float p=1.0/(1.0+(gamma_d-1.0)* lerp(0.375,1.0,w3));
1537
	float mg=pow(mc, p );
1538
	return c*mg/(mc+eps);
1539
}
1540
1541
float3 noise(float3 v)
1542
{
1543
	if(addnoised<0.0)v.z=-addnoised;else v.z= mod(v.z,6001.0)/1753.0;
1544
	v =frac(v)+frac(v*1e4)+frac(v*1e-4);
1545
	v+=float3(0.12345,0.6789,0.314159);
1546
	v =frac(v*dot(v,v)*123.456);
1547
	v =frac(v*dot(v,v)*123.456);
1548
	v =frac(v*dot(v,v)*123.456);
1549
	v =frac(v*dot(v,v)*123.456);
1550
	return v;
1551
}
1552
1553
void bring_pixel(inout float3 c,inout float3 b,inout float3 g,float2 coord,float2 boord)
1554
{
1555
	float stepx=NewSize.z;
1556
	float stepy=NewSize.w;
1557
	float2 dx=float2(stepx,0.0);
1558
	float2 dy=float2(0.0,stepy);
1559
	float posx= 2.0*coord.x-1.0;
1560
	float posy= 2.0*coord.y-1.0;
1561
	if(dctypex>0.025)
1562
	{
1563
	posx= sign(posx)*pow(abs(posx),1.05-dctypex);
1564
	dx=posx*dx;
1565
	}
1566
	if(dctypey>0.025)
1567
	{
1568
	posy= sign(posy)*pow(abs(posy),1.05-dctypey);
1569
	dy=posy*dy;
1570
	}
1571
	float2 rc=deconrx*dx+deconry*dy;
1572
	float2 gc=decongx*dx+decongy*dy;
1573
	float2 bc=deconbx*dx+deconby*dy;
1574
	float r1=texCD(NTSC_S13,coord+rc).r;
1575
	float g1=texCD(NTSC_S13,coord+gc).g;
1576
	float b1=texCD(NTSC_S13,coord+bc).b;
1577
	float ds=decons;
1578
	float3 d=float3(r1,g1,b1);
1579
	c=clamp(lerp(c,d,ds),0.0,1.0);
1580
	r1=texCD(NTSC_S12,boord+rc).r;
1581
	g1=texCD(NTSC_S12,boord+gc).g;
1582
	b1=texCD(NTSC_S12,boord+bc).b;
1583
	d=float3(r1,g1,b1);
1584
	b=g=lerp(b,d,min(ds,1.0));
1585
	r1=texCD(NTSC_S10,boord+rc).r;
1586
	g1=texCD(NTSC_S10,boord+gc).g;
1587
	b1=texCD(NTSC_S10,boord+bc).b;
1588
	d=float3(r1,g1,b1);
1589
	g=lerp(g,d,min(ds,1.0));
1590
}
1591
1592
static const float2 expanse=BoxSize/ (2*OptSize.xy);
1593
static const float2 capital=0.0/OptSize.xy+0.5;
1594
static const float coord_w=capital.x-expanse.x;
1595
static const float coord_e=capital.x+expanse.x;
1596
static const float coord_n=capital.y-expanse.y;
1597
static const float coord_s=capital.y+expanse.y;
1598
static const float2 correct=float2(coord_w,coord_n);
1599
1600
void CropProcessVS(in uint id:SV_VertexID,out float4 position:SV_Position,out float2 texcoord:TEXCOORD)
1601
{
1602
	#if __RENDERER__ <= 0x09300
1603
	texcoord.x=(id==1||id==3)?coord_e:coord_w;
1604
	texcoord.y=(id>1)?coord_s:coord_n;
1605
	position.x=(id==1||id==3)? 1:-1;
1606
	position.y=(id>1)?-1: 1;
1607
	position.zw=1;
1608
	#else
1609
	texcoord.x=(id&1)?coord_e:coord_w;
1610
	texcoord.y=(id&2)?coord_s:coord_n;
1611
	position.x=(id&1)? 1:-1;
1612
	position.y=(id&2)?-1: 1;
1613
	position.zw=1;
1614
	#endif
1615
}
1616
1617
float4 StockPassPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
1618
{
1619
	return texCD(NTSC_S00,texcoord);
1620
}
1621
1622
float4 Signal_1_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
1623
{
1624
	float pix_res= min(ntsc_scale,1.0);
1625
	float phase= (ntsc_phase<1.5)?((OrgSize.x>300.0)? 2.0:3.0):((ntsc_phase>2.5)?3.0:2.0);
1626
	if(ntsc_phase==4.0)phase=3.0;
1627
	float res=ntsc_scale;
1628
	float CHROMA_MOD_FREQ=(phase<2.5)?(4.0*pii/15.0):(pii/3.0);
1629
	float ARTIFACT=cust_artifacting;
1630
	float FRINGING=cust_fringing;
1631
	float BRIGHTNESS=ntsc_brt;
1632
	float SATURATION=ntsc_sat;
1633
	float MERGE=0.0;
1634
	if(ntsc_fields== 1.0&&phase==3.0) MERGE=1.0;else
1635
	if(ntsc_fields== 2.0) MERGE=0.0;else
1636
	if(ntsc_fields== 3.0) MERGE=1.0;
1637
	float2 pix_no=texcoord*OrgSize.xy*pix_res* float2(4.0,1.0);
1638
	float3 col0=texCD(NTSC_S01, texcoord).rgb;
1639
	float3 yiq1=rgb2yiq(col0);
1640
	yiq1.x=pow(yiq1.x,ntsc_gamma); float lum=yiq1.x;
1641
	float2 dx=float2(OrgSize.z,0.0);
1642
	float c1=get_luma(texCD(NTSC_S01,texcoord-dx).rgb);
1643
	float c2=get_luma(texCD(NTSC_S01,texcoord+dx).rgb);
1644
	if(ntsc_phase==4.0)
1645
	{
1646
	float miix=min(5.0*abs(c1-c2),1.0);
1647
	c1=pow(c1,ntsc_gamma);
1648
	c2=pow(c2,ntsc_gamma);
1649
	yiq1.x=lerp(min(0.5*(yiq1.x+max(c1,c2)),max(yiq1.x,min(c1,c2))),yiq1.x,miix);
1650
	}
1651
	float3 yiq2=yiq1;
1652
	float3 yiqs=yiq1;
1653
	float3 yiqz=yiq1;
1654
	float3 temp=yiq1;
1655
	float mit=ntsc_taps;if(ntsc_charp1>0.25&&phase==2.0)mit=clamp(mit,8.0,min(ntsc_taps,14.0));
1656
	mit=swoothstep(16.0,8.0,mit)*0.325;
1657
	if(MERGE>0.5)
1658
	{
1659
	float chroma_phase2=(phase<2.5)?pii*(mod(pix_no.y,2.0)+mod(float(framecount)+1,2.)):0.6667*pii*(mod(pix_no.y,3.0)+mod(float(framecount)+1,2.));
1660
	float mod_phase2=chroma_phase2+pix_no.x*CHROMA_MOD_FREQ;
1661
	float i_mod2=cos( mod_phase2 );
1662
	float q_mod2=sin( mod_phase2 );
1663
	yiq2.yz*=float2(i_mod2,q_mod2);
1664
	yiq2=mul(mix_m,yiq2);
1665
	yiq2.yz*=float2(i_mod2,q_mod2);
1666
	yiq2.yz =lerp(yiq2.yz,temp.yz,mit);
1667
	if(res>1.025)
1668
	{
1669
	mod_phase2=chroma_phase2 +res *pix_no.x*CHROMA_MOD_FREQ;
1670
	i_mod2=cos(mod_phase2);
1671
	q_mod2=sin(mod_phase2);
1672
	yiqs.yz*=float2(i_mod2,q_mod2);
1673
	yiq2.x=dot(yiqs,mix_m[0]);
1674
	}
1675
	}
1676
	float chroma_phase1=(phase<2.5)?pii*(mod(pix_no.y,2.0)+mod(float(framecount)  ,2.)):0.6667*pii*(mod(pix_no.y,3.0)+mod(float(framecount)  ,2.));
1677
	float mod_phase1=chroma_phase1+pix_no.x*CHROMA_MOD_FREQ;
1678
	float i_mod1=cos( mod_phase1 );
1679
	float q_mod1=sin( mod_phase1 );
1680
	yiq1.yz*=float2(i_mod1,q_mod1);
1681
	yiq1=mul(mix_m,yiq1);
1682
	yiq1.yz*=float2(i_mod1,q_mod1);
1683
	yiq1.yz =lerp(yiq1.yz,temp.yz,mit);
1684
	if(res>1.025)
1685
	{
1686
	mod_phase1=chroma_phase1 +res *pix_no.x*CHROMA_MOD_FREQ;
1687
	i_mod1=cos(mod_phase1);
1688
	q_mod1=sin(mod_phase1);
1689
	yiqz.yz*=float2(i_mod1,q_mod1);
1690
	yiq1.x=dot(yiqz,mix_m[0]);
1691
	}
1692
	if(ntsc_phase==4.0){yiq1.x=lum;yiq2.x=lum;}
1693
	if(MERGE>0.5){if(ntsc_rainbow<0.5||phase>2.5)yiq1=0.5*(yiq1+yiq2); else yiq1.x=0.5*(yiq1.x+yiq2.x);}
1694
	return float4(yiq1,lum);
1695
}
1696
1697
float4 Signal_2_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
1698
{
1699
	float chroma_filter_2_phase[33]={
1700
    0.001384762, 0.001678312, 0.002021715, 0.002420562, 0.002880460, 0.003406879, 0.004004985, 0.004679445, 0.005434218, 0.006272332, 0.007195654,
1701
    0.008204665, 0.009298238, 0.010473450, 0.011725413, 0.013047155, 0.014429548, 0.015861306, 0.017329037, 0.018817382, 0.020309220, 0.021785952,
1702
    0.023227857, 0.024614500, 0.025925203, 0.027139546, 0.028237893, 0.029201910, 0.030015081, 0.030663170, 0.031134640, 0.031420995, 0.031517031};
1703
	float chroma_filter_3_phase[25]={
1704
   -0.000118847,-0.000271306,-0.000502642,-0.000930833,-0.001451013,
1705
   -0.002064744,-0.002700432,-0.003241276,-0.003524948,-0.003350284,
1706
   -0.002491729,-0.000721149, 0.002164659, 0.006313635, 0.011789103,
1707
    0.018545660, 0.026414396, 0.035100710, 0.044196567, 0.053207202,
1708
    0.061590275, 0.068803602, 0.074356193, 0.077856564, 0.079052396};
1709
	float luma_filter_2_phase[33]={
1710
   -0.000174844,-0.000205844,-0.000149453,-0.000051693, 0.000000000,-0.000066171,-0.000245058,-0.000432928,-0.000472644,-0.000252236, 0.000198929,
1711
    0.000687058, 0.000944112, 0.000803467, 0.000363199, 0.000013422, 0.000253402, 0.001339461, 0.002932972, 0.003983485, 0.003026683,-0.001102056,
1712
   -0.008373026,-0.016897700,-0.022914480,-0.021642347,-0.028863273, 0.027271957, 0.054921920, 0.098342579, 0.139044281, 0.168055832, 0.178571429};
1713
	float luma_filter_3_phase[25]={
1714
   -0.000012020,-0.000022146,-0.000013155,-0.000012020,-0.000049979,
1715
   -0.000113940,-0.000122150,-0.000005612, 0.000170516, 0.000237199,
1716
    0.000169640, 0.000285688, 0.000984574, 0.002018683, 0.002002275,
1717
   -0.005909882,-0.012049081,-0.018222860,-0.022606931, 0.002460860,
1718
    0.035868225, 0.084016453, 0.135563500, 0.175261268, 0.220176552};
1719
	float luma_filter_4_phase[25]={
1720
   -0.000472644,-0.000252236, 0.000198929, 0.000687058, 0.000944112,
1721
    0.000803467, 0.000363199, 0.000013422, 0.000253402, 0.001339461,
1722
    0.002932972, 0.003983485, 0.003026683,-0.001102056,-0.008373026,
1723
   -0.016897700,-0.022914480,-0.021642347,-0.028863273, 0.027271957,
1724
    0.054921920, 0.098342579, 0.139044281, 0.168055832, 0.178571429};
1725
	const int TAPS_2_phase=32;
1726
	const int TAPS_3_phase=24;
1727
	float res=ntsc_scale;
1728
	float3 signal=0.0;
1729
	float2 one=0.25*OrgSize.zz/res;
1730
	float2 tex_c=texcoord+float2(0.5*OrgSize.z/4.0,0.0);
1731
	float phase= ( ntsc_phase<1.5)?((OrgSize.x>300.0)?2.0:3.0):((ntsc_phase>2.5)?3.0:2.0);
1732
	if(ntsc_phase==4.0){phase=3.0;luma_filter_3_phase=luma_filter_4_phase;}
1733
	float3 wsum =0.0.xxx;
1734
	float3 sums=wsum;
1735
	float3 tmps=wsum;
1736
	float offset=0.0;int i=0;
1737
	float j =0.0;
1738
	if(phase<2.5)
1739
	{
1740
	float loop=max(ntsc_taps,8.0);
1741
	if(ntsc_charp1>0.25)loop=min(loop,14.0);
1742
	float loob=loop+1.0;
1743
	float taps=0.0;
1744
	float ssub=loop-loop/ntsc_cscale1;
1745
	float mit=1.0+0.0375*pow(swoothstep(16.0,8.0,loop),0.5);
1746
	float2 dx=float2(one.x*mit,0.0);
1747
	float2 xd=dx; int loopstart=int(TAPS_2_phase-loop);
1748
	for(i=loopstart;i<32;i++)
1749
	{
1750
	offset=float(i-loopstart);
1751
	j=offset+1.0;xd= (offset-loop)*dx;
1752
	sums=fetch_offset1(xd);
1753
	taps=max(j-ssub,0.0);
1754
	tmps=float3(luma_filter_2_phase[i], taps.xx );
1755
	wsum=wsum+tmps; signal+=sums*tmps;
1756
	}
1757
	taps=loob-ssub;
1758
	tmps=float3(luma_filter_2_phase[TAPS_2_phase], taps.xx);
1759
	wsum=wsum+wsum+tmps;
1760
	signal+=texCD(NTSC_S02,tex_c).xyz*tmps;
1761
	signal =signal/wsum;
1762
	}else
1763
	{
1764
	float loop=min(ntsc_taps,TAPS_3_phase); one.y=one.y/ntsc_cscale2;
1765
	float mit=1.0;
1766
	if(ntsc_phase==4.0){loop=max(loop,8.0); mit=1.0+0.0375*pow(swoothstep(16.0,8.0,loop),0.5);}
1767
	float3 dx=float3(one.x,one.y,0.0);
1768
	float3 xd=dx; int loopstart=int(TAPS_3_phase-loop);
1769
	dx.x*=mit;
1770
	for(i=loopstart;i<24;i++)
1771
	{
1772
	offset=float(i-loopstart);
1773
	j=offset+1.0;xd.xy=(offset-loop)*dx.xy;
1774
	sums=fetch_offset2(xd);
1775
	tmps=float3(luma_filter_3_phase[i], chroma_filter_3_phase[i].xx);
1776
	wsum=wsum+tmps; signal+=sums*tmps;
1777
	}
1778
	tmps=float3(luma_filter_3_phase[TAPS_3_phase], chroma_filter_3_phase[TAPS_3_phase], chroma_filter_3_phase[TAPS_3_phase]);
1779
	wsum=wsum+wsum+tmps;
1780
	signal+=texCD(NTSC_S02,tex_c).xyz*tmps;
1781
	signal =signal/wsum;
1782
	}
1783
	signal.x=clamp( signal.x,0.0,1.0);
1784
	if(ntsc_ring>0.05)
1785
	{
1786
	float2 dx=float2(OrgSize.z/min(res,1.0),0.0);
1787
	float a=texCD(NTSC_S02,tex_c-2.0*dx).a;
1788
	float b=texCD(NTSC_S02,tex_c-    dx).a;
1789
	float c=texCD(NTSC_S02,tex_c+2.0*dx).a;
1790
	float d=texCD(NTSC_S02,tex_c+    dx).a;
1791
	float e=texCD(NTSC_S02,tex_c       ).a;
1792
	signal.x=lerp(signal.x,clamp(signal.x,min(min(min(a,b),min(c,d)),e),max(max(max(a,b),max(c,d)),e)),ntsc_ring);
1793
	}
1794
	float x=get_luma(texCD(NTSC_S01, tex_c).rgb);
1795
	return float4(signal,x);
1796
}
1797
1798
float4 Signal_3_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
1799
{
1800
	float2 dx=float2(0.25*OrgSize.z/4.0,0.0);
1801
	float2 xx=float2(0.50*OrgSize.z,0.0);
1802
	float2 tex_c=texcoord+float2(0.5*OrgSize.z/4.0,0.0);float2 tcoord=tex_c-2.0*dx;
1803
	float2 tcoorb=(floor(OrgSize.xy*tex_c)+0.5)*OrgSize.zw;
1804
	float lcoord=OrgSize.x*(tex_c.x+dx.x )-0.5;
1805
	float fpx=frac(lcoord);
1806
	lcoord =(floor(lcoord)+0.5)*OrgSize.z;
1807
	float3 ll1=texCD(NTSC_S03,tcoord+ xx).xyz;
1808
	float3 ll2=texCD(NTSC_S03,tcoord- xx).xyz;
1809
	float dy=0.0;
1810
	xx=float2(OrgSize.z,0.0);
1811
	float phase= (ntsc_phase<1.5)?((OrgSize.x>300.0)? 2.0:3.0):((ntsc_phase>2.5)?3.0:2.0);
1812
	if(ntsc_phase==4.0)phase=3.0;
1813
	float ca=texCD(NTSC_S02,tcoorb-xx-xx).a;
1814
	float c0=texCD(NTSC_S02,tcoorb-xx   ).a;
1815
	float c1=texCD(NTSC_S02,tcoorb      ).a;
1816
	float c2=texCD(NTSC_S02,tcoorb+xx   ).a;
1817
	float cb=texCD(NTSC_S02,tcoorb+xx+xx).a;
1818
	float th=(phase<2.5)?0.025:0.0075;
1819
	float line0=    swoothstep(th,0.0,min(abs(c1-c0),abs(c2-c1)));
1820
	float line1=max(swoothstep(th,0.0,min(abs(ca-c0),abs(c2-cb))), line0 );
1821
	float line2=max(swoothstep(th,0.0,min(abs(ca-c2),abs(c0-cb))), line1 );
1822
	if( ntsc_rainbow>0.5&&phase<2.5)
1823
	{
1824
	float ybool1=1.0;bool ybool2=(c0==c1&&c1==c2);
1825
	if((ntsc_rainbow<1.5)&&bool(line0))ybool1=0.0;else
1826
	if((ntsc_rainbow<2.5)&&bool(line2))ybool1=0.0;else
1827
	if(ybool2)ybool1=0.0;
1828
	float liine_no=floor( mod(OrgSize.y*tex_c.y,2.0));
1829
	float frame_no=floor( mod(float(framecount),2.0));
1830
	float ii=abs(liine_no-frame_no);
1831
	dy=ii*OrgSize.w*ybool1;
1832
	}
1833
	float3 ref=texCD(NTSC_S03,tcoord).xyz;
1834
	float2 org=ref.yz;
1835
	ref.yz= texCD(NTSC_S03,tcoord+float2(0.0,dy)).yz;
1836
	float lum1=min(texCD(NTSC_S02,tex_c-dx).a, texCD(NTSC_S02,tex_c+dx).a);
1837
	float lum2=ref.x ;
1838
	float3 ll3=abs(ll1-ll2);
1839
	float di=max(max(ll3.x,ll3.y),max(ll3.z,abs(ll1.x*ll1.x-ll2.x*ll2.x)));
1840
	float df=pow(di,0.125);
1841
	float lc=swoothstep(0.20,0.10,abs(lum2-lum1))*df;
1842
	float tmp1=swoothstep(0.05-0.03*lc,0.425-0.375*lc,di);
1843
	float tmp2=pow((tmp1+0.1)/1.1,0.25);
1844
	float sweight=lerp(tmp1,tmp2,line0);
1845
	float zweight=lerp(tmp1,tmp2,line2);
1846
	float3 signal=ref;
1847
	float ntzc_shrp= abs(ntsc_shrp);
1848
	if(ntzc_shrp>0.25)
1849
	{
1850
	float mixer=sweight;
1851
	if(ntsc_shrp>0.25)mixer=zweight; mixer*=0.1*ntzc_shrp;
1852
	float lumix=lerp(lum2,lum1,mixer);
1853
	float lm1=lerp(lum2*lum2 ,lum1*lum1 ,mixer);lm1=sqrt(lm1);
1854
	float lm2=lerp(sqrt(lum2),sqrt(lum1),mixer);lm2=lm2* lm2 ;
1855
	float k1=abs(lumix-lm1)+0.00001;
1856
	float k2=abs(lumix-lm2)+0.00001;
1857
	signal.x=min((k2*lm1+k1*lm2)/(k1+k2),1.0);
1858
	signal.x=min(signal.x,max(ntsc_shpe*signal.x,lum2));
1859
	}
1860
	if((ntsc_charp1+ntsc_charp2)>0.25)
1861
	{
1862
	float mixer=sweight;
1863
	if(ntsc_shrp>0.25)mixer=zweight;
1864
	mixer =lerp(swoothstep(0.075,0.125,max(ll3.y,ll3.z)),swoothstep(0.015,0.0275,di),line2)*mixer;
1865
	mixer*=0.1*((phase<2.5)? ntsc_charp1:ntsc_charp2);
1866
	tcoord=float2(lcoord,tcoord.y);
1867
	float3 origin=rgb2yiq(lerp(texCD(NTSC_S01,tcoord).rgb,texCD(NTSC_S01,tcoord+xx).rgb,clamp(1.5*fpx-0.25,0.0,1.0)));
1868
	signal.yz=lerp(signal.yz,origin.yz,mixer);
1869
	}
1870
	if(ntsc_rainbow==2.0&&phase<2.5){signal.yz=lerp(signal.yz,org,zweight);}
1871
	signal.x=pow(signal.x,1.0/ntsc_gamma);
1872
	signal=clamp(yiq2rgb(signal),0.0,1.0);
1873
	return float4(signal,1.0);
1874
}
1875
1876
float4 SharpnessPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
1877
{
1878
	float2 g01=float2(-0.5*OrgSize.z,0.0);
1879
	float2 g21=float2( 0.5*OrgSize.z,0.0);
1880
	float3 c01=texCD(NTSC_S04,texcoord+g01).rgb;
1881
	float3 c21=texCD(NTSC_S04,texcoord+g21).rgb;
1882
	float3 c11=texCD(NTSC_S04,texcoord    ).rgb;
1883
	float3 b11=0.5*(c01+c21);
1884
	float contrazt=max(max(c11.r,c11.g),c11.b);
1885
	contrazt=lerp(2.0*CCONTR,CCONTR,contrazt);
1886
	float3 nim=min(min(c01,c21),c11);float3 mn1=min(nim,c11*(1.0-contrazt));
1887
	float3 xam=max(max(c01,c21),c11);float3 mx1=max(xam,c11*(1.0+contrazt));
1888
	float3 di0=pow(mx1-mn1+0.00001,0.75);
1889
	float3 sharpen=lerp(CSHARPEN*CDETAILS,CSHARPEN,di0);
1890
	float3 res=clamp(lerp(c11,b11,-sharpen),mn1,mx1);
1891
	if(DEBLUR>1.125)
1892
	{
1893
	float2 toxcoord=(floor(OrgSize.xy*texcoord)+0.5)*OrgSize.zw;
1894
	float l01=get_luma(texCD(NTSC_S01,texcoord+2.0*g01).rgb);
1895
	float l21=get_luma(texCD(NTSC_S01,texcoord+2.0*g21).rgb);
1896
	float l11=get_luma(texCD(NTSC_S01,toxcoord        ).rgb);
1897
	float d11=min(min(l01,l21),l11);
1898
	l11=max(max(l01,l21),l11);
1899
	float lmn=min(min(get_luma(c01),get_luma(c21)),get_luma(c11));float ln1=min(lerp(d11,lmn,lmn),lmn);
1900
	float lmx=max(max(get_luma(c01),get_luma(c21)),get_luma(c11));float lx1=max(lerp(lmx,l11,lmx),lmx);
1901
	float r11=get_luma(res);
1902
	float di1=max((r11-ln1),0.0)+0.00001;di1=pow(di1,DEBLUR);
1903
	float di2=max((lx1-r11),0.0)+0.00001;di2=pow(di2,DEBLUR);
1904
	float ratio=di1/(di1+di2);
1905
	float zharpen=lerp(ln1,lx1,ratio);
1906
	zharpen=min(zharpen,max(DREDGE*zharpen,r11));
1907
	res=rgb2yiq(res);
1908
	d11=res.x;
1909
	res.x=zharpen;
1910
	res.x=clamp((1.0+ DSHARP)* res.x-DSHARP*d11,ln1*(1.0-contrazt),lx1*(1.0+contrazt));
1911
	res=max(yiq2rgb(res),0.0);
1912
	}
1913
	return float4(res,1.0);
1914
}
1915
1916
float4 LuminancePS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
1917
{
1918
	float m=max(log2(LumSize.x),log2(LumSize.y));
1919
	m=floor(max(m,1.0))-1.0;
1920
	float2 dx=float2(1.0/LumSize.x,0.0);
1921
	float2 dy=float2(0.0,1.0/LumSize.y);
1922
	float2 x2=2.0*dx;
1923
	float2 y2=2.0*dy;
1924
	float ltotal=0.0;
1925
	ltotal+=length(tex2Dlod(NTSC_S05,float4(float2(0.3,0.3),m,0)).rgb);
1926
	ltotal+=length(tex2Dlod(NTSC_S05,float4(float2(0.3,0.7),m,0)).rgb);
1927
	ltotal+=length(tex2Dlod(NTSC_S05,float4(float2(0.7,0.3),m,0)).rgb);
1928
	ltotal+=length(tex2Dlod(NTSC_S05,float4(float2(0.7,0.7),m,0)).rgb);
1929
	ltotal*=0.25;
1930
	ltotal=pow(0.577350269*ltotal,0.7);
1931
	float lhistory=texCD(NTSC_S06,float2(0.5,0.5)).a;
1932
	ltotal=lerp(ltotal,lhistory,lsmooth);
1933
	float3 l1=texCD(NTSC_S05,fuxcoord.xy   ).rgb;
1934
	float3 r1=texCD(NTSC_S05,fuxcoord.xy+dx).rgb;
1935
	float3 l2=texCD(NTSC_S05,fuxcoord.xy-dx).rgb;
1936
	float3 r2=texCD(NTSC_S05,fuxcoord.xy+x2).rgb;
1937
	float c1=dist(l2,l1);
1938
	float c2=dist(l1,r1);
1939
	float c3=dist(r2,r1);
1940
	return float4(c1,c2,c3,ltotal);
1941
}
1942
1943
float4 LinearizePS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
1944
{
1945
	float3 c1=texCD(NTSC_S05,fuxcoord).rgb;
1946
	float3 c2=texCD(NTSC_S05,fuxcoord+float2(0.0,OrgSize.w)).rgb;
1947
	if((downsample_levelx+downsample_levely)>0.025)
1948
	{
1949
	c1=fetch_pixel(fuxcoord);
1950
	c2=fetch_pixel(fuxcoord+float2(0.0,OrgSize.w));
1951
	}
1952
	float3 c=c1;
1953
	float intera=1.0;
1954
	float gamma_in=gamma_i;
1955
	float m1=max(max(c1.r,c1.g),c1.b);
1956
	float m2=max(max(c2.r,c2.g),c2.b);
1957
	float3 df=abs(c1-c2);
1958
	float d=max(max(df.r,df.g),df.b);
1959
	if(interm==2.0) d=lerp(0.1*d,10.0*d,step(m1/(m2+0.0001),m2/(m1+0.0001)));
1960
	float r=m1;
1961
	float yres_div=1.0;if(intres>1.25)yres_div=intres;
1962
	bool hscans=(hiscan>0.5);
1963
	if(interr<=OrgSize.y/yres_div&&interm>0.5&&intres!=1.0&&intres!=0.5||hscans)
1964
	{
1965
	intera=0.25;
1966
	float liine_no=floor( mod(OrgSize.y*fuxcoord.y,2.0));
1967
	float frame_no=floor( mod(float(framecount),2.0));
1968
	float ii=abs(liine_no-frame_no);
1969
	if(interm< 3.5)
1970
	{
1971
	c2=plant(lerp(c2,c2*c2,iscans),max(max(c2.r,c2.g),c2.b));
1972
	r=max(m1*ii,(1.0-iscanb)*min(m1,m2));
1973
	c=plant(lerp(lerp(c1,c2,min(lerp(m1,1.0-m2,min(m1,1.0-m1))/(d+0.00001),1.0)),c1,ii),r);
1974
	if(interm==3.0) c=(1.0-0.5*iscanb)*lerp(c2,c1,ii);
1975
	}
1976
	if(interm==4.0){c=plant(lerp(c,c*c,0.5*iscans),max(max(c.r,c.g),c.b))*(1.0-0.5*iscanb);
1977
	}
1978
	if(interm==5.0){c=lerp(c2,c1,0.5);c=plant(lerp(c,c*c,0.5*iscans),max(max(c.r,c.g),c.b))*(1.0-0.5*iscanb);
1979
	}
1980
	if(hscans)c=c1;
1981
	}
1982
	c=pow(c,gamma_in);
1983
	if(fuxcoord.x>0.5)gamma_in=intera;else gamma_in=1.0/gamma_in;
1984
	return float4(c,gamma_in);
1985
}
1986
1987
float4 HGaussianPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
1988
{
1989
	float FINE_GAUSS= (FINE_GAUSS>0.5)? FINE_GAUSS: lerp(0.75,0.50,-FINE_GAUSS);
1990
	float4 AdvSize=float4(OrgSize.x,OrgSize.y,OrgSize.z,OrgSize.w)*float4(FINE_GAUSS,FINE_GAUSS,1.0/FINE_GAUSS,1.0/FINE_GAUSS);
1991
	float f=frac(AdvSize.x*texcoord.x);
1992
	f=0.5-f;
1993
	float2 tex=floor(AdvSize.xy*texcoord)*AdvSize.zw+0.5*AdvSize.zw;
1994
	float3 color=0.0;
1995
	float2 dx=float2(AdvSize.z ,0.0);
1996
	float3 pixel;
1997
	float w;
1998
	float wsum=0.0;
1999
	float n=-SIZEH;
2000
	do
2001
	{
2002
	pixel=texCD(NTSC_S07,tex+n*dx).rgb;
2003
	if(m_glow>0.5)
2004
	{
2005
	pixel=max(pixel-m_glow_cutoff,0.0);
2006
	pixel=plant(pixel,max(max(max(pixel.r,pixel.g),pixel.b)-m_glow_cutoff,0.0));
2007
	}
2008
	w=gauss_h(n+f);
2009
	color=color+w*pixel;
2010
	wsum=wsum+w;
2011
	n=n+1.0;
2012
	}
2013
	while(n<=SIZEH);
2014
	color=color/wsum;
2015
	return float4(color,1.0);
2016
}
2017
2018
float4 VGaussianPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
2019
{
2020
	float FINE_GAUSS= (FINE_GAUSS>0.5)? FINE_GAUSS: lerp(0.75,0.50,-FINE_GAUSS);
2021
	float4 AdvSize=float4(SrcSize.x,OrgSize.y,SrcSize.z,OrgSize.w)*float4(FINE_GAUSS,FINE_GAUSS,1.0/FINE_GAUSS,1.0/FINE_GAUSS);
2022
	float f=frac(AdvSize.y*texcoord.y);
2023
	f=0.5-f;
2024
	float2 tex=floor(AdvSize.xy*texcoord)*AdvSize.zw+0.5*AdvSize.zw;
2025
	float3 color=0.0;
2026
	float2 dy=float2(0.0,AdvSize.w );
2027
	float3 pixel;
2028
	float w;
2029
	float wsum=0.0;
2030
	float n=-SIZEV;
2031
	do
2032
	{
2033
	pixel=texCD(NTSC_S09,tex+n*dy).rgb;
2034
	w=gauss_v(n+f);
2035
	color=color+w*pixel;
2036
	wsum=wsum+w;
2037
	n=n+1.0;
2038
	}
2039
	while(n<=SIZEV);
2040
	color=color/wsum;
2041
	return float4(color,1.0);
2042
}
2043
2044
float4 BloomHorzPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
2045
{
2046
	float FINE_BLOOM= (FINE_BLOOM>0.5)? FINE_BLOOM: lerp(0.75,0.50,-FINE_BLOOM);
2047
	float4 AdvSize=float4(OrgSize.x,OrgSize.y,OrgSize.z,OrgSize.w)*float4(FINE_BLOOM,FINE_BLOOM,1.0/FINE_BLOOM,1.0/FINE_BLOOM);
2048
	float f=frac(AdvSize.x*texcoord.x);
2049
	f=0.5-f;
2050
	float2 tex=floor(AdvSize.xy*texcoord)*AdvSize.zw+0.5*AdvSize.zw;
2051
	float4 color=0.0;
2052
	float2 dx=float2(AdvSize.z ,0.0);
2053
	float4 pixel;
2054
	float w;
2055
	float wsum=0.0;
2056
	float n=-SIZEX;
2057
	do
2058
	{
2059
	pixel=texCD(NTSC_S07,tex+n*dx);
2060
	w=bloom_h(n+f);
2061
	pixel.a =max(max(pixel.r,pixel.g),pixel.b);
2062
	pixel.a*=pixel.a*pixel.a;
2063
	color=color+w*pixel;
2064
	wsum=wsum+w;
2065
	n=n+1.0;
2066
	}
2067
	while(n<=SIZEX);
2068
	color=color/wsum;
2069
	return float4(color.rgb,pow(color.a,0.333333));
2070
}
2071
2072
float4 BloomVertPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
2073
{
2074
	float FINE_BLOOM= (FINE_BLOOM>0.5)? FINE_BLOOM: lerp(0.75,0.50,-FINE_BLOOM);
2075
	float4 AdvSize=float4(SrcSize.x,OrgSize.y,SrcSize.z,OrgSize.w)*float4(FINE_BLOOM,FINE_BLOOM,1.0/FINE_BLOOM,1.0/FINE_BLOOM);
2076
	float f=frac(AdvSize.y*texcoord.y);
2077
	f=0.5-f;
2078
	float2 tex=floor(AdvSize.xy*texcoord)*AdvSize.zw+0.5*AdvSize.zw;
2079
	float4 color=0.0;
2080
	float2 dy=float2(0.0,AdvSize.w );
2081
	float4 pixel;
2082
	float w;
2083
	float wsum=0.0;
2084
	float n=-SIZEY;
2085
	do
2086
	{
2087
	pixel=texCD(NTSC_S11,tex+n*dy);
2088
	w=bloom_v(n+f);
2089
	pixel.a*=pixel.a*pixel.a;
2090
	color=color+w*pixel;
2091
	wsum=wsum+w;
2092
	n=n+1.0;
2093
	}
2094
	while(n<=SIZEY);
2095
	color=color/wsum;
2096
	return float4(color.rgb,pow(color.a,0.175000));
2097
}
2098
2099
float4 NTSC_TV1_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
2100
{
2101
	float f=frac(LumSize.x*fuxcoord.x);
2102
	f=0.5-f;
2103
	float2 tex=floor(LumSize.xy*fuxcoord)*LumSize.zw+0.5*LumSize.zw;
2104
	float3 color=0.0.xxx;
2105
	float solor=0.0;
2106
	float2 dx=float2(LumSize.z ,0.0);
2107
	float3 pixel;
2108
	float w=0.0;
2109
	float swum=0.0;
2110
	float wsum=0.0;
2111
	float xs=2.0*0.50;
2112
	float hsharpness=HSHARPNESS*xs*internal_res;
2113
	float3 cmax=0.0.xxx;
2114
	float3 cmin=1.0.xxx;
2115
	float sharp=crthd_h(hsharpness,xs) *S_SHARP;
2116
	float maxsharp=MAXS;
2117
	float FPR=hsharpness;
2118
	float FPRi=1.0/hsharpness;
2119
	float fpx=0.0;
2120
	float sp=0.0;
2121
	float sw=0.0;
2122
	float ts=0.025;
2123
	float3 luma=float3(0.2126,0.7152,0.0722);
2124
	float LOOPSIZE=ceil(2.0*FPR);
2125
	float n=-LOOPSIZE;
2126
	do
2127
	{
2128
	pixel=texCD(NTSC_S07,tex+n*dx).rgb;
2129
	w=crthd_h(n+f,xs)-sharp;
2130
	fpx=(abs(n+f)-FPR)*FPRi;
2131
	if(w<0.0)w=max(w,lerp(-maxsharp,0.0,pow(clamp(fpx,0.0,1.0),SHARP))); else
2132
	{
2133
	cmax=max(cmax,pixel);cmin=min(cmin,pixel);sw=w*(dot(pixel,luma)+ts);
2134
	sp=max(max(pixel.r,pixel.g),pixel.b);
2135
	solor=solor+sw*sp;
2136
	swum=swum+sw;
2137
	}
2138
	color=color+w*pixel;
2139
	wsum=wsum+w;
2140
	n=n+1.0;
2141
	}
2142
	while(n<=LOOPSIZE);
2143
	color=color/wsum;
2144
	solor=solor/swum;
2145
	color=clamp(lerp( clamp (color,cmin,cmax),color,SSRNG),0.0,1.0);
2146
	solor=clamp(lerp(max(max(color.r,color.g),color.b),solor,spike),0.0,1.0);
2147
	return float4(color,solor);
2148
}
2149
2150
float4 NTSC_TV2_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
2151
{
2152
	float gamma_in=1.0/texCD(NTSC_S07,float2(0.25,0.25)).a;
2153
	float lum=texCD(NTSC_S06,float2(0.5,0.5)).a;
2154
	float intera=texCD(NTSC_S07,float2(0.75,0.25)).a;
2155
	bool hscans=(hiscan>0.5);
2156
	bool interb=(((intera<0.35)||(no_scanlines>0.025))&&!hscans);
2157
	float4 AdvSize= LumSize;
2158
	float SourceY=AdvSize.y;
2159
	float sy=1.0;
2160
	if( intres==1.0)sy=max(round(SourceY/224.0),1.0);
2161
	if( intres>0.25&&intres!=1.0)sy=intres;
2162
	AdvSize*=float4(1.0,1.0/sy,1.0,sy);
2163
	float2 lexcoord=fuxcoord.xy;
2164
	if(IOS> 0.0&& !interb)
2165
	{
2166
	float2 ofactor= NewSize.xy/OrgSize.xy;
2167
	float2 ifactor=(IOS<2.5)? floor(ofactor):ceil(ofactor);
2168
	float2 diff=ofactor/ifactor;
2169
	float scan=diff.y;
2170
	lexcoord=overscan(lexcoord,scan,scan);
2171
	if(IOS==1.0||IOS==3.0) lexcoord=float2(fuxcoord.x,lexcoord.y);
2172
	}
2173
	float factor=1.0+(1.0-0.5*OS)*blm_2/100.0-lum*blm_2/100.0;
2174
	lexcoord=overscan(lexcoord,factor,factor);
2175
	lexcoord=overscan(lexcoord,(OrgSize.x-overscanx)/OrgSize.x,(OrgSize.y-overscany)/OrgSize.y);
2176
	float2 pos = warp(lexcoord);
2177
	float2 coffset=0.5;
2178
	float2 ps=AdvSize.zw;
2179
	float2 OGL2Pos=pos*AdvSize.xy-coffset;
2180
	float2 fp=frac(OGL2Pos);
2181
	float2 dx=float2(ps.x,0.0);
2182
	float2 dy=float2(0.0,ps.y);
2183
	float f=fp.y;
2184
	float2 pC4=floor(OGL2Pos)*ps+0.5*ps;
2185
	pC4.x=pos.x;
2186
	if( intres==0.5<1.5)pC4.y=floor(pC4.y*OrgSize.y)*OrgSize.w+0.5*OrgSize.w;
2187
	if( interb&&no_scanlines<0.025|| hscans) pC4.y=pos.y;else
2188
	if( interb) pC4.y=pC4.y+smoothstep(0.40-0.5*no_scanlines,0.60+0.5*no_scanlines,f)*AdvSize.w;
2189
	float3 color1=texCD(NTSC_S08,pC4).rgb;
2190
	float3 solor1=texCD(NTSC_S08,pC4).aaa;
2191
	if(!interb)color1=pow(color1,scangamma/gamma_in);
2192
	pC4+=dy;
2193
	if( intres==0.5<1.5)pC4.y=floor((pos.y+0.33*dy.y)*OrgSize.y)*OrgSize.w+0.5*OrgSize.w;
2194
	float3 color2=texCD(NTSC_S08,pC4).rgb;
2195
	float3 solor2=texCD(NTSC_S08,pC4).aaa;
2196
	if(!interb)color2=pow(color2,scangamma/gamma_in);
2197
	float3 ctmp=color1;float w3=1.0;float3 color=color1;
2198
	float3 one=1.0;
2199
	if( hscans){color2=color1;solor2=solor1;}
2200
	if(!interb|| hscans)
2201
	{
2202
	float shape1=lerp(scanline1,scanline2,    f);
2203
	float shape2=lerp(scanline1,scanline2,1.0-f);
2204
	float wt1=st0(    f);
2205
	float wt2=st0(1.0-f);
2206
	float3 color0=color1*wt1+color2*wt2;
2207
	float3 solor0=solor1*wt1+solor2*wt2;
2208
	ctmp = color0/(wt1+wt2);
2209
	float3 stmp=solor0/(wt1+wt2);
2210
	if(abs(rolling_scan)>0.005){color1=ctmp;color2=ctmp;solor1=stmp;solor2=stmp;}
2211
	float3 w1,w2;
2212
	float3 cref1=lerp(stmp,solor1,beam_size);float creff1=pow(max(max(cref1.r,cref1.g),cref1.b),scan_falloff);
2213
	float3 cref2=lerp(stmp,solor2,beam_size);float creff2=pow(max(max(cref2.r,cref2.g),cref2.b),scan_falloff);
2214
	if(tds>0.5){shape1=lerp(scanline2,shape1,creff1);shape2=lerp(scanline2,shape2,creff2);}
2215
	float scanpix=OrgSize.y/NewSize.y;
2216
	float f1=frac(f-rolling_scan*float(framecount)*scanpix);
2217
	float f2=1.0-f1;
2218
	float m1=max(max(color1.r,color1.g),color1.b)+eps;
2219
	float m2=max(max(color2.r,color2.g),color2.b)+eps;
2220
	cref1=color1/m1;
2221
	cref2=color2/m2;
2222
	if(gsl< 0.5)
2223
	{w1=sw0(f1,creff1,shape1,cref1);w2=sw0(f2,creff2,shape2,cref2);}else
2224
	if(gsl==1.0)
2225
	{w1=sw1(f1,creff1,shape1,cref1);w2=sw1(f2,creff2,shape2,cref2);}else
2226
	{w1=sw2(f1,creff1,shape1,cref1);w2=sw2(f2,creff2,shape2,cref2);}
2227
	float3 w3=w1+w2;
2228
	float wf1=max(max(w3.r,w3.g),w3.b);
2229
	if(wf1>1.0){wf1=1.0/wf1;w1*=wf1,w2*=wf1;}
2230
	if(abs(clp)>0.005)
2231
	{
2232
	sy=m1; one=(clp>0.0)?w1:1.0.xxx;
2233
	float sat=1.0001-min(min(cref1.r,cref1.g),cref1.b);
2234
	color1=lerp(color1,plant(pow(color1,0.70.xxx-0.325*sat),sy),pow(sat,0.3333)*one*abs(clp));
2235
	sy=m2; one=(clp>0.0)?w2:1.0.xxx;
2236
	sat=1.0001-min(min(cref2.r,cref2.g),cref2.b);
2237
	color2=lerp(color2,plant(pow(color2,0.70.xxx-0.325*sat),sy),pow(sat,0.3333)*one*abs(clp));
2238
	}
2239
	color=gc1(color1)*w1+gc1(color2)*w2;
2240
	color=min(color,1.0);
2241
	}
2242
	if( interb)
2243
	{
2244
	color=gc1(color1);
2245
	}
2246
	float colmx=max( max(ctmp.r,ctmp.g),ctmp.b);
2247
	if(!interb)color=pow(color,gamma_in/scangamma);
2248
	return float4(color,colmx);
2249
}
2250
2251
float4 ChromaticPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
2252
{
2253
	float gamma_in=1.0/texCD(NTSC_S07,float2(0.25,0.25)).a;
2254
	float lum=texCD(NTSC_S06,float2(0.5,0.5)).a;
2255
	float intera=texCD(NTSC_S07,float2(0.75,0.25)).a;
2256
	bool interb=((intera<0.35||no_scanlines>0.025)&&(hiscan<0.5));
2257
	float2 lexcoord=fuxcoord.xy;
2258
	if(IOS> 0.0&& !interb)
2259
	{
2260
	float2 ofactor= NewSize.xy/OrgSize.xy;
2261
	float2 ifactor=(IOS<2.5)? floor(ofactor):ceil(ofactor);
2262
	float2 diff=ofactor/ifactor;
2263
	float scan=diff.y;
2264
	lexcoord=overscan(lexcoord,scan,scan);
2265
	if(IOS==1.0||IOS==3.0) lexcoord=float2(fuxcoord.x,lexcoord.y);
2266
	}
2267
	float factor=1.0+(1.0-0.5*OS)*blm_2/100.0-lum*blm_2/100.0;
2268
	lexcoord=overscan(lexcoord,factor,factor);
2269
	lexcoord=overscan(lexcoord,(OrgSize.x-overscanx)/OrgSize.x,(OrgSize.y-overscany)/OrgSize.y);
2270
	float2 pos0= warp(fuxcoord);
2271
	float2 pos1= fuxcoord;
2272
	float2 pos = warp(lexcoord);
2273
	float3 color=texCD(NTSC_S13,pos1).rgb;
2274
	float3 Bloom=texCD(NTSC_S12,pos ).rgb;
2275
	float3 Glow =texCD(NTSC_S10,pos ).rgb;
2276
	if((abs(deconrx)+abs(deconry)+abs(decongx)+abs(decongy)+abs(deconbx)+abs(deconby))>0.2) bring_pixel(color,Bloom,Glow,pos1,pos);
2277
	float cm=igc(max(max(color.r,color.g),color.b));
2278
	float mx1=texCD(NTSC_S13,pos1   ).a;
2279
	float colmx=max(mx1,cm);
2280
	float w3=min((max((cm-0.0005)*1.0005,0.0)+0.0001)/(colmx+0.0005),1.0);if(interb)w3=1.0;
2281
	float2 dx=float2(0.001,0.0);
2282
	float mx0=texCD(NTSC_S13,pos1-dx).a;
2283
	float mx2=texCD(NTSC_S13,pos1+dx).a;
2284
	float mxg=max(max(mx0,mx1),max(mx2,cm));
2285
	float mx=pow(mxg,1.40/gamma_in);
2286
	float cx=pow(colmx,1.40/gamma_in);
2287
	dx=float2(OrgSize.z,0.0)*0.25;
2288
	mx0=texCD(NTSC_S13,pos1-dx).a;
2289
	mx2=texCD(NTSC_S13,pos1+dx).a;
2290
	float mb=(1.0-min(abs(mx0-mx2)/(0.5+mx1),1.0));
2291
	float3 orig1=color;
2292
	float3 one=1.0;
2293
	float3 cmask=one;
2294
	float3 dmask=one;
2295
	float3 emask=one;
2296
	float mwidths[15]={0.0,2.0,3.0,3.0,6.0,6.0,2.4,3.5,2.4,3.25,3.5,4.5,4.25,7.5,6.25};
2297
	float mwidth=mwidths[int(shadow_msk)];
2298
	float mask_compensate=frac(mwidth);
2299
	if(shadow_msk> 0.5)
2300
	{
2301
	float2 maskcoord= fracoord.xy;
2302
	float2 scoord=maskcoord;
2303
	mwidth=floor(mwidth)*masksize;
2304
	float swidth=mwidth;
2305
	bool zoomed=(abs(mask_zoom)>0.75);
2306
	float mscale=1.0;
2307
	float2 maskcoord0=maskcoord;
2308
	maskcoord.y=floor(maskcoord.y/masksize);
2309
	float mwidth0=max(mwidth+mask_zoom,2.0);
2310
	if( mshift> 0.25)
2311
	{
2312
	float stagg_lvl=1.0; if(frac(mshift)>0.25)stagg_lvl=2.0;
2313
	float next_line=float(floor(mod(maskcoord.y,2.0*stagg_lvl))<stagg_lvl);
2314
	maskcoord0.x=maskcoord0.x+next_line*0.5*mwidth0;
2315
	}
2316
	maskcoord=maskcoord0/masksize;
2317
	if(!zoomed)cmask*=crt_mask(floor(maskcoord),mx,mb);else
2318
	{
2319
	mscale=mwidth0/mwidth;
2320
	float clerp= frac(maskcoord.x/mscale); if( zoom_mask>0.025 )clerp=clamp((1.0+zoom_mask)*clerp-0.5*zoom_mask,0.0,1.0);
2321
	float coord=floor(maskcoord.x/mscale); if(shadow_msk==13.0&&mask_zoom==-2.0)coord=ceil(maskcoord.x/mscale);
2322
	cmask*=lerp(crt_mask(float2(coord,maskcoord.y),mx,mb),crt_mask(float2(coord+1.0,maskcoord.y),mx,mb),clerp);
2323
	}
2324
	if(slotwidth>0.5)swidth=slotwidth;float smask=1.0;
2325
	float sm_offset=0.0;bool bsm_offset=(shadow_msk==1.0||shadow_msk==3.0||shadow_msk==6.0||shadow_msk==7.0||shadow_msk==9.0||shadow_msk==12.0);
2326
	if( zoomed)
2327
	{
2328
	if(mask_layout<0.5&&bsm_offset)sm_offset=1.0;else
2329
	if(bsm_offset)sm_offset=-1.0;
2330
	}
2331
	swidth=round(swidth*mscale);
2332
	smask =slt_mask(scoord+float2(sm_offset,0.0),mx,swidth);
2333
	smask =clamp(smask+lerp(smask_mit,0.0,w3*pow(colmx,0.3)),0.0,1.0);
2334
	emask =cmask;
2335
	cmask*=smask;
2336
	dmask =cmask;
2337
	if(abs(mask_bloom)>0.025)
2338
	{
2339
	float maxbl=max( max(max(Bloom.r,Bloom.g),Bloom.b),mxg);
2340
	maxbl=maxbl*max(lerp(1.0,2-colmx,bloom_dist),0.0);
2341
	if(mask_bloom>0.025) cmask= max(min(cmask +maxbl*mask_bloom,1),cmask); else
2342
	cmask=max(lerp(cmask,cmask*(1.0-0.5*maxbl)+plant(pow( Bloom,0.35.xxx),maxbl),-mask_bloom),cmask);
2343
	}
2344
	color=pow(color,mask_gamma/gamma_in);
2345
	color=color*cmask;
2346
	color=min(color,1.0);
2347
	color=pow(color,gamma_in/mask_gamma);
2348
	cmask=min(cmask,1.0);
2349
	dmask=min(dmask,1.0);
2350
	float mm=max(-2.75*cx*(cx-1.0)-lerp(0.075,0.165,cx),0.0);color=max(color,orig1*maskmid*mm);
2351
	}
2352
	float dark_compensate=lerp(max(clamp(lerp(mcut,maskstr,mx),0.0,1.0)-1.0+ mask_compensate,0.0)+1.0,1.0,mx); if(shadow_msk< 0.5) dark_compensate=1.0;
2353
	float bb=lerp(brightboost1,brightboost2,mx)* dark_compensate; color*=bb;
2354
	float3 Ref=texCD(NTSC_S07,pos).rgb;
2355
	float maxb=texCD(NTSC_S12,pos).a;
2356
	float3 bcmask=lerp(one,dmask,b_mask);
2357
	float3 hcmask=lerp(one,dmask,h_mask);
2358
	float3 Bloomy=Bloom;
2359
	if(abs(blm_1)>0.025)
2360
	{
2361
	if(blm_1<-0.01)Bloomy=plant(Bloom,maxb);
2362
	Bloomy= min(Bloomy*(orig1+color),max(0.5*(colmx+orig1-color),0.001*Bloomy));
2363
	Bloomy=0.5*(Bloomy+lerp(Bloomy,lerp(colmx*orig1,Bloomy,0.5),1.0-color));
2364
	Bloomy= bcmask*Bloomy*max(lerp(1.0,2.0-colmx,bloom_dist),0);
2365
	color=pow(pow(color,mask_gamma/gamma_in)+abs(blm_1)*pow( Bloomy,mask_gamma/gamma_in),gamma_in/mask_gamma);
2366
	}
2367
	if(halation> 0.01)
2368
	{
2369
	Bloom= 0.5*(Bloom+Bloom*Bloom);float mbl=max(max(Bloom.r,Bloom.g),Bloom.b);float mxh=0.5*(colmx+colmx*colmx);
2370
	mbl=lerp(lerp(mxh,lerp( mxh,mbl,mbl),colmx),mbl,mb);
2371
	Bloom=plant(Bloom,lerp(sqrt(mbl*mxh),max((mbl-0.15*(1.0-colmx)),0.4*mxh),pow(colmx,0.25)))*lerp(0.425,1.0,colmx);
2372
	Bloom=(3.0-colmx-color)*plant(0.325+orig1/w3,0.5*(1.0+w3))*hcmask*Bloom;
2373
	color=pow(pow(color,mask_gamma/gamma_in)+ halation *pow( Bloom ,mask_gamma/gamma_in),gamma_in/mask_gamma);
2374
	}else
2375
	if(halation<-0.01)
2376
	{
2377
	float mbl=max(max(Bloom.r,Bloom.g),Bloom.b);
2378
	Bloom=plant(Bloom+Ref+orig1+Bloom*Bloom*Bloom,min(mbl*mbl,0.75));
2379
	color=color+2.0*lerp(1.0,w3,0.5*colmx)*hcmask*Bloom*(-halation);
2380
	}
2381
	color=min(color,1.0);
2382
	color=gc2(color,w3 );
2383
	if(smoothmask>0.125){float w4=pow(w3,0.425+0.3*smoothmask);w4=max(w4-0.175*colmx*smoothmask,0.2);color=lerp(min(color/w4,plant(orig1,1.0+0.175*colmx*smoothmask))*w4,color,w4);}
2384
	if(m_glow<0.5)Glow=lerp(Glow,0.25*color,colmx);else
2385
	{
2386
	float3 orig2=plant(orig1+0.001*Ref,1.0); maxb=max(max(Glow.r,Glow.g),Glow.b);
2387
	Bloom=plant(Glow,1.0);Ref=abs(orig2-Bloom);
2388
	mx0=max(max(orig2.r,orig2.g),orig2.b)-min(min(orig2.r,orig2.g),orig2.b);
2389
	mx2=max(max(Bloom.r,Bloom.g),Bloom.b)-min(min(Bloom.r,Bloom.g),Bloom.b);
2390
	Bloom=lerp(maxb*min(Bloom,orig2),lerp(lerp(Glow,max(max(Ref.r,Ref.g),Ref.b)*Glow,max(mx,mx0)),lerp(color,Glow,mx2),max(mx0,mx2)*Ref),min(sqrt((1.10-mx0)*(0.10+mx2)),1.0));
2391
	if(m_glow>1.5)Glow=lerp(0.5*Glow*Glow,Bloom,Bloom);
2392
	Glow=lerp(m_glow_low*Glow,m_glow_high*Bloom,pow(colmx,m_glow_dist/gamma_in));
2393
	}
2394
	if(m_glow<0.5)
2395
	{
2396
	if(glow >=0.0)color=color+0.5*Glow*glow;else color=color+abs(glow)*min(emask*emask,1.0)*Glow;}else
2397
	{
2398
	float3 fmask=clamp(lerp(one,dmask,m_glow_mask),0.0,1.0);
2399
	color=color+abs(glow)*fmask*Glow;
2400
	}
2401
	float vig=vignette(pos);
2402
	color=min(color,1.0);
2403
	if(edgemask>0.05)
2404
	{
2405
	mx0=texCD(NTSC_S13,pos1-dx).a;mx0=texCD(NTSC_S13,pos1-dx*(1.0-0.75*sqrt(mx0))).a;
2406
	mx2=texCD(NTSC_S13,pos1+dx).a;mx2=texCD(NTSC_S13,pos1+dx*(1.0-0.75*sqrt(mx2))).a;
2407
	float mx3=texCD(NTSC_S13,pos1-4.0*dx).a;
2408
	float mx4=texCD(NTSC_S13,pos1+4.0*dx).a;
2409
	mx4=max(pow(abs(mx3-mx4),0.55-0.40*cx),min(max(mx3,mx4)/min(0.1+cx,1.0),1.0));
2410
	mb=(1.0-abs(pow(mx0,1.0-0.65*mx2)-pow(mx2,1.0-0.65*mx0)));
2411
	mb=mx4*edgemask*(1.0001-mb*mb);float3 temp=lerp(color,orig1,mb);
2412
	color=max(temp+lerp(3.5*mb*lerp(1.625*temp,temp,cx),0.0.xxx,pow(color,0.75.xxx -0.5*colmx)),color);
2413
	}
2414
	color=color* lerp(1.0,lerp(0.5*(1.0+w3),w3,mx),pr_scan);
2415
	color=min(color,max(orig1,color)*lerp(one,dmask,mclip));
2416
	color=pow(color,1.0/gamma_o);
2417
	float q=0.6*sqrt(max(max(color.r,color.g),color.b))+0.4;
2418
	if(abs(addnoised)>0.01)
2419
	{
2420
	float3 noise0=noise(float3(floor(NewSize.xy*fuxcoord/noiseresd),float(framecount)));
2421
	if(noisetype<0.5)color=lerp(color,noise0,0.25*abs(addnoised)*q);else
2422
	color=min(color* lerp(1.0,1.5*noise0.x,0.5*abs(addnoised)),1.0);
2423
	}
2424
	colmx=max(max(orig1.r,orig1.g),orig1.b);
2425
	color=color+bmask*lerp(emask,0.125*(1.0-colmx)*color,min(20.0*colmx,1.0));
2426
	return float4(color*vig*humbars(lerp(pos.y,pos.x,bardir))*post_br*corner(pos0),1.0);
2427
}
2428
2429
float4 RatioSizePS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
2430
{
2431
	const bool margins=float(texcoord.x>=coord_w&&texcoord.x<=coord_e&&texcoord.y>=coord_n&&texcoord.y<=coord_s);
2432
	const float2 boxcoord=((texcoord-correct)*OptSize.xy+0)/BoxSize;
2433-
	const float4 boxcolor=texCD(CGHD_S09,boxcoord);
2433+
	const float4 boxcolor=texCD(NTSC_S14,boxcoord);
2434
	return float4(margins*boxcolor.rgb,boxcolor.a);
2435
}
2436
2437
technique CRT_Guest_NTSC
2438
{
2439
	pass StockPass
2440
	{
2441
	VertexShader=CropProcessVS;
2442
	PixelShader=StockPassPS;
2443
	RenderTarget=NTSC_T01;
2444
	PrimitiveTopology=TRIANGLESTRIP;
2445
	VertexCount=4;
2446
	}
2447
	pass NTSCPASS1
2448
	{
2449
	VertexShader=PostProcessVS;
2450
	PixelShader=Signal_1_PS;
2451
	RenderTarget=NTSC_T02;
2452
	}
2453
	pass NTSCPASS2
2454
	{
2455
	VertexShader=PostProcessVS;
2456
	PixelShader=Signal_2_PS;
2457
	RenderTarget=NTSC_T03;
2458
	}
2459
	pass NTSCPASS3
2460
	{
2461
	VertexShader=PostProcessVS;
2462
	PixelShader=Signal_3_PS;
2463
	RenderTarget=NTSC_T04;
2464
	}
2465
	pass Sharpness
2466
	{
2467
	VertexShader=PostProcessVS;
2468
	PixelShader=SharpnessPS;
2469
	RenderTarget=NTSC_T05;
2470
	}
2471
	pass Luminance
2472
	{
2473
	VertexShader=PostProcessVS;
2474
	PixelShader=LuminancePS;
2475
	RenderTarget=NTSC_T06;
2476
	}
2477
	pass Linearize
2478
	{
2479
	VertexShader=PostProcessVS;
2480
	PixelShader=LinearizePS;
2481
	RenderTarget=NTSC_T07;
2482
	}
2483
	pass CRT_Pass1
2484
	{
2485
	VertexShader=PostProcessVS;
2486
	PixelShader=NTSC_TV1_PS;
2487
	RenderTarget=NTSC_T08;
2488
	}
2489
	pass GaussianX
2490
	{
2491
	VertexShader=PostProcessVS;
2492
	PixelShader=HGaussianPS;
2493
	RenderTarget=NTSC_T09;
2494
	}
2495
	pass GaussianY
2496
	{
2497
	VertexShader=PostProcessVS;
2498
	PixelShader=VGaussianPS;
2499
	RenderTarget=NTSC_T10;
2500
	}
2501
	pass BloomHorz
2502
	{
2503
	VertexShader=PostProcessVS;
2504
	PixelShader=BloomHorzPS;
2505
	RenderTarget=NTSC_T11;
2506
	}
2507
	pass BloomVert
2508
	{
2509
	VertexShader=PostProcessVS;
2510
	PixelShader=BloomVertPS;
2511
	RenderTarget=NTSC_T12;
2512
	}
2513
	pass CRT_Pass2
2514
	{
2515
	VertexShader=PostProcessVS;
2516
	PixelShader=NTSC_TV2_PS;
2517
	RenderTarget=NTSC_T13;
2518
	}
2519
	pass Chromatic
2520
	{
2521
	VertexShader=PostProcessVS;
2522
	PixelShader=ChromaticPS;
2523
	RenderTarget=NTSC_T14;
2524
	}
2525
	pass RatioSize
2526
	{
2527
	VertexShader=PostProcessVS;
2528
	PixelShader=RatioSizePS;
2529
	}
2530
}