Advertisement
Guest User

CRT-Guest-NTSC (TEST)

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