Guest User

CRT-Guest-NTSC : TEST #2

a guest
Jun 14th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 66.61 KB | None | 0 0
  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.89;
  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 OptSize float4(BUFFER_SCREEN_SIZE,1.0/BUFFER_SCREEN_SIZE)
  1110. #define OrgSize float4(TexSize,1.0/TexSize)
  1111. #define SrcSize float4(IptSize,1.0/IptSize)
  1112. #define fuxcoord (texcoord*1.00001)
  1113. #define scans 1.5*scans
  1114. #define eps 1e-8
  1115. #define pii 3.14159265
  1116. #define fracoord (fuxcoord*OptSize.xy)
  1117. #define texCD(c,d) tex2Dlod(c,float4(d,0,0))
  1118. #define LumSize float4(2.0*TexSize.x,1.0*TexSize.y,1.0/(2.0*TexSize.x),1.0/(1.0*TexSize.y))
  1119. #define mix_m float3x3(BRIGHTNESS,ARTIFACT,ARTIFACT,FRINGING,2.0*SATURATION,0.0,FRINGING,0.0,2.0*SATURATION)
  1120. #define rgb_m float3x3(0.299,0.587,0.114,0.596,-0.274,-0.322,0.211,-0.523,0.312)
  1121. #define yiq_m float3x3(1.000,0.956,0.621,1.000,-0.272,-0.647,1.000,-1.106,1.703)
  1122. #define fetch_offset1(dx) texCD(NTSC_S02,tex_c+dx).xyz+texCD(NTSC_S02,tex_c-dx).xyz
  1123. #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)
  1124.  
  1125. #ifndef Resolution_X
  1126. #define Resolution_X 320
  1127. #endif
  1128.  
  1129. #ifndef Resolution_Y
  1130. #define Resolution_Y 240
  1131. #endif
  1132.  
  1133. #define NTSC_S00 ReShade::BackBuffer
  1134.  
  1135. texture NTSC_T01{Width=1.0*Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  1136. sampler NTSC_S01{Texture=NTSC_T01;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=POINT ;MinFilter=POINT ;MipFilter=POINT ;};
  1137.  
  1138. texture NTSC_T02{Width=4.0*Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  1139. sampler NTSC_S02{Texture=NTSC_T02;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1140.  
  1141. texture NTSC_T03{Width=2.0*Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  1142. sampler NTSC_S03{Texture=NTSC_T03;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1143.  
  1144. texture NTSC_T04{Width=2.0*Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  1145. sampler NTSC_S04{Texture=NTSC_T04;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1146.  
  1147. texture NTSC_T05{Width=2.0*Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  1148. sampler NTSC_S05{Texture=NTSC_T05;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1149.  
  1150. texture NTSC_T06{Width=2.0*Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  1151. sampler NTSC_S06{Texture=NTSC_T06;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1152.  
  1153. texture NTSC_T07{Width=2.0*Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  1154. sampler NTSC_S07{Texture=NTSC_T07;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1155.  
  1156. texture NTSC_T08{Width=1.0*BUFFER_WIDTH;Height=Resolution_Y ;Format=RGBA16F;};
  1157. sampler NTSC_S08{Texture=NTSC_T08;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1158.  
  1159. texture NTSC_T09{Width=1.0*800.00000000;Height=Resolution_Y ;Format=RGBA16F;};
  1160. sampler NTSC_S09{Texture=NTSC_T09;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1161.  
  1162. texture NTSC_T10{Width=1.0*800.00000000;Height=600.00000000 ;Format=RGBA16F;};
  1163. sampler NTSC_S10{Texture=NTSC_T10;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1164.  
  1165. texture NTSC_T11{Width=1.0*800.00000000;Height=600.00000000 ;Format=RGBA16F;};
  1166. sampler NTSC_S11{Texture=NTSC_T11;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1167.  
  1168. texture NTSC_T12{Width=1.0*800.00000000;Height=600.00000000 ;Format=RGBA16F;};
  1169. sampler NTSC_S12{Texture=NTSC_T12;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1170.  
  1171. texture NTSC_T13{Width=1.0*BUFFER_WIDTH;Height=BUFFER_HEIGHT;Format=RGBA16F;};
  1172. sampler NTSC_S13{Texture=NTSC_T13;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;MipFilter=LINEAR;};
  1173.  
  1174. uniform int framecount<source="framecount";>;
  1175.  
  1176. float vignette(float2 pos)
  1177. {
  1178. float2 b=vigdef*float2(1.0,OrgSize.x/OrgSize.y)*0.125;
  1179. pos=clamp(pos,0.0,1.0);
  1180. pos=abs(2.0*(pos-0.5));
  1181. float2 res=lerp(0.0.xx,1.0.xx,smoothstep(1.0.xx,1.0.xx-b,sqrt(pos)));
  1182. res=pow(res,0.70.xx);
  1183. return max(lerp(1.0,sqrt(res.x*res.y),vigstr),0.0);
  1184. }
  1185.  
  1186. float dist(float3 A,float3 B)
  1187. {
  1188. float r=0.5*(A.r+B.r);
  1189. float3 d=A-B;
  1190. float3 c=float3(2.+r,4.,3.-r);
  1191. return sqrt(dot(c*d,d))/3.;
  1192. }
  1193.  
  1194. float3 plant(float3 tar,float r)
  1195. {
  1196. float t=max(max(tar.r,tar.g),tar.b)+0.00001;
  1197. return tar*r/t;
  1198. }
  1199.  
  1200. float3 fetch_pixel(float2 coord)
  1201. {
  1202. float2 dx=float2(LumSize.z,0.0)*downsample_levelx;
  1203. float2 dy=float2(0.0,LumSize.w)*downsample_levely;
  1204. float2 d1=dx+dy;
  1205. float2 d2=dx-dy;
  1206. float sum=15.0;
  1207. float3 result=
  1208. 3.0*texCD(NTSC_S05,coord ).rgb+2.0*texCD(NTSC_S05,coord+dx).rgb+2.0*texCD(NTSC_S05,coord-dx).rgb+
  1209. 2.0*texCD(NTSC_S05,coord+dy).rgb+2.0*texCD(NTSC_S05,coord-dy).rgb+ texCD(NTSC_S05,coord+d1).rgb+
  1210. texCD(NTSC_S05,coord-d1).rgb+ texCD(NTSC_S05,coord+d2).rgb+ texCD(NTSC_S05,coord-d2).rgb;
  1211. return result/sum;
  1212. }
  1213.  
  1214. float gauss_h(float x)
  1215. {
  1216. float sigma=1.0/(2.0*SIGMA_H*SIGMA_H);
  1217. return exp(-x*x*sigma);
  1218. }
  1219.  
  1220. float gauss_v(float x)
  1221. {
  1222. float sigma=1.0/(2.0*SIGMA_V*SIGMA_V);
  1223. return exp(-x*x*sigma);
  1224. }
  1225.  
  1226. float bloom_h(float x)
  1227. {
  1228. float sigma=1.0/(2.0*SIGMA_X*SIGMA_X);
  1229. return exp(-x*x*sigma);
  1230. }
  1231.  
  1232. float bloom_v(float x)
  1233. {
  1234. float sigma=1.0/(2.0*SIGMA_Y*SIGMA_Y);
  1235. return exp(-x*x*sigma);
  1236. }
  1237.  
  1238. float crthd_h(float x,float y)
  1239. {
  1240. float sigma=1.0/(2.0*LIGMA_H*LIGMA_H*y*y*internal_res*internal_res);
  1241. return exp(-x*x*sigma);
  1242. }
  1243.  
  1244. float mod(float x,float y)
  1245. {
  1246. return x-y* floor(x/y);
  1247. }
  1248.  
  1249. float st0(float x)
  1250. {
  1251. return exp2(-10.0*x*x);
  1252. }
  1253.  
  1254. float3 sw0(float x,float color,float scanline,float3 c)
  1255. {
  1256. float3 xe=lerp(1.0.xxx+scans,1.0.xxx,c);
  1257. float tmp=lerp(beam_min,beam_max,color);
  1258. float ex=x*tmp;
  1259. ex=(gsl>-0.5)?ex*ex:lerp(ex*ex,ex*ex*ex,0.4);
  1260. return exp2(-scanline*ex*xe);
  1261. }
  1262.  
  1263. float3 sw1(float x,float color,float scanline,float3 c)
  1264. {
  1265. float3 xe=lerp(1.0.xxx+scans,1.0.xxx,c);
  1266. x=lerp(x,beam_min*x,max(x-0.4*color,0.0));
  1267. float tmp=lerp(1.2*beam_min,beam_max,color);
  1268. float ex=x*tmp;
  1269. return exp2(-scanline*ex*ex*xe);
  1270. }
  1271.  
  1272. float3 sw2(float x,float color,float scanline,float3 c)
  1273. {
  1274. float3 xe=lerp(1.0.xxx+scans,1.0.xxx,c);
  1275. float tmp=lerp((2.5-0.5*color)*beam_min,beam_max,color);
  1276. tmp=lerp(beam_max,tmp,pow(x,color+0.3));
  1277. float ex=x*tmp;
  1278. return exp2(-scanline*ex*ex*xe);
  1279. }
  1280.  
  1281. float2 overscan(float2 pos,float dx,float dy)
  1282. {
  1283. pos=pos*2.0-1.0;
  1284. pos*=float2(dx,dy);
  1285. return pos*0.5+0.5;
  1286. }
  1287.  
  1288. float2 warp(float2 pos)
  1289. {
  1290. pos=pos*2.0-1.0;
  1291. 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);
  1292. return pos*0.5+0.5;
  1293. }
  1294.  
  1295. float3 gc1(float3 c)
  1296. {
  1297. float mc=max(max(c.r,c.g),c.b);
  1298. float mg=pow(mc,1.0/gamma_c);
  1299. return c*mg/(mc+eps);
  1300. }
  1301.  
  1302. float3 rgb2yiq(float3 r)
  1303. {
  1304. return mul(rgb_m, r);
  1305. }
  1306.  
  1307. float3 yiq2rgb(float3 y)
  1308. {
  1309. return mul(yiq_m, y);
  1310. }
  1311.  
  1312. float get_luma(float3 c)
  1313. {
  1314. return dot(c,float3(0.299,0.587,0.114));
  1315. }
  1316.  
  1317. float swoothstep(float e0,float e1,float x)
  1318. {
  1319. return clamp((x-e0)/(e1-e0),0.0,1.0);
  1320. }
  1321.  
  1322. float3 crt_mask(float2 pos,float mx,float mb)
  1323. {
  1324. float3 mask=mask_drk;
  1325. float3 one=1.0;
  1326. if(shadow_msk== 1.0)
  1327. {
  1328. float mc=1.0-max(maskstr,0.0);
  1329. pos.x=frac(pos.x*0.5);
  1330. if(pos.x<0.49)
  1331. {
  1332. mask.r=1.0;mask.g= mc;mask.b=1.0;
  1333. }else
  1334. {
  1335. mask.r= mc;mask.g=1.0;mask.b= mc;
  1336. }
  1337. }else
  1338. if(shadow_msk== 2.0)
  1339. {
  1340. float lane=mask_lgt;
  1341. float odd=0.0;
  1342. if(frac(pos.x/6.0)<0.49)odd=1.0;
  1343. if(frac((pos.y+odd)/2.0)<0.49)lane=mask_drk;
  1344. pos.x=floor(mod(pos.x,3.0));
  1345. if(pos.x<0.5)mask.r=mask_lgt;else
  1346. if(pos.x<1.5)mask.g=mask_lgt;else
  1347. mask.b= mask_lgt;
  1348. mask*=lane;
  1349. }else
  1350. if(shadow_msk== 3.0)
  1351. {
  1352. pos.x=floor(mod(pos.x,3.0));
  1353. if(pos.x<0.5)mask.r=mask_lgt;else
  1354. if(pos.x<1.5)mask.g=mask_lgt;else
  1355. mask.b= mask_lgt;
  1356. }else
  1357. if(shadow_msk== 4.0)
  1358. {
  1359. pos.x+=pos.y*3.0;
  1360. pos.x=frac(pos.x/6.0);
  1361. if(pos.x<0.3)mask.r=mask_lgt;else
  1362. if(pos.x<0.6)mask.g=mask_lgt;else
  1363. mask.b= mask_lgt;
  1364. }else
  1365. if(shadow_msk== 5.0)
  1366. {
  1367. pos.xy=floor(pos.xy*float2(1.0,0.5));
  1368. pos.x+=pos.y*3.0;
  1369. pos.x=frac(pos.x/6.0);
  1370. if(pos.x<0.3)mask.r=mask_lgt;else
  1371. if(pos.x<0.6)mask.g=mask_lgt;else
  1372. mask.b= mask_lgt;
  1373. }else
  1374. if(shadow_msk== 6.0)
  1375. {
  1376. mask=0.0;
  1377. pos.x=frac(pos.x/2.0);
  1378. if(pos.x<0.49)
  1379. {
  1380. mask.r=1.0;
  1381. mask.b=1.0;
  1382. }else
  1383. mask.g=1.0;
  1384. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1385. }else
  1386. if(shadow_msk== 7.0)
  1387. {
  1388. mask=0.0;
  1389. pos.x=floor(mod(pos.x,3.0));
  1390. if(pos.x<0.5)mask.r=1.0;else
  1391. if(pos.x<1.5)mask.g=1.0;else
  1392. mask.b=1.0;
  1393. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1394. }else
  1395. if(shadow_msk== 8.0)
  1396. {
  1397. mask=0.0;
  1398. pos.x=frac(pos.x/2.0);
  1399. if(pos.x<0.49)
  1400. {
  1401. mask=0.0.xxx;
  1402. }else
  1403. mask=1.0.xxx;
  1404. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1405. }else
  1406. if(shadow_msk== 9.0)
  1407. {
  1408. mask=0.0;
  1409. pos.x=frac(pos.x/3.0);
  1410. if(pos.x<0.3)mask=0.0.xxx;else
  1411. if(pos.x<0.6)mask=1.0.xxx;else
  1412. mask=1.0.xxx;
  1413. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1414. }else
  1415. if(shadow_msk==10.0)
  1416. {
  1417. mask=0.0;
  1418. pos.x=frac(pos.x/3.0);
  1419. if(pos.x<0.3)mask =0.0.xxx;else
  1420. if(pos.x<0.6)mask.rb=1.0.xx ;else
  1421. mask.g=1.0;
  1422. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1423. }else
  1424. if(shadow_msk==11.0)
  1425. {
  1426. mask=0.0;
  1427. pos.x=frac(pos.x*0.25);
  1428. if(pos.x<0.2)mask =0.0.xxx;else
  1429. if(pos.x<0.4)mask.r=1.0 ;else
  1430. if(pos.x<0.7)mask.g=1.0 ;else
  1431. mask.b=1.0;
  1432. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1433. }else
  1434. if(shadow_msk==12.0)
  1435. {
  1436. mask=0.0;
  1437. pos.x=frac(pos.x*0.25);
  1438. if(pos.x<0.2)mask.r =1.0 ;else
  1439. if(pos.x<0.4)mask.rg=1.0.xx;else
  1440. if(pos.x<0.7)mask.gb=1.0.xx;else
  1441. mask.b=1.0;mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1442. }else
  1443. if(shadow_msk==13.0)
  1444. {
  1445. mask=0.0;
  1446. pos.x=floor(mod(pos.x,7.0));
  1447. if(pos.x<0.5)mask =0.0.xxx;else
  1448. if(pos.x<2.5)mask.r=1.0 ;else
  1449. if(pos.x<4.5)mask.g=1.0 ;else
  1450. mask.b=1.0;
  1451. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1452. }else
  1453. {
  1454. mask=0.0;
  1455. pos.x=floor(mod(pos.x,6.0));
  1456. if(pos.x<0.5)mask =0.0.xxx;else
  1457. if(pos.x<1.5)mask.r =1.0 ;else
  1458. if(pos.x<2.5)mask.rg =1.0.xx ;else
  1459. if(pos.x<3.5)mask.rgb=1.0.xxx;else
  1460. if(pos.x<4.5)mask.gb =1.0.xx ;else
  1461. mask.b=1.0;
  1462. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1463. }
  1464. if(mask_layout>0.5)mask=mask.rbg;
  1465. float maskmin=min(min(mask.r,mask.g),mask.b);
  1466. return (mask-maskmin)*(1.0+(maskboost-1.0)*mb)+maskmin;
  1467. }
  1468.  
  1469. float slt_mask(float2 pos,float m,float swidth)
  1470. {
  1471. if ((slotmask1+slotmask2)==0.0)return 1.0;else
  1472. {
  1473. pos.y=floor(pos.y/slotms);
  1474. float mlen=swidth*2.0;
  1475. float px=floor( mod(pos.x, 0.99999*mlen));
  1476. float py=floor(frac(pos.y/(2.0*double_slot))*2.0*double_slot);
  1477. float slot_dark=lerp(1.0-slotmask2,1.0-slotmask1,m);
  1478. float slot=1.0;
  1479. if(py==0.0&&px<swidth) slot=slot_dark;else
  1480. if(py==double_slot&&px>=swidth) slot=slot_dark;
  1481. return slot;
  1482. }
  1483. }
  1484.  
  1485. float humbars(float pos)
  1486. {
  1487. if (barintensity==0.0)return 1.0;else
  1488. {
  1489. pos=(barintensity>=0.0)?pos:(1.0-pos);
  1490. pos=frac(pos+ mod(float(framecount),barspeed)/(barspeed-1.0));
  1491. pos=(barintensity< 0.0)?pos:(1.0-pos);
  1492. return (1.0-barintensity)+barintensity*pos;
  1493. }
  1494. }
  1495.  
  1496. float corner(float2 pos)
  1497. {
  1498. pos=abs(2.0*(pos-0.50));
  1499. float2 aspect=float2(1.0,OptSize.x/OptSize.y);
  1500. float b=bsize*0.05+0.0005;pos.y=pos.y+b*(aspect.y-1.0);
  1501. float2 crn=max(csize.xx,2.0*b+0.0015);
  1502. float2 crp=max(pos-(1.0-crn*aspect),0.0)/aspect;float cd=sqrt(dot(crp,crp));
  1503. pos=max(pos,1.0-crn+cd);
  1504. float res=lerp(1.0,0.0,smoothstep(1.0-b,1.0,sqrt(max(pos.x,pos.y))));
  1505. return pow(res,sborder);
  1506. }
  1507.  
  1508. float3 declip(float3 c,float b)
  1509. {
  1510. float m=max(max(c.r,c.g),c.b);
  1511. if(m>b)c=c*b/m;
  1512. return c;
  1513. }
  1514.  
  1515. float igc(float mc)
  1516. {
  1517. return pow(mc,gamma_c);
  1518. }
  1519.  
  1520. float3 gc2(float3 c,float w3)
  1521. {
  1522. float mc=max(max(c.r,c.g),c.b);
  1523. float p=1.0/(1.0+(gamma_d-1.0)* lerp(0.375,1.0,w3));
  1524. float mg=pow(mc, p );
  1525. return c*mg/(mc+eps);
  1526. }
  1527.  
  1528. float3 noise(float3 v)
  1529. {
  1530. if(addnoised<0.0)v.z=-addnoised;else v.z= mod(v.z,6001.0)/1753.0;
  1531. v =frac(v)+frac(v*1e4)+frac(v*1e-4);
  1532. v+=float3(0.12345,0.6789,0.314159);
  1533. v =frac(v*dot(v,v)*123.456);
  1534. v =frac(v*dot(v,v)*123.456);
  1535. v =frac(v*dot(v,v)*123.456);
  1536. v =frac(v*dot(v,v)*123.456);
  1537. return v;
  1538. }
  1539.  
  1540. void bring_pixel(inout float3 c,inout float3 b,inout float3 g,float2 coord,float2 boord)
  1541. {
  1542. float stepx=OptSize.z;
  1543. float stepy=OptSize.w;
  1544. float2 dx=float2(stepx,0.0);
  1545. float2 dy=float2(0.0,stepy);
  1546. float posx= 2.0*coord.x-1.0;
  1547. float posy= 2.0*coord.y-1.0;
  1548. if(dctypex>0.025)
  1549. {
  1550. posx= sign(posx)*pow(abs(posx),1.05-dctypex);
  1551. dx=posx*dx;
  1552. }
  1553. if(dctypey>0.025)
  1554. {
  1555. posy= sign(posy)*pow(abs(posy),1.05-dctypey);
  1556. dy=posy*dy;
  1557. }
  1558. float2 rc=deconrx*dx+deconry*dy;
  1559. float2 gc=decongx*dx+decongy*dy;
  1560. float2 bc=deconbx*dx+deconby*dy;
  1561. float r1=texCD(NTSC_S13,coord+rc).r;
  1562. float g1=texCD(NTSC_S13,coord+gc).g;
  1563. float b1=texCD(NTSC_S13,coord+bc).b;
  1564. float ds=decons;
  1565. float3 d=float3(r1,g1,b1);
  1566. c=clamp(lerp(c,d,ds),0.0,1.0);
  1567. r1=texCD(NTSC_S12,boord+rc).r;
  1568. g1=texCD(NTSC_S12,boord+gc).g;
  1569. b1=texCD(NTSC_S12,boord+bc).b;
  1570. d=float3(r1,g1,b1);
  1571. b=g=lerp(b,d,min(ds,1.0));
  1572. r1=texCD(NTSC_S10,boord+rc).r;
  1573. g1=texCD(NTSC_S10,boord+gc).g;
  1574. b1=texCD(NTSC_S10,boord+bc).b;
  1575. d=float3(r1,g1,b1);
  1576. g=lerp(g,d,min(ds,1.0));
  1577. }
  1578.  
  1579. float4 StockPassPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1580. {
  1581. return texCD(NTSC_S00,texcoord);
  1582. }
  1583.  
  1584. float4 Signal_1_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1585. {
  1586. float pix_res= min(ntsc_scale,1.0);
  1587. float phase= (ntsc_phase<1.5)?((OrgSize.x>300.0)? 2.0:3.0):((ntsc_phase>2.5)?3.0:2.0);
  1588. if(ntsc_phase==4.0)phase=3.0;
  1589. float res=ntsc_scale;
  1590. float CHROMA_MOD_FREQ=(phase<2.5)?(4.0*pii/15.0):(pii/3.0);
  1591. float ARTIFACT=cust_artifacting;
  1592. float FRINGING=cust_fringing;
  1593. float BRIGHTNESS=ntsc_brt;
  1594. float SATURATION=ntsc_sat;
  1595. float MERGE=0.0;
  1596. if(ntsc_fields== 1.0&&phase==3.0) MERGE=1.0;else
  1597. if(ntsc_fields== 2.0) MERGE=0.0;else
  1598. if(ntsc_fields== 3.0) MERGE=1.0;
  1599. float2 pix_no=texcoord*OrgSize.xy*pix_res* float2(4.0,1.0);
  1600. float3 col0=texCD(NTSC_S01, texcoord).rgb;
  1601. float3 yiq1=rgb2yiq(col0);
  1602. yiq1.x=pow(yiq1.x,ntsc_gamma); float lum=yiq1.x;
  1603. float2 dx=float2(OrgSize.z,0.0);
  1604. float c1=get_luma(texCD(NTSC_S01,texcoord-dx).rgb);
  1605. float c2=get_luma(texCD(NTSC_S01,texcoord+dx).rgb);
  1606. if(ntsc_phase==4.0)
  1607. {
  1608. float miix=min(5.0*abs(c1-c2),1.0);
  1609. c1=pow(c1,ntsc_gamma);
  1610. c2=pow(c2,ntsc_gamma);
  1611. yiq1.x=lerp(min(0.5*(yiq1.x+max(c1,c2)),max(yiq1.x,min(c1,c2))),yiq1.x,miix);
  1612. }
  1613. float3 yiq2=yiq1;
  1614. float3 yiqs=yiq1;
  1615. float3 yiqz=yiq1;
  1616. float3 temp=yiq1;
  1617. float mit=ntsc_taps;if(ntsc_charp1>0.25&&phase==2.0)mit=clamp(mit,8.0,min(ntsc_taps,14.0));
  1618. mit=swoothstep(16.0,8.0,mit)*0.325;
  1619. if(MERGE>0.5)
  1620. {
  1621. 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.));
  1622. float mod_phase2=chroma_phase2+pix_no.x*CHROMA_MOD_FREQ;
  1623. float i_mod2=cos( mod_phase2 );
  1624. float q_mod2=sin( mod_phase2 );
  1625. yiq2.yz*=float2(i_mod2,q_mod2);
  1626. yiq2=mul(mix_m,yiq2);
  1627. yiq2.yz*=float2(i_mod2,q_mod2);
  1628. yiq2.yz =lerp(yiq2.yz,temp.yz,mit);
  1629. if(res>1.025)
  1630. {
  1631. mod_phase2=chroma_phase2 +res *pix_no.x*CHROMA_MOD_FREQ;
  1632. i_mod2=cos(mod_phase2);
  1633. q_mod2=sin(mod_phase2);
  1634. yiqs.yz*=float2(i_mod2,q_mod2);
  1635. yiq2.x=dot(yiqs,mix_m[0]);
  1636. }
  1637. }
  1638. 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.));
  1639. float mod_phase1=chroma_phase1+pix_no.x*CHROMA_MOD_FREQ;
  1640. float i_mod1=cos( mod_phase1 );
  1641. float q_mod1=sin( mod_phase1 );
  1642. yiq1.yz*=float2(i_mod1,q_mod1);
  1643. yiq1=mul(mix_m,yiq1);
  1644. yiq1.yz*=float2(i_mod1,q_mod1);
  1645. yiq1.yz =lerp(yiq1.yz,temp.yz,mit);
  1646. if(res>1.025)
  1647. {
  1648. mod_phase1=chroma_phase1 +res *pix_no.x*CHROMA_MOD_FREQ;
  1649. i_mod1=cos(mod_phase1);
  1650. q_mod1=sin(mod_phase1);
  1651. yiqz.yz*=float2(i_mod1,q_mod1);
  1652. yiq1.x=dot(yiqz,mix_m[0]);
  1653. }
  1654. if(ntsc_phase==4.0){yiq1.x=lum;yiq2.x=lum;}
  1655. 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);}
  1656. return float4(yiq1,lum);
  1657. }
  1658.  
  1659. float4 Signal_2_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1660. {
  1661. float chroma_filter_2_phase[33]={
  1662. 0.001384762, 0.001678312, 0.002021715, 0.002420562, 0.002880460, 0.003406879, 0.004004985, 0.004679445, 0.005434218, 0.006272332, 0.007195654,
  1663. 0.008204665, 0.009298238, 0.010473450, 0.011725413, 0.013047155, 0.014429548, 0.015861306, 0.017329037, 0.018817382, 0.020309220, 0.021785952,
  1664. 0.023227857, 0.024614500, 0.025925203, 0.027139546, 0.028237893, 0.029201910, 0.030015081, 0.030663170, 0.031134640, 0.031420995, 0.031517031};
  1665. float chroma_filter_3_phase[25]={
  1666. -0.000118847,-0.000271306,-0.000502642,-0.000930833,-0.001451013,
  1667. -0.002064744,-0.002700432,-0.003241276,-0.003524948,-0.003350284,
  1668. -0.002491729,-0.000721149, 0.002164659, 0.006313635, 0.011789103,
  1669. 0.018545660, 0.026414396, 0.035100710, 0.044196567, 0.053207202,
  1670. 0.061590275, 0.068803602, 0.074356193, 0.077856564, 0.079052396};
  1671. float luma_filter_2_phase[33]={
  1672. -0.000174844,-0.000205844,-0.000149453,-0.000051693, 0.000000000,-0.000066171,-0.000245058,-0.000432928,-0.000472644,-0.000252236, 0.000198929,
  1673. 0.000687058, 0.000944112, 0.000803467, 0.000363199, 0.000013422, 0.000253402, 0.001339461, 0.002932972, 0.003983485, 0.003026683,-0.001102056,
  1674. -0.008373026,-0.016897700,-0.022914480,-0.021642347,-0.028863273, 0.027271957, 0.054921920, 0.098342579, 0.139044281, 0.168055832, 0.178571429};
  1675. float luma_filter_3_phase[25]={
  1676. -0.000012020,-0.000022146,-0.000013155,-0.000012020,-0.000049979,
  1677. -0.000113940,-0.000122150,-0.000005612, 0.000170516, 0.000237199,
  1678. 0.000169640, 0.000285688, 0.000984574, 0.002018683, 0.002002275,
  1679. -0.005909882,-0.012049081,-0.018222860,-0.022606931, 0.002460860,
  1680. 0.035868225, 0.084016453, 0.135563500, 0.175261268, 0.220176552};
  1681. float luma_filter_4_phase[25]={
  1682. -0.000472644,-0.000252236, 0.000198929, 0.000687058, 0.000944112,
  1683. 0.000803467, 0.000363199, 0.000013422, 0.000253402, 0.001339461,
  1684. 0.002932972, 0.003983485, 0.003026683,-0.001102056,-0.008373026,
  1685. -0.016897700,-0.022914480,-0.021642347,-0.028863273, 0.027271957,
  1686. 0.054921920, 0.098342579, 0.139044281, 0.168055832, 0.178571429};
  1687. const int TAPS_2_phase=32;
  1688. const int TAPS_3_phase=24;
  1689. float res=ntsc_scale;
  1690. float3 signal=0.0;
  1691. float2 one=0.25*OrgSize.zz/res;
  1692. float2 tex_c=texcoord+float2(0.5*OrgSize.z/4.0,0.0);
  1693. float phase= ( ntsc_phase<1.5)?((OrgSize.x>300.0)?2.0:3.0):((ntsc_phase>2.5)?3.0:2.0);
  1694. if(ntsc_phase==4.0){phase=3.0;luma_filter_3_phase=luma_filter_4_phase;}
  1695. float3 wsum =0.0.xxx;
  1696. float3 sums=wsum;
  1697. float3 tmps=wsum;
  1698. float offset=0.0;int i=0;
  1699. float j =0.0;
  1700. if(phase<2.5)
  1701. {
  1702. float loop=max(ntsc_taps,8.0);
  1703. if(ntsc_charp1>0.25)loop=min(loop,14.0);
  1704. float loob=loop+1.0;
  1705. float taps=0.0;
  1706. float ssub=loop-loop/ntsc_cscale1;
  1707. float mit=1.0+0.0375*pow(swoothstep(16.0,8.0,loop),0.5);
  1708. float2 dx=float2(one.x*mit,0.0);
  1709. float2 xd=dx; int loopstart=int(TAPS_2_phase-loop);
  1710. for(i=loopstart;i<32;i++)
  1711. {
  1712. offset=float(i-loopstart);
  1713. j=offset+1.0;xd= (offset-loop)*dx;
  1714. sums=fetch_offset1(xd);
  1715. taps=max(j-ssub,0.0);
  1716. tmps=float3(luma_filter_2_phase[i], taps.xx );
  1717. wsum=wsum+tmps; signal+=sums*tmps;
  1718. }
  1719. taps=loob-ssub;
  1720. tmps=float3(luma_filter_2_phase[TAPS_2_phase], taps.xx);
  1721. wsum=wsum+wsum+tmps;
  1722. signal+=texCD(NTSC_S02,tex_c).xyz*tmps;
  1723. signal =signal/wsum;
  1724. }else
  1725. {
  1726. float loop=min(ntsc_taps,TAPS_3_phase); one.y=one.y/ntsc_cscale2;
  1727. float mit=1.0;
  1728. if(ntsc_phase==4.0){loop=max(loop,8.0); mit=1.0+0.0375*pow(swoothstep(16.0,8.0,loop),0.5);}
  1729. float3 dx=float3(one.x,one.y,0.0);
  1730. float3 xd=dx; int loopstart=int(TAPS_3_phase-loop);
  1731. dx.x*=mit;
  1732. for(i=loopstart;i<24;i++)
  1733. {
  1734. offset=float(i-loopstart);
  1735. j=offset+1.0;xd.xy=(offset-loop)*dx.xy;
  1736. sums=fetch_offset2(xd);
  1737. tmps=float3(luma_filter_3_phase[i], chroma_filter_3_phase[i].xx);
  1738. wsum=wsum+tmps; signal+=sums*tmps;
  1739. }
  1740. tmps=float3(luma_filter_3_phase[TAPS_3_phase], chroma_filter_3_phase[TAPS_3_phase], chroma_filter_3_phase[TAPS_3_phase]);
  1741. wsum=wsum+wsum+tmps;
  1742. signal+=texCD(NTSC_S02,tex_c).xyz*tmps;
  1743. signal =signal/wsum;
  1744. }
  1745. signal.x=clamp( signal.x,0.0,1.0);
  1746. if(ntsc_ring>0.05)
  1747. {
  1748. float2 dx=float2(OrgSize.z/min(res,1.0),0.0);
  1749. float a=texCD(NTSC_S02,tex_c-2.0*dx).a;
  1750. float b=texCD(NTSC_S02,tex_c- dx).a;
  1751. float c=texCD(NTSC_S02,tex_c+2.0*dx).a;
  1752. float d=texCD(NTSC_S02,tex_c+ dx).a;
  1753. float e=texCD(NTSC_S02,tex_c ).a;
  1754. 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);
  1755. }
  1756. float x=get_luma(texCD(NTSC_S01, tex_c).rgb);
  1757. return float4(signal,x);
  1758. }
  1759.  
  1760. float4 Signal_3_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1761. {
  1762. float2 dx=float2(0.25*OrgSize.z/4.0,0.0);
  1763. float2 xx=float2(0.50*OrgSize.z,0.0);
  1764. float2 tex_c=texcoord+float2(0.5*OrgSize.z/4.0,0.0);float2 tcoord=tex_c-2.0*dx;
  1765. float2 tcoorb=(floor(OrgSize.xy*tex_c)+0.5)*OrgSize.zw;
  1766. float lcoord=OrgSize.x*(tex_c.x+dx.x )-0.5;
  1767. float fpx=frac(lcoord);
  1768. lcoord =(floor(lcoord)+0.5)*OrgSize.z;
  1769. float3 ll1=texCD(NTSC_S03,tcoord+ xx).xyz;
  1770. float3 ll2=texCD(NTSC_S03,tcoord- xx).xyz;
  1771. float dy=0.0;
  1772. xx=float2(OrgSize.z,0.0);
  1773. float phase= (ntsc_phase<1.5)?((OrgSize.x>300.0)? 2.0:3.0):((ntsc_phase>2.5)?3.0:2.0);
  1774. if(ntsc_phase==4.0)phase=3.0;
  1775. float ca=texCD(NTSC_S02,tcoorb-xx-xx).a;
  1776. float c0=texCD(NTSC_S02,tcoorb-xx ).a;
  1777. float c1=texCD(NTSC_S02,tcoorb ).a;
  1778. float c2=texCD(NTSC_S02,tcoorb+xx ).a;
  1779. float cb=texCD(NTSC_S02,tcoorb+xx+xx).a;
  1780. float th=(phase<2.5)?0.025:0.0075;
  1781. float line0= swoothstep(th,0.0,min(abs(c1-c0),abs(c2-c1)));
  1782. float line1=max(swoothstep(th,0.0,min(abs(ca-c0),abs(c2-cb))), line0 );
  1783. float line2=max(swoothstep(th,0.0,min(abs(ca-c2),abs(c0-cb))), line1 );
  1784. if( ntsc_rainbow>0.5&&phase<2.5)
  1785. {
  1786. float ybool1=1.0;bool ybool2=(c0==c1&&c1==c2);
  1787. if((ntsc_rainbow<1.5)&&bool(line0))ybool1=0.0;else
  1788. if((ntsc_rainbow<2.5)&&bool(line2))ybool1=0.0;else
  1789. if(ybool2)ybool1=0.0;
  1790. float liine_no=floor( mod(OrgSize.y*texcoord.y,2.0));
  1791. float frame_no=floor( mod(float(framecount),2.0));
  1792. float ii=abs(liine_no-frame_no);
  1793. dy=ii*OrgSize.w*ybool1;
  1794. }
  1795. float3 ref=texCD(NTSC_S03,tcoord).xyz;
  1796. float2 org=ref.yz;
  1797. ref.yz= texCD(NTSC_S03,tcoord+float2(0.0,dy)).yz;
  1798. float lum1=min(texCD(NTSC_S02,tex_c-dx).a, texCD(NTSC_S02,tex_c+dx).a);
  1799. float lum2=ref.x ;
  1800. float3 ll3=abs(ll1-ll2);
  1801. float di=max(max(ll3.x,ll3.y),max(ll3.z,abs(ll1.x*ll1.x-ll2.x*ll2.x)));
  1802. float df=pow(di,0.125);
  1803. float lc=swoothstep(0.20,0.10,abs(lum2-lum1))*df;
  1804. float tmp1=swoothstep(0.05-0.03*lc,0.425-0.375*lc,di);
  1805. float tmp2=pow((tmp1+0.1)/1.1,0.25);
  1806. float sweight=lerp(tmp1,tmp2,line0);
  1807. float zweight=lerp(tmp1,tmp2,line2);
  1808. float3 signal=ref;
  1809. float ntzc_shrp= abs(ntsc_shrp);
  1810. if(ntzc_shrp>0.25)
  1811. {
  1812. float mixer=sweight;
  1813. if(ntsc_shrp>0.25)mixer=zweight; mixer*=0.1*ntzc_shrp;
  1814. float lumix=lerp(lum2,lum1,mixer);
  1815. float lm1=lerp(lum2*lum2 ,lum1*lum1 ,mixer);lm1=sqrt(lm1);
  1816. float lm2=lerp(sqrt(lum2),sqrt(lum1),mixer);lm2=lm2* lm2 ;
  1817. float k1=abs(lumix-lm1)+0.00001;
  1818. float k2=abs(lumix-lm2)+0.00001;
  1819. signal.x=min((k2*lm1+k1*lm2)/(k1+k2),1.0);
  1820. signal.x=min(signal.x,max(ntsc_shpe*signal.x,lum2));
  1821. }
  1822. if((ntsc_charp1+ntsc_charp2)>0.25)
  1823. {
  1824. float mixer=sweight;
  1825. if(ntsc_shrp>0.25)mixer=zweight;
  1826. mixer =lerp(swoothstep(0.075,0.125,max(ll3.y,ll3.z)),swoothstep(0.015,0.0275,di),line2)*mixer;
  1827. mixer*=0.1*((phase<2.5)? ntsc_charp1:ntsc_charp2);
  1828. tcoord=float2(lcoord,tcoord.y);
  1829. 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)));
  1830. signal.yz=lerp(signal.yz,origin.yz,mixer);
  1831. }
  1832. if(ntsc_rainbow==2.0&&phase<2.5){signal.yz=lerp(signal.yz,org,zweight);}
  1833. signal.x=pow(signal.x,1.0/ntsc_gamma);
  1834. signal=clamp(yiq2rgb(signal),0.0,1.0);
  1835. return float4(signal,1.0);
  1836. }
  1837.  
  1838. float4 SharpnessPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1839. {
  1840. float2 g01=float2(-0.5*OrgSize.z,0.0);
  1841. float2 g21=float2( 0.5*OrgSize.z,0.0);
  1842. float3 c01=texCD(NTSC_S04,texcoord+g01).rgb;
  1843. float3 c21=texCD(NTSC_S04,texcoord+g21).rgb;
  1844. float3 c11=texCD(NTSC_S04,texcoord ).rgb;
  1845. float3 b11=0.5*(c01+c21);
  1846. float contrazt=max(max(c11.r,c11.g),c11.b);
  1847. contrazt=lerp(2.0*CCONTR,CCONTR,contrazt);
  1848. float3 nim=min(min(c01,c21),c11);float3 mn1=min(nim,c11*(1.0-contrazt));
  1849. float3 xam=max(max(c01,c21),c11);float3 mx1=max(xam,c11*(1.0+contrazt));
  1850. float3 di0=pow(mx1-mn1+0.00001,0.75);
  1851. float3 sharpen=lerp(CSHARPEN*CDETAILS,CSHARPEN,di0);
  1852. float3 res=clamp(lerp(c11,b11,-sharpen),mn1,mx1);
  1853. if(DEBLUR>1.125)
  1854. {
  1855. float2 toxcoord=(floor(OrgSize.xy*texcoord)+0.5)*OrgSize.zw;
  1856. float l01=get_luma(texCD(NTSC_S01,texcoord+2.0*g01).rgb);
  1857. float l21=get_luma(texCD(NTSC_S01,texcoord+2.0*g21).rgb);
  1858. float l11=get_luma(texCD(NTSC_S01,toxcoord ).rgb);
  1859. float d11=min(min(l01,l21),l11);
  1860. l11=max(max(l01,l21),l11);
  1861. float lmn=get_luma(nim);
  1862. float lmx=get_luma(xam);
  1863. float ln1=min(lerp(d11,lmn,lmn),lmn);
  1864. float lx1=max(lerp(lmx,l11,lmx),lmx);
  1865. float r11=get_luma(res);
  1866. float di1=max((r11-ln1),0.0)+0.00001;di1=pow(di1,DEBLUR);
  1867. float di2=max((lx1-r11),0.0)+0.00001;di2=pow(di2,DEBLUR);
  1868. float ratio=di1/(di1+di2);
  1869. float zharpen=lerp(ln1,lx1,ratio);
  1870. zharpen=min(zharpen,max(DREDGE*zharpen,r11));
  1871. res=rgb2yiq(res);
  1872. d11=res.x;
  1873. res.x=zharpen;
  1874. res.x=clamp((1.0+ DSHARP)* res.x-DSHARP*d11,ln1*(1.0-contrazt),lx1*(1.0+contrazt));
  1875. res=max(yiq2rgb(res),0.0);
  1876. }
  1877. return float4(res,1.0);
  1878. }
  1879.  
  1880. float4 LuminancePS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1881. {
  1882. float m=max(log2(LumSize.x),log2(LumSize.y));
  1883. m=floor(max(m,1.0))-1.0;
  1884. float2 dx=float2(1.0/LumSize.x,0.0);
  1885. float2 dy=float2(0.0,1.0/LumSize.y);
  1886. float2 x2=2.0*dx;
  1887. float2 y2=2.0*dy;
  1888. float ltotal=0.0;
  1889. ltotal+=length(tex2Dlod(NTSC_S05,float4(float2(0.3,0.3),m,0)).rgb);
  1890. ltotal+=length(tex2Dlod(NTSC_S05,float4(float2(0.3,0.7),m,0)).rgb);
  1891. ltotal+=length(tex2Dlod(NTSC_S05,float4(float2(0.7,0.3),m,0)).rgb);
  1892. ltotal+=length(tex2Dlod(NTSC_S05,float4(float2(0.7,0.7),m,0)).rgb);
  1893. ltotal*=0.25;
  1894. ltotal=pow(0.577350269*ltotal,0.7);
  1895. float lhistory=texCD(NTSC_S06,float2(0.5,0.5)).a;
  1896. ltotal=lerp(ltotal,lhistory,lsmooth);
  1897. float3 l1=texCD(NTSC_S05,fuxcoord.xy ).rgb;
  1898. float3 r1=texCD(NTSC_S05,fuxcoord.xy+dx).rgb;
  1899. float3 l2=texCD(NTSC_S05,fuxcoord.xy-dx).rgb;
  1900. float3 r2=texCD(NTSC_S05,fuxcoord.xy+x2).rgb;
  1901. float c1=dist(l2,l1);
  1902. float c2=dist(l1,r1);
  1903. float c3=dist(r2,r1);
  1904. return float4(c1,c2,c3,ltotal);
  1905. }
  1906.  
  1907. float4 LinearizePS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1908. {
  1909. float3 c1=texCD(NTSC_S05,fuxcoord).rgb;
  1910. float3 c2=texCD(NTSC_S05,fuxcoord+float2(0.0,OrgSize.w)).rgb;
  1911. if((downsample_levelx+downsample_levely)>0.025)
  1912. {
  1913. c1=fetch_pixel(fuxcoord);
  1914. c2=fetch_pixel(fuxcoord+float2(0.0,OrgSize.w));
  1915. }
  1916. float3 c=c1;
  1917. float intera=1.0;
  1918. float gamma_in=gamma_i;
  1919. float m1=max(max(c1.r,c1.g),c1.b);
  1920. float m2=max(max(c2.r,c2.g),c2.b);
  1921. float3 df=abs(c1-c2);
  1922. float d=max(max(df.r,df.g),df.b);
  1923. if(interm==2.0) d=lerp(0.1*d,10.0*d,step(m1/(m2+0.0001),m2/(m1+0.0001)));
  1924. float r=m1;
  1925. float yres_div=1.0;if(intres>1.25)yres_div=intres;
  1926. bool hscans=(hiscan>0.5);
  1927. if(interr<=OrgSize.y/yres_div&&interm>0.5&&intres!=1.0&&intres!=0.5||hscans)
  1928. {
  1929. intera=0.25;
  1930. float liine_no=floor( mod(OrgSize.y*fuxcoord.y,2.0));
  1931. float frame_no=floor( mod(float(framecount),2.0));
  1932. float ii=abs(liine_no-frame_no);
  1933. if(interm< 3.5)
  1934. {
  1935. c2=plant(lerp(c2,c2*c2,iscans),max(max(c2.r,c2.g),c2.b));
  1936. r=max(m1*ii,(1.0-iscanb)*min(m1,m2));
  1937. 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);
  1938. if(interm==3.0) c=(1.0-0.5*iscanb)*lerp(c2,c1,ii);
  1939. }
  1940. 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);
  1941. }
  1942. 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);
  1943. }
  1944. if(hscans)c=c1;
  1945. }
  1946. c=pow(c,gamma_in);
  1947. if(fuxcoord.x>0.5)gamma_in=intera;else gamma_in=1.0/gamma_in;
  1948. return float4(c,gamma_in);
  1949. }
  1950.  
  1951. float4 HGaussianPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1952. {
  1953. float FINE_GAUSS= (FINE_GAUSS>0.5)? FINE_GAUSS: lerp(0.75,0.50,-FINE_GAUSS);
  1954. float4 AdvSize=float4(OrgSize.x,OrgSize.y,OrgSize.z,OrgSize.w)*float4(FINE_GAUSS,FINE_GAUSS,1.0/FINE_GAUSS,1.0/FINE_GAUSS);
  1955. float f=frac(AdvSize.x*texcoord.x);
  1956. f=0.5-f;
  1957. float2 tex=floor(AdvSize.xy*texcoord)*AdvSize.zw+0.5*AdvSize.zw;
  1958. float3 color=0.0;
  1959. float2 dx=float2(AdvSize.z ,0.0);
  1960. float3 pixel;
  1961. float w;
  1962. float wsum=0.0;
  1963. float n=-SIZEH;
  1964. do
  1965. {
  1966. pixel=texCD(NTSC_S07,tex+n*dx).rgb;
  1967. if(m_glow>0.5)
  1968. {
  1969. pixel=max(pixel-m_glow_cutoff,0.0);
  1970. pixel=plant(pixel,max(max(max(pixel.r,pixel.g),pixel.b)-m_glow_cutoff,0.0));
  1971. }
  1972. w=gauss_h(n+f);
  1973. color=color+w*pixel;
  1974. wsum=wsum+w;
  1975. n=n+1.0;
  1976. }
  1977. while(n<=SIZEH);
  1978. color=color/wsum;
  1979. return float4(color,1.0);
  1980. }
  1981.  
  1982. float4 VGaussianPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1983. {
  1984. float FINE_GAUSS= (FINE_GAUSS>0.5)? FINE_GAUSS: lerp(0.75,0.50,-FINE_GAUSS);
  1985. float4 AdvSize=float4(SrcSize.x,OrgSize.y,SrcSize.z,OrgSize.w)*float4(FINE_GAUSS,FINE_GAUSS,1.0/FINE_GAUSS,1.0/FINE_GAUSS);
  1986. float f=frac(AdvSize.y*texcoord.y);
  1987. f=0.5-f;
  1988. float2 tex=floor(AdvSize.xy*texcoord)*AdvSize.zw+0.5*AdvSize.zw;
  1989. float3 color=0.0;
  1990. float2 dy=float2(0.0,AdvSize.w );
  1991. float3 pixel;
  1992. float w;
  1993. float wsum=0.0;
  1994. float n=-SIZEV;
  1995. do
  1996. {
  1997. pixel=texCD(NTSC_S09,tex+n*dy).rgb;
  1998. w=gauss_v(n+f);
  1999. color=color+w*pixel;
  2000. wsum=wsum+w;
  2001. n=n+1.0;
  2002. }
  2003. while(n<=SIZEV);
  2004. color=color/wsum;
  2005. return float4(color,1.0);
  2006. }
  2007.  
  2008. float4 BloomHorzPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  2009. {
  2010. float FINE_BLOOM= (FINE_BLOOM>0.5)? FINE_BLOOM: lerp(0.75,0.50,-FINE_BLOOM);
  2011. float4 AdvSize=float4(OrgSize.x,OrgSize.y,OrgSize.z,OrgSize.w)*float4(FINE_BLOOM,FINE_BLOOM,1.0/FINE_BLOOM,1.0/FINE_BLOOM);
  2012. float f=frac(AdvSize.x*texcoord.x);
  2013. f=0.5-f;
  2014. float2 tex=floor(AdvSize.xy*texcoord)*AdvSize.zw+0.5*AdvSize.zw;
  2015. float4 color=0.0;
  2016. float2 dx=float2(AdvSize.z ,0.0);
  2017. float4 pixel;
  2018. float w;
  2019. float wsum=0.0;
  2020. float n=-SIZEX;
  2021. do
  2022. {
  2023. pixel=texCD(NTSC_S07,tex+n*dx);
  2024. w=bloom_h(n+f);
  2025. pixel.a =max(max(pixel.r,pixel.g),pixel.b);
  2026. pixel.a*=pixel.a*pixel.a;
  2027. color=color+w*pixel;
  2028. wsum=wsum+w;
  2029. n=n+1.0;
  2030. }
  2031. while(n<=SIZEX);
  2032. color=color/wsum;
  2033. return float4(color.rgb,pow(color.a,0.333333));
  2034. }
  2035.  
  2036. float4 BloomVertPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  2037. {
  2038. float FINE_BLOOM= (FINE_BLOOM>0.5)? FINE_BLOOM: lerp(0.75,0.50,-FINE_BLOOM);
  2039. float4 AdvSize=float4(SrcSize.x,OrgSize.y,SrcSize.z,OrgSize.w)*float4(FINE_BLOOM,FINE_BLOOM,1.0/FINE_BLOOM,1.0/FINE_BLOOM);
  2040. float f=frac(AdvSize.y*texcoord.y);
  2041. f=0.5-f;
  2042. float2 tex=floor(AdvSize.xy*texcoord)*AdvSize.zw+0.5*AdvSize.zw;
  2043. float4 color=0.0;
  2044. float2 dy=float2(0.0,AdvSize.w );
  2045. float4 pixel;
  2046. float w;
  2047. float wsum=0.0;
  2048. float n=-SIZEY;
  2049. do
  2050. {
  2051. pixel=texCD(NTSC_S11,tex+n*dy);
  2052. w=bloom_v(n+f);
  2053. pixel.a*=pixel.a*pixel.a;
  2054. color=color+w*pixel;
  2055. wsum=wsum+w;
  2056. n=n+1.0;
  2057. }
  2058. while(n<=SIZEY);
  2059. color=color/wsum;
  2060. return float4(color.rgb,pow(color.a,0.175000));
  2061. }
  2062.  
  2063. float4 NTSC_TV1_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  2064. {
  2065. float f=frac(LumSize.x*fuxcoord.x);
  2066. f=0.5-f;
  2067. float2 tex=floor(LumSize.xy*fuxcoord)*LumSize.zw+0.5*LumSize.zw;
  2068. float3 color=0.0.xxx;
  2069. float solor=0.0;
  2070. float2 dx=float2(LumSize.z ,0.0);
  2071. float3 pixel;
  2072. float w=0.0;
  2073. float swum=0.0;
  2074. float wsum=0.0;
  2075. float xs=2.0*0.50;
  2076. float hsharpness=HSHARPNESS*xs*internal_res;
  2077. float3 cmax=0.0.xxx;
  2078. float3 cmin=1.0.xxx;
  2079. float sharp=crthd_h(hsharpness,xs) *S_SHARP;
  2080. float maxsharp=MAXS;
  2081. float FPR=hsharpness;
  2082. float FPRi=1.0/hsharpness;
  2083. float fpx=0.0;
  2084. float sp=0.0;
  2085. float sw=0.0;
  2086. float ts=0.025;
  2087. float3 luma=float3(0.2126,0.7152,0.0722);
  2088. float LOOPSIZE=ceil(2.0*FPR);
  2089. float n=-LOOPSIZE;
  2090. do
  2091. {
  2092. pixel=texCD(NTSC_S07,tex+n*dx).rgb;
  2093. w=crthd_h(n+f,xs)-sharp;
  2094. fpx=(abs(n+f)-FPR)*FPRi;
  2095. if(w<0.0)w=max(w,lerp(-maxsharp,0.0,pow(clamp(fpx,0.0,1.0),SHARP))); else
  2096. {
  2097. cmax=max(cmax,pixel);cmin=min(cmin,pixel);sw=w*(dot(pixel,luma)+ts);
  2098. sp=max(max(pixel.r,pixel.g),pixel.b);
  2099. solor=solor+sw*sp;
  2100. swum=swum+sw;
  2101. }
  2102. color=color+w*pixel;
  2103. wsum=wsum+w;
  2104. n=n+1.0;
  2105. }
  2106. while(n<=LOOPSIZE);
  2107. color=color/wsum;
  2108. solor=solor/swum;
  2109. color=clamp(lerp( clamp (color,cmin,cmax),color,SSRNG),0.0,1.0);
  2110. solor=clamp(lerp(max(max(color.r,color.g),color.b),solor,spike),0.0,1.0);
  2111. return float4(color,solor);
  2112. }
  2113.  
  2114. float4 NTSC_TV2_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  2115. {
  2116. float gamma_in=1.0/texCD(NTSC_S07,float2(0.25,0.25)).a;
  2117. float lum=texCD(NTSC_S06,float2(0.5,0.5)).a;
  2118. float intera=texCD(NTSC_S07,float2(0.75,0.25)).a;
  2119. bool hscans=(hiscan>0.5);
  2120. bool interb=(((intera<0.35)||(no_scanlines>0.025))&&!hscans);
  2121. float4 AdvSize= LumSize;
  2122. float SourceY=AdvSize.y;
  2123. float sy=1.0;
  2124. if( intres==1.0)sy=max(round(SourceY/224.0),1.0);
  2125. if( intres>0.25&&intres!=1.0)sy=intres;
  2126. AdvSize*=float4(1.0,1.0/sy,1.0,sy);
  2127. float2 lexcoord=fuxcoord.xy;
  2128. if(IOS> 0.0&& !interb)
  2129. {
  2130. float2 ofactor= OptSize.xy/OrgSize.xy;
  2131. float2 ifactor=(IOS<2.5)? floor(ofactor):ceil(ofactor);
  2132. float2 diff=ofactor/ifactor;
  2133. float scan=diff.y;
  2134. lexcoord=overscan(lexcoord,scan,scan);
  2135. if(IOS==1.0||IOS==3.0) lexcoord=float2(fuxcoord.x,lexcoord.y);
  2136. }
  2137. float factor=1.0+(1.0-0.5*OS)*blm_2/100.0-lum*blm_2/100.0;
  2138. lexcoord=overscan(lexcoord,factor,factor);
  2139. lexcoord=overscan(lexcoord,(OrgSize.x-overscanx)/OrgSize.x,(OrgSize.y-overscany)/OrgSize.y);
  2140. float2 pos = warp(lexcoord);
  2141. float2 coffset=0.5;
  2142. float2 ps=AdvSize.zw;
  2143. float2 OGL2Pos=pos*AdvSize.xy-coffset;
  2144. float2 fp=frac(OGL2Pos);
  2145. float2 dx=float2(ps.x,0.0);
  2146. float2 dy=float2(0.0,ps.y);
  2147. float f=fp.y;
  2148. float2 pC4=floor(OGL2Pos)*ps+0.5*ps;
  2149. pC4.x=pos.x;
  2150. if( intres==0.5<1.5)pC4.y=floor(pC4.y*OrgSize.y)*OrgSize.w+0.5*OrgSize.w;
  2151. if( interb&&no_scanlines<0.025|| hscans) pC4.y=pos.y;else
  2152. if( interb) pC4.y=pC4.y+smoothstep(0.40-0.5*no_scanlines,0.60+0.5*no_scanlines,f)*AdvSize.w;
  2153. float3 color1=texCD(NTSC_S08,pC4).rgb;
  2154. float3 solor1=texCD(NTSC_S08,pC4).aaa;
  2155. if(!interb)color1=pow(color1,scangamma/gamma_in);
  2156. pC4+=dy;
  2157. if( intres==0.5<1.5)pC4.y=floor((pos.y+0.33*dy.y)*OrgSize.y)*OrgSize.w+0.5*OrgSize.w;
  2158. float3 color2=texCD(NTSC_S08,pC4).rgb;
  2159. float3 solor2=texCD(NTSC_S08,pC4).aaa;
  2160. if(!interb)color2=pow(color2,scangamma/gamma_in);
  2161. float3 ctmp=color1;float w3=1.0;float3 color=color1;
  2162. float3 one=1.0;
  2163. if( hscans){color2=color1;solor2=solor1;}
  2164. if(!interb|| hscans)
  2165. {
  2166. float shape1=lerp(scanline1,scanline2, f);
  2167. float shape2=lerp(scanline1,scanline2,1.0-f);
  2168. float wt1=st0( f);
  2169. float wt2=st0(1.0-f);
  2170. float3 color0=color1*wt1+color2*wt2;
  2171. float3 solor0=solor1*wt1+solor2*wt2;
  2172. ctmp = color0/(wt1+wt2);
  2173. float3 stmp=solor0/(wt1+wt2);
  2174. if(abs(rolling_scan)>0.005){color1=ctmp;color2=ctmp;solor1=stmp;solor2=stmp;}
  2175. float3 w1,w2;
  2176. float3 cref1=lerp(stmp,solor1,beam_size);float creff1=pow(max(max(cref1.r,cref1.g),cref1.b),scan_falloff);
  2177. float3 cref2=lerp(stmp,solor2,beam_size);float creff2=pow(max(max(cref2.r,cref2.g),cref2.b),scan_falloff);
  2178. if(tds>0.5){shape1=lerp(scanline2,shape1,creff1);shape2=lerp(scanline2,shape2,creff2);}
  2179. float scanpix=OrgSize.y/OptSize.y;
  2180. float f1=frac(f-rolling_scan*float(framecount)*scanpix);
  2181. float f2=1.0-f1;
  2182. float m1=max(max(color1.r,color1.g),color1.b)+eps;
  2183. float m2=max(max(color2.r,color2.g),color2.b)+eps;
  2184. cref1=color1/m1;
  2185. cref2=color2/m2;
  2186. if(gsl< 0.5)
  2187. {w1=sw0(f1,creff1,shape1,cref1);w2=sw0(f2,creff2,shape2,cref2);}else
  2188. if(gsl==1.0)
  2189. {w1=sw1(f1,creff1,shape1,cref1);w2=sw1(f2,creff2,shape2,cref2);}else
  2190. {w1=sw2(f1,creff1,shape1,cref1);w2=sw2(f2,creff2,shape2,cref2);}
  2191. float3 w3=w1+w2;
  2192. float wf1=max(max(w3.r,w3.g),w3.b);
  2193. if(wf1>1.0){wf1=1.0/wf1;w1*=wf1,w2*=wf1;}
  2194. if(abs(clp)>0.005)
  2195. {
  2196. sy=m1; one=(clp>0.0)?w1:1.0.xxx;
  2197. float sat=1.0001-min(min(cref1.r,cref1.g),cref1.b);
  2198. color1=lerp(color1,plant(pow(color1,0.70.xxx-0.325*sat),sy),pow(sat,0.3333)*one*abs(clp));
  2199. sy=m2; one=(clp>0.0)?w2:1.0.xxx;
  2200. sat=1.0001-min(min(cref2.r,cref2.g),cref2.b);
  2201. color2=lerp(color2,plant(pow(color2,0.70.xxx-0.325*sat),sy),pow(sat,0.3333)*one*abs(clp));
  2202. }
  2203. color=gc1(color1)*w1+gc1(color2)*w2;
  2204. color=min(color,1.0);
  2205. }
  2206. if( interb)
  2207. {
  2208. color=gc1(color1);
  2209. }
  2210. float colmx=max( max(ctmp.r,ctmp.g),ctmp.b);
  2211. if(!interb)color=pow(color,gamma_in/scangamma);
  2212. return float4(color,colmx);
  2213. }
  2214.  
  2215. float4 ChromaticPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  2216. {
  2217. float gamma_in=1.0/texCD(NTSC_S07,float2(0.25,0.25)).a;
  2218. float lum=texCD(NTSC_S06,float2(0.5,0.5)).a;
  2219. float intera=texCD(NTSC_S07,float2(0.75,0.25)).a;
  2220. bool interb=((intera<0.35||no_scanlines>0.025)&&(hiscan<0.5));
  2221. float2 lexcoord=fuxcoord.xy;
  2222. if(IOS> 0.0&& !interb)
  2223. {
  2224. float2 ofactor= OptSize.xy/OrgSize.xy;
  2225. float2 ifactor=(IOS<2.5)? floor(ofactor):ceil(ofactor);
  2226. float2 diff=ofactor/ifactor;
  2227. float scan=diff.y;
  2228. lexcoord=overscan(lexcoord,scan,scan);
  2229. if(IOS==1.0||IOS==3.0) lexcoord=float2(fuxcoord.x,lexcoord.y);
  2230. }
  2231. float factor=1.0+(1.0-0.5*OS)*blm_2/100.0-lum*blm_2/100.0;
  2232. lexcoord=overscan(lexcoord,factor,factor);
  2233. lexcoord=overscan(lexcoord,(OrgSize.x-overscanx)/OrgSize.x,(OrgSize.y-overscany)/OrgSize.y);
  2234. float2 pos0= warp(fuxcoord);
  2235. float2 pos1= fuxcoord;
  2236. float2 pos = warp(lexcoord);
  2237. float3 color=texCD(NTSC_S13,pos1).rgb;
  2238. float3 Bloom=texCD(NTSC_S12,pos ).rgb;
  2239. float3 Glow =texCD(NTSC_S10,pos ).rgb;
  2240. if((abs(deconrx)+abs(deconry)+abs(decongx)+abs(decongy)+abs(deconbx)+abs(deconby))>0.2) bring_pixel(color,Bloom,Glow,pos1,pos);
  2241. float cm=igc(max(max(color.r,color.g),color.b));
  2242. float mx1=texCD(NTSC_S13,pos1 ).a;
  2243. float colmx=max(mx1,cm);
  2244. float w3=min((max((cm-0.0005)*1.0005,0.0)+0.0001)/(colmx+0.0005),1.0);if(interb)w3=1.0;
  2245. float2 dx=float2(0.001,0.0);
  2246. float mx0=texCD(NTSC_S13,pos1-dx).a;
  2247. float mx2=texCD(NTSC_S13,pos1+dx).a;
  2248. float mxg=max(max(mx0,mx1),max(mx2,cm));
  2249. float mx=pow(mxg,1.40/gamma_in);
  2250. float cx=pow(colmx,1.40/gamma_in);
  2251. dx=float2(OrgSize.z,0.0)*0.25;
  2252. mx0=texCD(NTSC_S13,pos1-dx).a;
  2253. mx2=texCD(NTSC_S13,pos1+dx).a;
  2254. float mb=(1.0-min(abs(mx0-mx2)/(0.5+mx1),1.0));
  2255. float3 orig1=color;
  2256. float3 one=1.0;
  2257. float3 cmask=one;
  2258. float3 dmask=one;
  2259. float3 emask=one;
  2260. 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};
  2261. float mwidth=mwidths[int(shadow_msk)];
  2262. float mask_compensate=frac(mwidth);
  2263. if(shadow_msk> 0.5)
  2264. {
  2265. float2 maskcoord= fracoord.xy;
  2266. float2 scoord=maskcoord;
  2267. mwidth=floor(mwidth)*masksize;
  2268. float swidth=mwidth;
  2269. bool zoomed=(abs(mask_zoom)>0.75);
  2270. float mscale=1.0;
  2271. float2 maskcoord0=maskcoord;
  2272. maskcoord.y=floor(maskcoord.y/masksize);
  2273. float mwidth0=max(mwidth+mask_zoom,2.0);
  2274. if( mshift> 0.25)
  2275. {
  2276. float stagg_lvl=1.0; if(frac(mshift)>0.25)stagg_lvl=2.0;
  2277. float next_line=float(floor(mod(maskcoord.y,2.0*stagg_lvl))<stagg_lvl);
  2278. maskcoord0.x=maskcoord0.x+next_line*0.5*mwidth0;
  2279. }
  2280. maskcoord=maskcoord0/masksize;
  2281. if(!zoomed)cmask*=crt_mask(floor(maskcoord),mx,mb);else
  2282. {
  2283. mscale=mwidth0/mwidth;
  2284. 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);
  2285. float coord=floor(maskcoord.x/mscale); if(shadow_msk==13.0&&mask_zoom==-2.0)coord=ceil(maskcoord.x/mscale);
  2286. cmask*=lerp(crt_mask(float2(coord,maskcoord.y),mx,mb),crt_mask(float2(coord+1.0,maskcoord.y),mx,mb),clerp);
  2287. }
  2288. if(slotwidth>0.5)swidth=slotwidth;float smask=1.0;
  2289. 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);
  2290. if( zoomed)
  2291. {
  2292. if(mask_layout<0.5&&bsm_offset)sm_offset=1.0;else
  2293. if(bsm_offset)sm_offset=-1.0;
  2294. }
  2295. swidth=round(swidth*mscale);
  2296. smask =slt_mask(scoord+float2(sm_offset,0.0),mx,swidth);
  2297. smask =clamp(smask+lerp(smask_mit,0.0,w3*pow(colmx,0.3)),0.0,1.0);
  2298. emask =cmask;
  2299. cmask*=smask;
  2300. dmask =cmask;
  2301. if(abs(mask_bloom)>0.025)
  2302. {
  2303. float maxbl=max( max(max(Bloom.r,Bloom.g),Bloom.b),mxg);
  2304. maxbl=maxbl*max(lerp(1.0,2-colmx,bloom_dist),0.0);
  2305. if(mask_bloom>0.025) cmask= max(min(cmask +maxbl*mask_bloom,1),cmask); else
  2306. cmask=max(lerp(cmask,cmask*(1.0-0.5*maxbl)+plant(pow( Bloom,0.35.xxx),maxbl),-mask_bloom),cmask);
  2307. }
  2308. color=pow(color,mask_gamma/gamma_in);
  2309. color=color*cmask;
  2310. color=min(color,1.0);
  2311. color=pow(color,gamma_in/mask_gamma);
  2312. cmask=min(cmask,1.0);
  2313. dmask=min(dmask,1.0);
  2314. float mm=max(-2.75*cx*(cx-1.0)-lerp(0.075,0.165,cx),0.0);color=max(color,orig1*maskmid*mm);
  2315. }
  2316. 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;
  2317. float bb=lerp(brightboost1,brightboost2,mx)* dark_compensate; color*=bb;
  2318. float3 Ref=texCD(NTSC_S07,pos).rgb;
  2319. float maxb=texCD(NTSC_S12,pos).a;
  2320. float3 bcmask=lerp(one,dmask,b_mask);
  2321. float3 hcmask=lerp(one,dmask,h_mask);
  2322. float3 Bloomy=Bloom;
  2323. if(abs(blm_1)>0.025)
  2324. {
  2325. if(blm_1<-0.01)Bloomy=plant(Bloom,maxb);
  2326. Bloomy= min(Bloomy*(orig1+color),max(0.5*(colmx+orig1-color),0.001*Bloomy));
  2327. Bloomy=0.5*(Bloomy+lerp(Bloomy,lerp(colmx*orig1,Bloomy,0.5),1.0-color));
  2328. Bloomy= bcmask*Bloomy*max(lerp(1.0,2.0-colmx,bloom_dist),0);
  2329. color=pow(pow(color,mask_gamma/gamma_in)+abs(blm_1)*pow( Bloomy,mask_gamma/gamma_in),gamma_in/mask_gamma);
  2330. }
  2331. if(halation> 0.01)
  2332. {
  2333. Bloom= 0.5*(Bloom+Bloom*Bloom);float mbl=max(max(Bloom.r,Bloom.g),Bloom.b);float mxh=0.5*(colmx+colmx*colmx);
  2334. mbl=lerp(lerp(mxh,lerp( mxh,mbl,mbl),colmx),mbl,mb);
  2335. 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);
  2336. Bloom=(3.0-colmx-color)*plant(0.325+orig1/w3,0.5*(1.0+w3))*hcmask*Bloom;
  2337. color=pow(pow(color,mask_gamma/gamma_in)+ halation *pow( Bloom ,mask_gamma/gamma_in),gamma_in/mask_gamma);
  2338. }else
  2339. if(halation<-0.01)
  2340. {
  2341. float mbl=max(max(Bloom.r,Bloom.g),Bloom.b);
  2342. Bloom=plant(Bloom+Ref+orig1+Bloom*Bloom*Bloom,min(mbl*mbl,0.75));
  2343. color=color+2.0*lerp(1.0,w3,0.5*colmx)*hcmask*Bloom*(-halation);
  2344. }
  2345. color=min(color,1.0);
  2346. color=gc2(color,w3 );
  2347. 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);}
  2348. if(m_glow<0.5)Glow=lerp(Glow,0.25*color,colmx);else
  2349. {
  2350. float3 orig2=plant(orig1+0.001*Ref,1.0); maxb=max(max(Glow.r,Glow.g),Glow.b);
  2351. Bloom=plant(Glow,1.0);Ref=abs(orig2-Bloom);
  2352. mx0=max(max(orig2.r,orig2.g),orig2.b)-min(min(orig2.r,orig2.g),orig2.b);
  2353. mx2=max(max(Bloom.r,Bloom.g),Bloom.b)-min(min(Bloom.r,Bloom.g),Bloom.b);
  2354. 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));
  2355. if(m_glow>1.5)Glow=lerp(0.5*Glow*Glow,Bloom,Bloom);
  2356. Glow=lerp(m_glow_low*Glow,m_glow_high*Bloom,pow(colmx,m_glow_dist/gamma_in));
  2357. }
  2358. if(m_glow<0.5)
  2359. {
  2360. if(glow >=0.0)color=color+0.5*Glow*glow;else color=color+abs(glow)*min(emask*emask,1.0)*Glow;}else
  2361. {
  2362. float3 fmask=clamp(lerp(one,dmask,m_glow_mask),0.0,1.0);
  2363. color=color+abs(glow)*fmask*Glow;
  2364. }
  2365. float vig=vignette(pos);
  2366. color=min(color,1.0);
  2367. if(edgemask>0.05)
  2368. {
  2369. mx0=texCD(NTSC_S13,pos1-dx).a;mx0=texCD(NTSC_S13,pos1-dx*(1.0-0.75*sqrt(mx0))).a;
  2370. mx2=texCD(NTSC_S13,pos1+dx).a;mx2=texCD(NTSC_S13,pos1+dx*(1.0-0.75*sqrt(mx2))).a;
  2371. float mx3=texCD(NTSC_S13,pos1-4.0*dx).a;
  2372. float mx4=texCD(NTSC_S13,pos1+4.0*dx).a;
  2373. mx4=max(pow(abs(mx3-mx4),0.55-0.40*cx),min(max(mx3,mx4)/min(0.1+cx,1.0),1.0));
  2374. mb=(1.0-abs(pow(mx0,1.0-0.65*mx2)-pow(mx2,1.0-0.65*mx0)));
  2375. mb=mx4*edgemask*(1.0001-mb*mb);float3 temp=lerp(color,orig1,mb);
  2376. 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);
  2377. }
  2378. color=color* lerp(1.0,lerp(0.5*(1.0+w3),w3,mx),pr_scan);
  2379. color=min(color,max(orig1,color)*lerp(one,dmask,mclip));
  2380. color=pow(color,1.0/gamma_o);
  2381. float q=0.6*sqrt(max(max(color.r,color.g),color.b))+0.4;
  2382. if(abs(addnoised)>0.01)
  2383. {
  2384. float3 noise0=noise(float3(floor(OptSize.xy*fuxcoord/noiseresd),float(framecount)));
  2385. if(noisetype<0.5)color=lerp(color,noise0,0.25*abs(addnoised)*q);else
  2386. color=min(color* lerp(1.0,1.5*noise0.x,0.5*abs(addnoised)),1.0);
  2387. }
  2388. colmx=max(max(orig1.r,orig1.g),orig1.b);
  2389. color=color+bmask*lerp(emask,0.125*(1.0-colmx)*color,min(20.0*colmx,1.0));
  2390. return float4(color*vig*humbars(lerp(pos.y,pos.x,bardir))*post_br*corner(pos0),1.0);
  2391. }
  2392.  
  2393. technique CRT_Guest_NTSC
  2394. {
  2395. pass StockPass
  2396. {
  2397. VertexShader=PostProcessVS;
  2398. PixelShader=StockPassPS;
  2399. RenderTarget=NTSC_T01;
  2400. }
  2401. pass NTSCPASS1
  2402. {
  2403. VertexShader=PostProcessVS;
  2404. PixelShader=Signal_1_PS;
  2405. RenderTarget=NTSC_T02;
  2406. }
  2407. pass NTSCPASS2
  2408. {
  2409. VertexShader=PostProcessVS;
  2410. PixelShader=Signal_2_PS;
  2411. RenderTarget=NTSC_T03;
  2412. }
  2413. pass NTSCPASS3
  2414. {
  2415. VertexShader=PostProcessVS;
  2416. PixelShader=Signal_3_PS;
  2417. RenderTarget=NTSC_T04;
  2418. }
  2419. pass Sharpness
  2420. {
  2421. VertexShader=PostProcessVS;
  2422. PixelShader=SharpnessPS;
  2423. RenderTarget=NTSC_T05;
  2424. }
  2425. pass Luminance
  2426. {
  2427. VertexShader=PostProcessVS;
  2428. PixelShader=LuminancePS;
  2429. RenderTarget=NTSC_T06;
  2430. }
  2431. pass Linearize
  2432. {
  2433. VertexShader=PostProcessVS;
  2434. PixelShader=LinearizePS;
  2435. RenderTarget=NTSC_T07;
  2436. }
  2437. pass CRT_Pass1
  2438. {
  2439. VertexShader=PostProcessVS;
  2440. PixelShader=NTSC_TV1_PS;
  2441. RenderTarget=NTSC_T08;
  2442. }
  2443. pass GaussianX
  2444. {
  2445. VertexShader=PostProcessVS;
  2446. PixelShader=HGaussianPS;
  2447. RenderTarget=NTSC_T09;
  2448. }
  2449. pass GaussianY
  2450. {
  2451. VertexShader=PostProcessVS;
  2452. PixelShader=VGaussianPS;
  2453. RenderTarget=NTSC_T10;
  2454. }
  2455. pass BloomHorz
  2456. {
  2457. VertexShader=PostProcessVS;
  2458. PixelShader=BloomHorzPS;
  2459. RenderTarget=NTSC_T11;
  2460. }
  2461. pass BloomVert
  2462. {
  2463. VertexShader=PostProcessVS;
  2464. PixelShader=BloomVertPS;
  2465. RenderTarget=NTSC_T12;
  2466. }
  2467. pass CRT_Pass2
  2468. {
  2469. VertexShader=PostProcessVS;
  2470. PixelShader=NTSC_TV2_PS;
  2471. RenderTarget=NTSC_T13;
  2472. }
  2473. pass Chromatic
  2474. {
  2475. VertexShader=PostProcessVS;
  2476. PixelShader=ChromaticPS;
  2477. }
  2478. }
Add Comment
Please, Sign In to add comment