Guest User

CRT-Guest-HD (DX9 Fix Test)

a guest
Jun 17th, 2023
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.75 KB | None | 0 0
  1. /*
  2.  
  3. CRT - Guest - HD (Copyright (C) 2018-2023 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 ResolutionX <
  23. ui_label = "Resolution X";
  24. > = 320.0;
  25.  
  26. uniform float ResolutionY <
  27. ui_label = "Resolution Y";
  28. > = 240.0;
  29.  
  30. uniform float PR <
  31. ui_type = "drag";
  32. ui_min = 0.0;
  33. ui_max = 0.5;
  34. ui_step = 0.01;
  35. ui_label = "Persistence Red";
  36. > = 0.32;
  37.  
  38. uniform float PG <
  39. ui_type = "drag";
  40. ui_min = 0.0;
  41. ui_max = 0.5;
  42. ui_step = 0.01;
  43. ui_label = "Persistence Green";
  44. > = 0.32;
  45.  
  46. uniform float PB <
  47. ui_type = "drag";
  48. ui_min = 0.0;
  49. ui_max = 0.5;
  50. ui_step = 0.01;
  51. ui_label = "Persistence Blue";
  52. > = 0.32;
  53.  
  54. uniform float AS <
  55. ui_type = "drag";
  56. ui_min = 0.0;
  57. ui_max = 0.6;
  58. ui_step = 0.01;
  59. ui_label = "Afterglow Strength";
  60. > = 0.2;
  61.  
  62. uniform float sat <
  63. ui_type = "drag";
  64. ui_min = 0.0;
  65. ui_max = 1.0;
  66. ui_step = 0.01;
  67. ui_label = "Afterglow Saturation";
  68. > = 0.5;
  69.  
  70. uniform float CS <
  71. ui_type = "drag";
  72. ui_min = 0.0;
  73. ui_max = 4.0;
  74. ui_step = 1.0;
  75. ui_label = "Display Gamut: sRGB | Modern | DCI | Adobe | Rec. 2020";
  76. > = 0.0;
  77.  
  78. uniform float CP <
  79. ui_type = "drag";
  80. ui_min = -1.0;
  81. ui_max = 5.0;
  82. ui_step = 1.0;
  83. ui_label = "CRT Profile: EBU | P22 | SMPTE-C | Philips | Trinitron";
  84. > = 0.0;
  85.  
  86. uniform float TNTC <
  87. ui_type = "drag";
  88. ui_min = 0.0;
  89. ui_max = 4.0;
  90. ui_step = 1.0;
  91. ui_label = "LUT Colors: Trinitron 1 | Trinitron 2 | Nec MultiSync | NTSC";
  92. > = 0.0;
  93.  
  94. uniform float LUTLOW <
  95. ui_type = "drag";
  96. ui_min = 0.0;
  97. ui_max = 50.0;
  98. ui_step = 1.0;
  99. ui_label = "Fix LUT Dark Range";
  100. > = 5.0;
  101.  
  102. uniform float LUTBR <
  103. ui_type = "drag";
  104. ui_min = 0.0;
  105. ui_max = 1.0;
  106. ui_step = 0.01;
  107. ui_label = "Fix LUT Brightness";
  108. > = 1.0;
  109.  
  110. uniform float WP <
  111. ui_type = "drag";
  112. ui_min = -100.0;
  113. ui_max = 100.0;
  114. ui_step = 5.0;
  115. ui_label = "Color Temperature %";
  116. > = 0.0;
  117.  
  118. uniform float wp_saturation <
  119. ui_type = "drag";
  120. ui_min = 0.0;
  121. ui_max = 2.0;
  122. ui_step = 0.05;
  123. ui_label = "Saturation Adjustment";
  124. > = 1.0;
  125.  
  126. uniform float pre_bb <
  127. ui_type = "drag";
  128. ui_min = 0.0;
  129. ui_max = 2.0;
  130. ui_step = 0.01;
  131. ui_label = "Brightness Adjustment";
  132. > = 1.0;
  133.  
  134. uniform float contr <
  135. ui_type = "drag";
  136. ui_min = -2.0;
  137. ui_max = 2.0;
  138. ui_step = 0.05;
  139. ui_label = "Contrast Adjustment";
  140. > = 0.0;
  141.  
  142. uniform float sega_fix <
  143. ui_type = "drag";
  144. ui_min = 0.0;
  145. ui_max = 1.0;
  146. ui_step = 1.0;
  147. ui_label = "Sega Brightness Fix";
  148. > = 0.0;
  149.  
  150. uniform float BP <
  151. ui_type = "drag";
  152. ui_min = -100.0;
  153. ui_max = 25.0;
  154. ui_step = 1.0;
  155. ui_label = "Raise Black Level";
  156. > = 0.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 gamma_i <
  175. ui_type = "drag";
  176. ui_min = 1.0;
  177. ui_max = 5.0;
  178. ui_step = 0.05;
  179. ui_label = "Gamma Input";
  180. > = 1.80;
  181.  
  182. uniform float gamma_o <
  183. ui_type = "drag";
  184. ui_min = 1.0;
  185. ui_max = 5.0;
  186. ui_step = 0.05;
  187. ui_label = "Gamma Out";
  188. > = 1.75;
  189.  
  190. uniform float inter <
  191. ui_type = "drag";
  192. ui_min = 0.0;
  193. ui_max = 800.0;
  194. ui_step = 25.0;
  195. ui_label = "Interlace Trigger Resolution";
  196. > = 400.0;
  197.  
  198. uniform float interm <
  199. ui_type = "drag";
  200. ui_min = 0.0;
  201. ui_max = 4.0;
  202. ui_step = 1.0;
  203. ui_label = "Interlace Mode: OFF | Normal 1-3 | Interpolation 4";
  204. > = 4.0;
  205.  
  206. uniform float iscan <
  207. ui_type = "drag";
  208. ui_min = 0.0;
  209. ui_max = 1.0;
  210. ui_step = 0.05;
  211. ui_label = "Interlacing Scanline Effect (Interlaced Brightness)";
  212. > = 0.2;
  213.  
  214. uniform float iscans <
  215. ui_type = "drag";
  216. ui_min = 0.0;
  217. ui_max = 1.0;
  218. ui_step = 0.05;
  219. ui_label = "Interlacing Scanline Saturation";
  220. > = 0.25;
  221.  
  222. uniform float intres <
  223. ui_type = "drag";
  224. ui_min = 0.0;
  225. ui_max = 6.0;
  226. ui_step = 0.5;
  227. ui_label = "Internal Resolution Y: 0.5 | Y-Dowsample";
  228. > = 0.0;
  229.  
  230. uniform float m_glow <
  231. ui_type = "drag";
  232. ui_min = 0.0;
  233. ui_max = 1.0;
  234. ui_step = 1.0;
  235. ui_label = "Ordinary Glow | Magic Glow";
  236. > = 0.0;
  237.  
  238. uniform float m_glow_cutoff <
  239. ui_type = "drag";
  240. ui_min = 0.0;
  241. ui_max = 0.4;
  242. ui_step = 0.01;
  243. ui_label = "Magic Glow Cutoff";
  244. > = 0.12;
  245.  
  246. uniform float m_glow_low <
  247. ui_type = "drag";
  248. ui_min = 0.0;
  249. ui_max = 7.0;
  250. ui_step = 0.05;
  251. ui_label = "Magic Glow Low Strength";
  252. > = 0.35;
  253.  
  254. uniform float m_glow_high <
  255. ui_type = "drag";
  256. ui_min = 0.0;
  257. ui_max = 7.0;
  258. ui_step = 0.05;
  259. ui_label = "Magic Glow High Strength";
  260. > = 5.0;
  261.  
  262. uniform float m_glow_dist <
  263. ui_type = "drag";
  264. ui_min = 0.2;
  265. ui_max = 4.0;
  266. ui_step = 0.05;
  267. ui_label = "Magic Glow Distribution";
  268. > = 1.0;
  269.  
  270. uniform float m_glow_mask <
  271. ui_type = "drag";
  272. ui_min = 0.0;
  273. ui_max = 2.0;
  274. ui_step = 0.025;
  275. ui_label = "Magic Glow Mask Strength";
  276. > = 1.0;
  277.  
  278. uniform float SIZEH <
  279. ui_type = "drag";
  280. ui_min = 1.0;
  281. ui_max = 50.0;
  282. ui_step = 1.0;
  283. ui_label = "Horizontal Glow Radius";
  284. > = 6.0;
  285.  
  286. uniform float SIGMA_H <
  287. ui_type = "drag";
  288. ui_min = 0.2;
  289. ui_max = 15.0;
  290. ui_step = 0.1;
  291. ui_label = "Horizontal Glow Sigma";
  292. > = 1.2;
  293.  
  294. uniform float SIZEV <
  295. ui_type = "drag";
  296. ui_min = 1.0;
  297. ui_max = 50.0;
  298. ui_step = 1.0;
  299. ui_label = "Vertical Glow Radius";
  300. > = 6.0;
  301.  
  302. uniform float SIGMA_V <
  303. ui_type = "drag";
  304. ui_min = 0.2;
  305. ui_max = 15.0;
  306. ui_step = 0.1;
  307. ui_label = "Vertical Glow Sigma";
  308. > = 1.2;
  309.  
  310. uniform float SIZEX <
  311. ui_type = "drag";
  312. ui_min = 1.0;
  313. ui_max = 30.0;
  314. ui_step = 1.0;
  315. ui_label = "Horizontal Bloom/Halation Radius";
  316. > = 4.0;
  317.  
  318. uniform float SIGMA_X <
  319. ui_type = "drag";
  320. ui_min = 0.25;
  321. ui_max = 15.0;
  322. ui_step = 0.05;
  323. ui_label = "Horizontal Bloom/Halation Sigma";
  324. > = 1.0;
  325.  
  326. uniform float BLOOMCUT_X <
  327. ui_type = "drag";
  328. ui_min = 0.0;
  329. ui_max = 0.5;
  330. ui_step = 0.01;
  331. ui_label = "Horizontal Bloom/Halation Substract";
  332. > = 0.0;
  333.  
  334. uniform float SIZEY <
  335. ui_type = "drag";
  336. ui_min = 1.0;
  337. ui_max = 30.0;
  338. ui_step = 1.0;
  339. ui_label = "Vertical Bloom/Halation Radius";
  340. > = 4.0;
  341.  
  342. uniform float SIGMA_Y <
  343. ui_type = "drag";
  344. ui_min = 0.25;
  345. ui_max = 15.0;
  346. ui_step = 0.05;
  347. ui_label = "Vertical Bloom/Halation Sigma";
  348. > = 1.0;
  349.  
  350. uniform float BLOOMCUT_Y <
  351. ui_type = "drag";
  352. ui_min = 0.0;
  353. ui_max = 0.5;
  354. ui_step = 0.01;
  355. ui_label = "Vertical Bloom/Halation Substract";
  356. > = 0.0;
  357.  
  358. uniform float HSHARPNESS <
  359. ui_type = "drag";
  360. ui_min = 1.0;
  361. ui_max = 8.0;
  362. ui_step = 0.05;
  363. ui_label = "Horizontal Filter Range";
  364. > = 1.0;
  365.  
  366. uniform float SIGMA_HOR <
  367. ui_type = "drag";
  368. ui_min = 0.1;
  369. ui_max = 7.0;
  370. ui_step = 0.025;
  371. ui_label = "Horizontal Blur Sigma";
  372. > = 0.5;
  373.  
  374. uniform float S_SHARPH <
  375. ui_type = "drag";
  376. ui_min = 0.0;
  377. ui_max = 2.0;
  378. ui_step = 0.1;
  379. ui_label = "Horizontal Substractive Sharpness";
  380. > = 1.0;
  381.  
  382. uniform float HSHARP <
  383. ui_type = "drag";
  384. ui_min = 0.0;
  385. ui_max = 2.0;
  386. ui_step = 0.1;
  387. ui_label = "Horizontal Sharpness Definition";
  388. > = 1.2;
  389.  
  390. uniform float HARNG <
  391. ui_type = "drag";
  392. ui_min = 0.0;
  393. ui_max = 4.0;
  394. ui_step = 0.1;
  395. ui_label = "Horizontal Substractive Sharpness Ringing";
  396. > = 0.2;
  397.  
  398. uniform float VSHARPNESS <
  399. ui_type = "drag";
  400. ui_min = 1.0;
  401. ui_max = 8.0;
  402. ui_step = 0.05;
  403. ui_label = "Vertical Filter Range";
  404. > = 1.0;
  405.  
  406. uniform float SIGMA_VER <
  407. ui_type = "drag";
  408. ui_min = 0.1;
  409. ui_max = 7.0;
  410. ui_step = 0.025;
  411. ui_label = "Vertical Blur Sigma";
  412. > = 0.5;
  413.  
  414. uniform float S_SHARPV <
  415. ui_type = "drag";
  416. ui_min = 0.0;
  417. ui_max = 2.0;
  418. ui_step = 0.1;
  419. ui_label = "Vertical Substractive Sharpness";
  420. > = 1.0;
  421.  
  422. uniform float VSHARP <
  423. ui_type = "drag";
  424. ui_min = 0.0;
  425. ui_max = 2.0;
  426. ui_step = 0.1;
  427. ui_label = "Vertical Sharpness Definition";
  428. > = 1.2;
  429.  
  430. uniform float VARNG <
  431. ui_type = "drag";
  432. ui_min = 0.0;
  433. ui_max = 4.0;
  434. ui_step = 0.1;
  435. ui_label = "Vertical Substractive Sharpness Ringing";
  436. > = 0.2;
  437.  
  438. uniform float MAXS <
  439. ui_type = "drag";
  440. ui_min = 0.0;
  441. ui_max = 0.3;
  442. ui_step = 0.01;
  443. ui_label = "Maximum Sharpness";
  444. > = 0.15;
  445.  
  446. uniform float internal_res <
  447. ui_type = "drag";
  448. ui_min = 1.0;
  449. ui_max = 8.0;
  450. ui_step = 0.1;
  451. ui_label = "Internal Resolution";
  452. > = 1.0;
  453.  
  454. uniform float glow <
  455. ui_type = "drag";
  456. ui_min = -2.0;
  457. ui_max = 2.0;
  458. ui_step = 0.01;
  459. ui_label = "(Magic) Glow Strength";
  460. > = 0.08;
  461.  
  462. uniform float bloom <
  463. ui_type = "drag";
  464. ui_min = -2.0;
  465. ui_max = 2.0;
  466. ui_step = 0.05;
  467. ui_label = "Bloom Strength";
  468. > = 0.0;
  469.  
  470. uniform float mask_bloom <
  471. ui_type = "drag";
  472. ui_min = 0.0;
  473. ui_max = 2.0;
  474. ui_step = 0.05;
  475. ui_label = "Mask Bloom";
  476. > = 0.0;
  477.  
  478. uniform float bloom_dist <
  479. ui_type = "drag";
  480. ui_min = 0.0;
  481. ui_max = 3.0;
  482. ui_step = 0.05;
  483. ui_label = "Bloom Distribution";
  484. > = 0.0;
  485.  
  486. uniform float halation <
  487. ui_type = "drag";
  488. ui_min = -2.0;
  489. ui_max = 2.0;
  490. ui_step = 0.025;
  491. ui_label = "Halation Strength";
  492. > = 0.0;
  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 gsl <
  519. ui_type = "drag";
  520. ui_min = -1.0;
  521. ui_max = 2.0;
  522. ui_step = 1.0;
  523. ui_label = "Scanline Type";
  524. > = 0.0;
  525.  
  526. uniform float scanline1 <
  527. ui_type = "drag";
  528. ui_min = -20.0;
  529. ui_max = 40.0;
  530. ui_step = 0.5;
  531. ui_label = "Scanline Beam Shape Center";
  532. > = 6.0;
  533.  
  534. uniform float scanline2 <
  535. ui_type = "drag";
  536. ui_min = 0.0;
  537. ui_max = 70.0;
  538. ui_step = 1.0;
  539. ui_label = "Scanline Beam Shape Edges";
  540. > = 8.0;
  541.  
  542. uniform float beam_min <
  543. ui_type = "drag";
  544. ui_min = 0.25;
  545. ui_max = 10.0;
  546. ui_step = 0.05;
  547. ui_label = "Scanline Shape Dark Pixels";
  548. > = 1.3;
  549.  
  550. uniform float beam_max <
  551. ui_type = "drag";
  552. ui_min = 0.2;
  553. ui_max = 3.5;
  554. ui_step = 0.01;
  555. ui_label = "Scanline Shape Bright Pixels";
  556. > = 1.0;
  557.  
  558. uniform float beam_size <
  559. ui_type = "drag";
  560. ui_min = 0.0;
  561. ui_max = 1.0;
  562. ui_step = 0.05;
  563. ui_label = "Increased Bright Scanline Beam";
  564. > = 0.6;
  565.  
  566. uniform float scans <
  567. ui_type = "drag";
  568. ui_min = -5.0;
  569. ui_max = 5.0;
  570. ui_step = 0.1;
  571. ui_label = "Scanline Saturation / Mask Falloff";
  572. > = 0.5;
  573.  
  574. uniform float scan_falloff <
  575. ui_type = "drag";
  576. ui_min = 0.15;
  577. ui_max = 2.0;
  578. ui_step = 0.05;
  579. ui_label = "Scanline Falloff";
  580. > = 1.0;
  581.  
  582. uniform float spike <
  583. ui_type = "drag";
  584. ui_min = 0.0;
  585. ui_max = 2.0;
  586. ui_step = 0.1;
  587. ui_label = "Scanline Spike Removal";
  588. > = 1.0;
  589.  
  590. uniform float scangamma <
  591. ui_type = "drag";
  592. ui_min = 0.5;
  593. ui_max = 5.0;
  594. ui_step = 0.05;
  595. ui_label = "Scanline Gamma";
  596. > = 2.4;
  597.  
  598. uniform float no_scanlines <
  599. ui_type = "drag";
  600. ui_min = 0.0;
  601. ui_max = 1.5;
  602. ui_step = 0.05;
  603. ui_label = "No-Scanline Mode";
  604. > = 0.0;
  605.  
  606. uniform float IOS <
  607. ui_type = "drag";
  608. ui_min = 0.0;
  609. ui_max = 4.0;
  610. ui_step = 1.0;
  611. ui_label = "Integer Scaling: Odd:Y | Even:X+Y";
  612. > = 0.0;
  613.  
  614. uniform float csize <
  615. ui_type = "drag";
  616. ui_min = 0.0;
  617. ui_max = 0.25;
  618. ui_step = 0.01;
  619. ui_label = "Corner Size";
  620. > = 0.0;
  621.  
  622. uniform float bsize1 <
  623. ui_type = "drag";
  624. ui_min = 0.0;
  625. ui_max = 3.0;
  626. ui_step = 0.01;
  627. ui_label = "Border Size";
  628. > = 0.01;
  629.  
  630. uniform float sborder <
  631. ui_type = "drag";
  632. ui_min = 0.25;
  633. ui_max = 2.0;
  634. ui_step = 0.05;
  635. ui_label = "Border Intensity";
  636. > = 0.75;
  637.  
  638. uniform float barspeed <
  639. ui_type = "drag";
  640. ui_min = 5.0;
  641. ui_max = 200.0;
  642. ui_step = 1.0;
  643. ui_label = "Hum Bar Speed";
  644. > = 50.0;
  645.  
  646. uniform float barintensity <
  647. ui_type = "drag";
  648. ui_min = -1.0;
  649. ui_max = 1.0;
  650. ui_step = 0.01;
  651. ui_label = "Hum Bar Intensity";
  652. > = 0.0;
  653.  
  654. uniform float bardir <
  655. ui_type = "drag";
  656. ui_min = 0.0;
  657. ui_max = 1.0;
  658. ui_step = 1.0;
  659. ui_label = "Hum Bar Direction";
  660. > = 0.0;
  661.  
  662. uniform float warpX <
  663. ui_type = "drag";
  664. ui_min = 0.0;
  665. ui_max = 0.25;
  666. ui_step = 0.01;
  667. ui_label = "Curvature X (Default 0.03)";
  668. > = 0.0;
  669.  
  670. uniform float warpY <
  671. ui_type = "drag";
  672. ui_min = 0.0;
  673. ui_max = 0.25;
  674. ui_step = 0.01;
  675. ui_label = "Curvature Y (Default 0.04)";
  676. > = 0.0;
  677.  
  678. uniform float c_shape <
  679. ui_type = "drag";
  680. ui_min = 0.05;
  681. ui_max = 0.6;
  682. ui_step = 0.05;
  683. ui_label = "Curvature Shape";
  684. > = 0.25;
  685.  
  686. uniform float overscanX <
  687. ui_type = "drag";
  688. ui_min = -200.0;
  689. ui_max = 200.0;
  690. ui_step = 1.0;
  691. ui_label = "Overscan X Original Pixels";
  692. > = 0.0;
  693.  
  694. uniform float overscanY <
  695. ui_type = "drag";
  696. ui_min = -200.0;
  697. ui_max = 200.0;
  698. ui_step = 1.0;
  699. ui_label = "Overscan Y Original Pixels";
  700. > = 0.0;
  701.  
  702. uniform float shadowMask <
  703. ui_type = "drag";
  704. ui_min = -1.0;
  705. ui_max = 13.0;
  706. ui_step = 1.0;
  707. ui_label = "CRT Mask: 0:CGWG | 1-4:Lottes | 5-13:Trinitron";
  708. > = 0.0;
  709.  
  710. uniform float maskstr <
  711. ui_type = "drag";
  712. ui_min = -0.5;
  713. ui_max = 1.0;
  714. ui_step = 0.025;
  715. ui_label = "Mask Strength (0, 5-12)";
  716. > = 0.3;
  717.  
  718. uniform float mcut <
  719. ui_type = "drag";
  720. ui_min = 0.0;
  721. ui_max = 2.0;
  722. ui_step = 0.05;
  723. ui_label = "Mask 5-12 Low Strength";
  724. > = 1.1;
  725.  
  726. uniform float maskboost <
  727. ui_type = "drag";
  728. ui_min = 1.0;
  729. ui_max = 3.0;
  730. ui_step = 0.05;
  731. ui_label = "CRT Mask Boost";
  732. > = 1.0;
  733.  
  734. uniform float masksize <
  735. ui_type = "drag";
  736. ui_min = 1.0;
  737. ui_max = 4.0;
  738. ui_step = 1.0;
  739. ui_label = "CRT Mask Size";
  740. > = 1.0;
  741.  
  742. uniform float mask_zoom <
  743. ui_type = "drag";
  744. ui_min = -4.0;
  745. ui_max = 4.0;
  746. ui_step = 1.0;
  747. ui_label = "CRT Mask Zoom (+ Mask Width)";
  748. > = 0.0;
  749.  
  750. uniform float mask_drk <
  751. ui_type = "drag";
  752. ui_min = 0.0;
  753. ui_max = 2.0;
  754. ui_step = 0.05;
  755. ui_label = "Lottes Mask Dark";
  756. > = 0.5;
  757.  
  758. uniform float mask_lgt <
  759. ui_type = "drag";
  760. ui_min = 0.0;
  761. ui_max = 2.0;
  762. ui_step = 0.05;
  763. ui_label = "Lottes Mask Light";
  764. > = 1.5;
  765.  
  766. uniform float mshift <
  767. ui_type = "drag";
  768. ui_min = -8.0;
  769. ui_max = 8.0;
  770. ui_step = 0.5;
  771. ui_label = "Mask Shift/Stagger";
  772. > = 0.0;
  773.  
  774. uniform float mask_layout <
  775. ui_type = "drag";
  776. ui_min = 0.0;
  777. ui_max = 1.0;
  778. ui_step = 1.0;
  779. ui_label = "Mask Layout: RGB or BGR (Check LCD Panel)";
  780. > = 0.0;
  781.  
  782. uniform float mask_gamma <
  783. ui_type = "drag";
  784. ui_min = 1.0;
  785. ui_max = 5.0;
  786. ui_step = 0.05;
  787. ui_label = "Mask Gamma";
  788. > = 2.4;
  789.  
  790. uniform float slotmask <
  791. ui_type = "drag";
  792. ui_min = 0.0;
  793. ui_max = 1.0;
  794. ui_step = 0.05;
  795. ui_label = "Slot Mask Strength Bright Pixels";
  796. > = 0.0;
  797.  
  798. uniform float slotmask1 <
  799. ui_type = "drag";
  800. ui_min = 0.0;
  801. ui_max = 1.0;
  802. ui_step = 0.05;
  803. ui_label = "Slot Mask Strength Dark Pixels";
  804. > = 0.0;
  805.  
  806. uniform float slotwidth <
  807. ui_type = "drag";
  808. ui_min = 0.0;
  809. ui_max = 16.0;
  810. ui_step = 1.0;
  811. ui_label = "Slot Mask Width (0:Auto)";
  812. > = 0.0;
  813.  
  814. uniform float double_slot <
  815. ui_type = "drag";
  816. ui_min = 1.0;
  817. ui_max = 4.0;
  818. ui_step = 1.0;
  819. ui_label = "Slot Mask Height: 2x1 or 4x1";
  820. > = 2.0;
  821.  
  822. uniform float slotms <
  823. ui_type = "drag";
  824. ui_min = 1.0;
  825. ui_max = 4.0;
  826. ui_step = 1.0;
  827. ui_label = "Slot Mask Thickness";
  828. > = 1.0;
  829.  
  830. uniform float mclip <
  831. ui_type = "drag";
  832. ui_min = 0.0;
  833. ui_max = 1.0;
  834. ui_step = 0.05;
  835. ui_label = "Keep Mask Effect With Clipping";
  836. > = 0.0;
  837.  
  838. uniform float smoothmask <
  839. ui_type = "drag";
  840. ui_min = 0.0;
  841. ui_max = 1.0;
  842. ui_step = 1.0;
  843. ui_label = "Smooth Masks In Bright Scanlines";
  844. > = 0.0;
  845.  
  846. uniform float smask_mit <
  847. ui_type = "drag";
  848. ui_min = 0.0;
  849. ui_max = 1.0;
  850. ui_step = 0.05;
  851. ui_label = "Mitigate Slot Mask Interaction";
  852. > = 0.0;
  853.  
  854. uniform float dctypex <
  855. ui_type = "drag";
  856. ui_min = 0.0;
  857. ui_max = 0.75;
  858. ui_step = 0.05;
  859. ui_label = "Deconvergence Type X: 0.0:Static | Other:Dynamic";
  860. > = 0.0;
  861.  
  862. uniform float dctypey <
  863. ui_type = "drag";
  864. ui_min = 0.0;
  865. ui_max = 0.75;
  866. ui_step = 0.05;
  867. ui_label = "Deconvergence Type Y: 0.0:Static | Other:Dynamic";
  868. > = 0.0;
  869.  
  870. uniform float deconrx <
  871. ui_type = "drag";
  872. ui_min = -15.0;
  873. ui_max = 15.0;
  874. ui_step = 0.25;
  875. ui_label = "Horizontal Deconvergence Red Range";
  876. > = 0.0;
  877.  
  878. uniform float decongx <
  879. ui_type = "drag";
  880. ui_min = -15.0;
  881. ui_max = 15.0;
  882. ui_step = 0.25;
  883. ui_label = "Horizontal Deconvergence Green Range";
  884. > = 0.0;
  885.  
  886. uniform float deconbx <
  887. ui_type = "drag";
  888. ui_min = -15.0;
  889. ui_max = 15.0;
  890. ui_step = 0.25;
  891. ui_label = "Horizontal Deconvergence Blue Range";
  892. > = 0.0;
  893.  
  894. uniform float deconry <
  895. ui_type = "drag";
  896. ui_min = -15.0;
  897. ui_max = 15.0;
  898. ui_step = 0.25;
  899. ui_label = "Vertical Deconvergence Red Range";
  900. > = 0.0;
  901.  
  902. uniform float decongy <
  903. ui_type = "drag";
  904. ui_min = -15.0;
  905. ui_max = 15.0;
  906. ui_step = 0.25;
  907. ui_label = "Vertical Deconvergence Green Range";
  908. > = 0.0;
  909.  
  910. uniform float deconby <
  911. ui_type = "drag";
  912. ui_min = -15.0;
  913. ui_max = 15.0;
  914. ui_step = 0.25;
  915. ui_label = "Vertical Deconvergence Blue Range";
  916. > = 0.0;
  917.  
  918. uniform float decons <
  919. ui_type = "drag";
  920. ui_min = 0.0;
  921. ui_max = 3.0;
  922. ui_step = 0.1;
  923. ui_label = "Deconvergence Strength";
  924. > = 1.0;
  925.  
  926. uniform float addnoised <
  927. ui_type = "drag";
  928. ui_min = -1.0;
  929. ui_max = 1.0;
  930. ui_step = 0.02;
  931. ui_label = "Add Noise";
  932. > = 0.0;
  933.  
  934. uniform float noiseresd <
  935. ui_type = "drag";
  936. ui_min = 1.0;
  937. ui_max = 10.0;
  938. ui_step = 1.0;
  939. ui_label = "Noise Resolution";
  940. > = 2.0;
  941.  
  942. uniform float noisetype <
  943. ui_type = "drag";
  944. ui_min = 0.0;
  945. ui_max = 1.0;
  946. ui_step = 1.0;
  947. ui_label = "Noise Type: Colored | Luma";
  948. > = 0.0;
  949.  
  950. uniform float post_br <
  951. ui_type = "drag";
  952. ui_min = 0.25;
  953. ui_max = 5.0;
  954. ui_step = 0.01;
  955. ui_label = "Post Brightness";
  956. > = 1.0;
  957.  
  958. #include "ReShade.fxh"
  959.  
  960. #define TexSize float2(ResolutionX,ResolutionY)
  961. #define IptSize float2(800.0000000,600.0000000)
  962. #define OptSize float4(BUFFER_SCREEN_SIZE,1.0/BUFFER_SCREEN_SIZE)
  963. #define OrgSize float4(TexSize,1.0/TexSize)
  964. #define SrcSize float4(IptSize,1.0/IptSize)
  965. #define FragCoord (texcoord*OptSize.xy)
  966. #define eps 1e-10
  967. #define COMPAT_TEXTURE(c,d) tex2D(c,d)
  968. #define inv_sqr_h 1.0/(2.0*SIGMA_H*SIGMA_H)
  969. #define inv_sqr_v 1.0/(2.0*SIGMA_V*SIGMA_V)
  970. #define inv_sqr_x 1.0/(2.0*SIGMA_X*SIGMA_X)
  971. #define inv_sqr_y 1.0/(2.0*SIGMA_Y*SIGMA_Y)
  972. #define invsigmah 1.0/(2.0*SIGMA_HOR*SIGMA_HOR*internal_res*internal_res)
  973. #define invsigmav 1.0/(2.0*SIGMA_VER*SIGMA_VER*internal_res*internal_res)
  974.  
  975. #ifndef Resolution_X
  976. #define Resolution_X 320
  977. #endif
  978.  
  979. #ifndef Resolution_Y
  980. #define Resolution_Y 240
  981. #endif
  982.  
  983. texture CRTHD_T1{Width=Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  984. sampler CRTHD_S1{Texture=CRTHD_T1;MinFilter=Point ;MagFilter=Point ;};
  985.  
  986. texture CRTHD_T2{Width=Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  987. sampler CRTHD_S2{Texture=CRTHD_T2;MinFilter=Point ;MagFilter=Point ;};
  988.  
  989. texture CRTHD_T3{Width=Resolution_X;Height=Resolution_Y ;Format=RGBA16F;};
  990. sampler CRTHD_S3{Texture=CRTHD_T3;MinFilter=Linear;MagFilter=Linear;};
  991.  
  992. texture CRTHD_T4{Width=BUFFER_WIDTH;Height=Resolution_Y ;Format=RGBA16F;};
  993. sampler CRTHD_S4{Texture=CRTHD_T4;MinFilter=Linear;MagFilter=Linear;};
  994.  
  995. texture CRTHD_T5{Width=800.00000000;Height=600.00000000 ;Format=RGBA16F;};
  996. sampler CRTHD_S5{Texture=CRTHD_T5;MinFilter=Linear;MagFilter=Linear;};
  997.  
  998. texture CRTHD_T6{Width=800.00000000;Height=600.00000000 ;Format=RGBA16F;};
  999. sampler CRTHD_S6{Texture=CRTHD_T6;MinFilter=Linear;MagFilter=Linear;};
  1000.  
  1001. texture CRTHD_T7{Width=800.00000000;Height=600.00000000 ;Format=RGBA16F;};
  1002. sampler CRTHD_S7{Texture=CRTHD_T7;MinFilter=Linear;MagFilter=Linear;};
  1003.  
  1004. texture CRTHD_T8{Width=800.00000000;Height=600.00000000 ;Format=RGBA16F;};
  1005. sampler CRTHD_S8{Texture=CRTHD_T8;MinFilter=Linear;MagFilter=Linear;};
  1006.  
  1007. texture CRTHD_T9{Width=BUFFER_WIDTH;Height=BUFFER_HEIGHT;Format=RGBA16F;};
  1008. sampler CRTHD_S9{Texture=CRTHD_T9;MinFilter=Linear;MagFilter=Linear;};
  1009.  
  1010. texture CRTHD_01<source="CRT-LUT-1.png";>{Width=1024;Height=32;};
  1011. sampler CRTHD_L1{Texture=CRTHD_01;};
  1012.  
  1013. texture CRTHD_02<source="CRT-LUT-2.png";>{Width=1024;Height=32;};
  1014. sampler CRTHD_L2{Texture=CRTHD_02;};
  1015.  
  1016. texture CRTHD_03<source="CRT-LUT-3.png";>{Width=1024;Height=32;};
  1017. sampler CRTHD_L3{Texture=CRTHD_03;};
  1018.  
  1019. texture CRTHD_04<source="CRT-LUT-4.png";>{Width=1024;Height=32;};
  1020. sampler CRTHD_L4{Texture=CRTHD_04;};
  1021.  
  1022. sampler CRTHD_S0{Texture=ReShade::BackBufferTex;};
  1023.  
  1024. uniform int framecount<source="framecount";>;
  1025.  
  1026. float3 fix_lut(float3 lut,float3 ref)
  1027. {
  1028. float r=length(ref);
  1029. float l=length(lut);
  1030. float m=max(max(ref.r,ref.g),ref.b);
  1031. ref=normalize(lut+0.0000001)*lerp(r,l,pow(m,1.25));
  1032. return lerp(lut,ref,LUTBR);
  1033. }
  1034.  
  1035. float vignette(float2 pos)
  1036. {
  1037. float2 b=vigdef*float2(1.0,OrgSize.x/OrgSize.y)*0.125;
  1038. pos=clamp(pos,0.0,1.0);
  1039. pos=abs(2.0*(pos-0.5));
  1040. float2 res=lerp(0.0.xx,1.0.xx,smoothstep(1.0.xx,1.0.xx-b,sqrt(pos)));
  1041. res=pow(res,0.70.xx);
  1042. return max(lerp(1.0,sqrt(res.x*res.y),vigstr),0.0);
  1043. }
  1044.  
  1045. float contrast(float x)
  1046. {
  1047. return max(lerp(x,smoothstep(0.0,1.0,x),contr),0.0);
  1048. }
  1049.  
  1050. float3 plant(float3 tar,float r)
  1051. {
  1052. float t=max(max(tar.r,tar.g),tar.b)+0.00001;
  1053. return tar*r/t;
  1054. }
  1055.  
  1056. float gauss_h(float x)
  1057. {
  1058. return exp(-x*x*inv_sqr_h);
  1059. }
  1060.  
  1061. float gauss_v(float x)
  1062. {
  1063. return exp(-x*x*inv_sqr_v);
  1064. }
  1065.  
  1066. float gauss_x(float x)
  1067. {
  1068. return exp(-x*x*inv_sqr_x);
  1069. }
  1070.  
  1071. float gauss_y(float x)
  1072. {
  1073. return exp(-x*x*inv_sqr_y);
  1074. }
  1075.  
  1076. float crthd_h(float x)
  1077. {
  1078. return exp(-x*x*invsigmah);
  1079. }
  1080.  
  1081. float crthd_v(float x)
  1082. {
  1083. return exp(-x*x*invsigmav);
  1084. }
  1085.  
  1086. float mod(float x,float y)
  1087. {
  1088. return x-y* floor(x/y);
  1089. }
  1090.  
  1091. float st0(float x)
  1092. {
  1093. return exp2(-10.0*x*x);
  1094. }
  1095.  
  1096. float sw0(float x,float color,float scanline)
  1097. {
  1098. float tmp=lerp(beam_min,beam_max,color);
  1099. float ex=x*tmp;
  1100. ex=(gsl>-0.5)?ex*ex:lerp(ex*ex,ex*ex*ex,0.4);
  1101. return exp2(-scanline*ex);
  1102. }
  1103.  
  1104. float sw1(float x,float color,float scanline)
  1105. {
  1106. x=lerp(x,beam_min*x,max(x-0.4*color,0.0));
  1107. float tmp=lerp(1.2*beam_min,beam_max,color);
  1108. float ex=x*tmp;
  1109. return exp2(-scanline*ex*ex);
  1110. }
  1111.  
  1112. float sw2(float x,float color,float scanline)
  1113. {
  1114. float tmp=lerp((2.5-0.5*color)*beam_min,beam_max,color);
  1115. tmp=lerp(beam_max,tmp,pow(x,color+0.3));
  1116. float ex=x*tmp;
  1117. return exp2(-scanline*ex*ex);
  1118. }
  1119.  
  1120. float2 overscan(float2 pos,float dx,float dy)
  1121. {
  1122. pos=pos*2.0-1.0;
  1123. pos*=float2(dx,dy);
  1124. return pos*0.5+0.5;
  1125. }
  1126.  
  1127. float2 warp(float2 pos)
  1128. {
  1129. pos=pos*2.0-1.0;
  1130. 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);
  1131. return pos*0.5+0.5;
  1132. }
  1133.  
  1134. float3 gc(float3 c)
  1135. {
  1136. float mc=max(max(c.r,c.g),c.b);
  1137. float mg=pow(mc,1.0/gamma_c);
  1138. return c*mg/(mc+eps);
  1139. }
  1140.  
  1141. float3 v_resample(float2 tex0,float4 size)
  1142. {
  1143. float f=frac(size.y*tex0.y);
  1144. f=0.5-f;
  1145. float2 tex=tex0;
  1146. tex.y=floor(size.y*tex.y)*size.w+0.5*size.w;
  1147. float3 color=0.0.xxx;
  1148. float2 dy=float2(0.0,size.w);
  1149. float w=0.0;
  1150. float wsum=0.0;
  1151. float3 pixel;
  1152. float vsharpness=VSHARPNESS*internal_res;
  1153. float3 cmax=0.0.xxx;
  1154. float3 cmin=1.0.xxx;
  1155. float sharp=crthd_v(vsharpness)*S_SHARPV;
  1156. float maxsharp=MAXS;
  1157. float FPR=vsharpness;
  1158. float fpx=0.0;
  1159. float LOOPSIZE=ceil(2.0*FPR);
  1160. float CLAMPSIZE=round(2.0*LOOPSIZE/3.0);
  1161. float n=-LOOPSIZE;
  1162. do
  1163. {
  1164. pixel=tex2Dlod(CRTHD_S4,float4(tex+n*dy,0.0,0.0)).rgb;
  1165. w=crthd_v(n+f)-sharp;
  1166. fpx=abs(n+f-sign(n)*FPR)/FPR;
  1167. if(abs(n)<=CLAMPSIZE)cmax=max(cmax,pixel);cmin=min(cmin,pixel);
  1168. if(w<0.0)w=clamp(w,lerp(-maxsharp,0.0,pow(clamp(fpx,0.0,1.0),VSHARP)),0.0);
  1169. color=color+w*pixel;
  1170. wsum=wsum+w;
  1171. n=n+1.0;
  1172. }while(n<=LOOPSIZE);
  1173. color=color/wsum;
  1174. color=clamp(lerp(clamp(color,cmin,cmax),color,VARNG),0.0,1.0);
  1175. return color;
  1176. }
  1177.  
  1178. float3 crt_mask(float2 pos,float mx,float mb)
  1179. {
  1180. float3 mask=mask_drk;
  1181. float3 one=1.0;
  1182. if(shadowMask==-1.0)
  1183. {
  1184. mask=one;
  1185. }else
  1186. if(shadowMask== 0.0)
  1187. {
  1188. float mc=1.0-max(maskstr,0.0);
  1189. pos.x=frac(pos.x*0.5);
  1190. if(pos.x<0.49)
  1191. {
  1192. mask.r=1.0;mask.g= mc;mask.b=1.0;
  1193. }else
  1194. {
  1195. mask.r= mc;mask.g=1.0;mask.b= mc;
  1196. }
  1197. }else
  1198. if(shadowMask== 1.0)
  1199. {
  1200. float line=mask_lgt;
  1201. float odd=0.0;
  1202. if(frac(pos.x/6.0)<0.49)odd=1.0;
  1203. if(frac((pos.y+odd)/2.0)<0.49)line=mask_drk;
  1204. pos.x=floor(mod(pos.x,3.0));
  1205. if(pos.x<0.5)mask.r=mask_lgt;else
  1206. if(pos.x<1.5)mask.g=mask_lgt;else
  1207. mask.b= mask_lgt;
  1208. mask*=line;
  1209. }else
  1210. if(shadowMask== 2.0)
  1211. {
  1212. pos.x=floor(mod(pos.x,3.0));
  1213. if(pos.x<0.5)mask.r=mask_lgt;else
  1214. if(pos.x<1.5)mask.g=mask_lgt;else
  1215. mask.b= mask_lgt;
  1216. }else
  1217. if(shadowMask== 3.0)
  1218. {
  1219. pos.x+=pos.y*3.0;
  1220. pos.x=frac(pos.x/6.0);
  1221. if(pos.x<0.3)mask.r=mask_lgt;else
  1222. if(pos.x<0.6)mask.g=mask_lgt;else
  1223. mask.b= mask_lgt;
  1224. }else
  1225. if(shadowMask== 4.0)
  1226. {
  1227. pos.xy=floor(pos.xy*float2(1.0,0.5));
  1228. pos.x+=pos.y*3.0;
  1229. pos.x=frac(pos.x/6.0);
  1230. if(pos.x<0.3)mask.r=mask_lgt;else
  1231. if(pos.x<0.6)mask.g=mask_lgt;else
  1232. mask.b= mask_lgt;
  1233. }else
  1234. if(shadowMask== 5.0)
  1235. {
  1236. mask=0.0;
  1237. pos.x=frac(pos.x/2.0);
  1238. if(pos.x<0.49)
  1239. {
  1240. mask.r=1.0;
  1241. mask.b=1.0;
  1242. }else
  1243. mask.g=1.0;
  1244. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1245. }else
  1246. if(shadowMask== 6.0)
  1247. {
  1248. mask=0.0;
  1249. pos.x=floor(mod(pos.x,3.0));
  1250. if(pos.x<0.5)mask.r=1.0;else
  1251. if(pos.x<1.5)mask.g=1.0;else
  1252. mask.b=1.0;
  1253. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1254. }else
  1255. if(shadowMask== 7.0)
  1256. {
  1257. mask=0.0;
  1258. pos.x=frac(pos.x/2.0);
  1259. if(pos.x<0.49)
  1260. {
  1261. mask=0.0.xxx;
  1262. }else
  1263. mask=1.0.xxx;
  1264. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1265. }else
  1266. if(shadowMask== 8.0)
  1267. {
  1268. mask=0.0;
  1269. pos.x=frac(pos.x/3.0);
  1270. if(pos.x<0.3)mask=0.0.xxx;else
  1271. if(pos.x<0.6)mask=1.0.xxx;else
  1272. mask=1.0.xxx;
  1273. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1274. }
  1275. else
  1276. if(shadowMask== 9.0)
  1277. {
  1278. mask=0.0;
  1279. pos.x=frac(pos.x/3.0);
  1280. if(pos.x<0.3)mask =0.0.xxx;else
  1281. if(pos.x<0.6)mask.rb=1.0.xx ;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(shadowMask==10.0)
  1286. {
  1287. mask=0.0;
  1288. pos.x=frac(pos.x*0.25);
  1289. if(pos.x<0.2)mask =0.0.xxx;else
  1290. if(pos.x<0.4)mask.r=1.0 ;else
  1291. if(pos.x<0.7)mask.g=1.0 ;else
  1292. mask.b=1.0;
  1293. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1294. }else
  1295. if(shadowMask==11.0)
  1296. {
  1297. mask=0.0;
  1298. pos.x=frac(pos.x*0.25);
  1299. if(pos.x<0.2)mask.r =1.0 ;else
  1300. if(pos.x<0.4)mask.rg=1.0.xx;else
  1301. if(pos.x<0.7)mask.gb=1.0.xx;else
  1302. mask.b=1.0;mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1303. }else
  1304. if(shadowMask==12.0)
  1305. {
  1306. mask=0.0;
  1307. pos.x=floor(mod(pos.x,7.0));
  1308. if(pos.x<0.5)mask =0.0.xxx;else
  1309. if(pos.x<2.5)mask.r=1.0 ;else
  1310. if(pos.x<4.5)mask.g=1.0 ;else
  1311. mask.b=1.0;
  1312. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1313. }
  1314. else
  1315. {
  1316. mask=0.0;
  1317. pos.x=floor(mod(pos.x,6.0));
  1318. if(pos.x<0.5)mask =0.0.xxx;else
  1319. if(pos.x<1.5)mask.r =1.0 ;else
  1320. if(pos.x<2.5)mask.rg =1.0.xx ;else
  1321. if(pos.x<3.5)mask.rgb=1.0.xxx;else
  1322. if(pos.x<4.5)mask.gb =1.0.xx ;else
  1323. mask.b=1.0;
  1324. mask=clamp(lerp(lerp(one,mask,mcut),lerp(one,mask,maskstr),mx),0.0,1.0);
  1325. }
  1326. if(mask_layout>0.5)mask=mask.rbg;
  1327. float maskmin=min(min(mask.r,mask.g),mask.b);
  1328. return (mask-maskmin)*(1.0+(maskboost-1.0)*mb)+maskmin;
  1329. }
  1330.  
  1331. float slt_mask(float2 pos,float m,float swidth)
  1332. {
  1333. if ((slotmask+slotmask1)==0.0)return 1.0;else
  1334. {
  1335. pos.y=floor(pos.y/slotms);
  1336. float mlen=swidth*2.0;
  1337. float px=floor( mod(pos.x,0.99999*mlen));
  1338. float py=floor(frac(pos.y/(2.0*double_slot))*2.0*double_slot);
  1339. float slot_dark=lerp(1.0-slotmask1,1.0-slotmask,m);
  1340. float slot=1.0;
  1341. if(py==0.0&&px<swidth)slot=slot_dark;else
  1342. if(py==double_slot&&px>=swidth)slot=slot_dark;
  1343. return slot;
  1344. }
  1345. }
  1346.  
  1347. float humbars(float pos)
  1348. {
  1349. if (barintensity==0.0)return 1.0;else
  1350. {
  1351. pos=(barintensity>=0.0)?pos:(1.0-pos);
  1352. pos=frac(pos+ mod(float(framecount),barspeed)/(barspeed-1.0));
  1353. pos=(barintensity< 0.0)?pos:(1.0-pos);
  1354. return (1.0-barintensity)+barintensity*pos;
  1355. }
  1356. }
  1357.  
  1358. float corner(float2 pos)
  1359. {
  1360. float2 b=bsize1* float2(1.0,OptSize.x/OptSize.y)*0.05;
  1361. pos=clamp(pos,0.0,1.0);
  1362. pos=abs(2.0*(pos-0.5));
  1363. float csize1=lerp(400.0,7.0,pow(4.0*csize,0.10));
  1364. float crn=dot(pow(pos,csize1.xx),float2(1.0,OptSize.y/OptSize.x));
  1365. crn=(csize==0.0)?max(pos.x,pos.y):pow(crn,1.0/csize1);
  1366. pos=max(pos,crn);
  1367. float2 res=(bsize1==0.0)?1.0.xx:lerp(0.0.xx,1.0.xx,smoothstep(1.0.xx,1.0.xx-b,sqrt(pos)));
  1368. res=pow(res, sborder.xx);
  1369. return sqrt(res.x*res.y);
  1370. }
  1371.  
  1372. float3 declip(float3 c,float b)
  1373. {
  1374. float m=max(max(c.r,c.g),c.b);
  1375. if(m>b)c=c*b/m;
  1376. return c;
  1377. }
  1378.  
  1379. float igc(float mc)
  1380. {
  1381. return pow(mc,gamma_c);
  1382. }
  1383.  
  1384. float3 noise(float3 v)
  1385. {
  1386. if(addnoised<0.0) {v.z=-addnoised;}else{v.z= mod(v.z,6001.0)/1753.0;}
  1387. v =frac(v)+frac(v*1e4)+frac(v*1e-4);
  1388. v+=float3(0.12345,0.6789,0.314159);
  1389. v =frac(v*dot(v,v)*123.456);
  1390. v =frac(v*dot(v,v)*123.456);
  1391. v =frac(v*dot(v,v)*123.456);
  1392. v =frac(v*dot(v,v)*123.456);
  1393. return v;
  1394. }
  1395.  
  1396. void bring_pixel(inout float3 c,inout float3 b,float2 coord,float2 boord)
  1397. {
  1398. float stepx=OptSize.z;
  1399. float stepy=OptSize.w;
  1400. float2 dx=float2(stepx,0.0);
  1401. float2 dy=float2(0.0,stepy);
  1402. float posx= 2.0*coord.x-1.0;
  1403. float posy= 2.0*coord.y-1.0;
  1404. if(dctypex>0.025)
  1405. {
  1406. posx= sign(posx)*pow(abs(posx),1.05-dctypex);
  1407. dx=posx*dx;
  1408. }
  1409. if(dctypey>0.025)
  1410. {
  1411. posy= sign(posy)*pow(abs(posy),1.05-dctypey);
  1412. dy=posy*dy;
  1413. }
  1414. float2 rc=deconrx*dx+deconry*dy;
  1415. float2 gc=decongx*dx+decongy*dy;
  1416. float2 bc=deconbx*dx+deconby*dy;
  1417. float r1=COMPAT_TEXTURE(CRTHD_S9,coord+rc).r;
  1418. float g1=COMPAT_TEXTURE(CRTHD_S9,coord+gc).g;
  1419. float b1=COMPAT_TEXTURE(CRTHD_S9,coord+bc).b;
  1420. float ds=decons;
  1421. float3 d;
  1422. d=float3(r1,g1,b1);
  1423. c=clamp(lerp(c,d,ds),0.0,1.0);
  1424. r1=COMPAT_TEXTURE(CRTHD_S8,boord+rc).r;
  1425. g1=COMPAT_TEXTURE(CRTHD_S8,boord+gc).g;
  1426. b1=COMPAT_TEXTURE(CRTHD_S8,boord+bc).b;
  1427. d=float3(r1,g1,b1);
  1428. b=clamp(lerp(b,d,ds),0.0,1.0);
  1429. }
  1430.  
  1431. float4 AfterglowPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1432. {
  1433. float2 dx=float2(OrgSize.z,0.0);
  1434. float2 dy=float2(0.0,OrgSize.w);
  1435. float w=1.0;
  1436. float3 color0=COMPAT_TEXTURE(CRTHD_S0,texcoord.xy ).rgb;
  1437. float3 color1=COMPAT_TEXTURE(CRTHD_S0,texcoord.xy-dx).rgb;
  1438. float3 color2=COMPAT_TEXTURE(CRTHD_S0,texcoord.xy+dx).rgb;
  1439. float3 color3=COMPAT_TEXTURE(CRTHD_S0,texcoord.xy-dy).rgb;
  1440. float3 color4=COMPAT_TEXTURE(CRTHD_S0,texcoord.xy+dy).rgb;
  1441. float3 clr=(2.5*color0+color1+color2+color3+color4)/6.5;
  1442. float3 a=COMPAT_TEXTURE(CRTHD_S1,texcoord.xy).rgb;
  1443. if((color0.r+color0.g+color0.b<5.0/255.0)){w=0.0;}
  1444. float3 result=lerp(max(lerp(clr,a,0.49+float3(PR,PG,PB))-2.0/255.0,0.0),clr,w);
  1445. return float4(result,w);
  1446. }
  1447.  
  1448. float4 PreShaderPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1449. {
  1450. const float3x3 File0=float3x3(0.412391, 0.212639,0.019331, 0.357584,0.715169, 0.119195, 0.180481,0.072192,0.950532);
  1451. const float3x3 File1=float3x3(0.430554, 0.222004,0.020182, 0.341550,0.706655, 0.129553, 0.178352,0.071341,0.939322);
  1452. const float3x3 File2=float3x3(0.396686, 0.210299,0.006131, 0.372504,0.713766, 0.115356, 0.181266,0.075936,0.967571);
  1453. const float3x3 File3=float3x3(0.393521, 0.212376,0.018739, 0.365258,0.701060, 0.111934, 0.191677,0.086564,0.958385);
  1454. const float3x3 File4=float3x3(0.392258, 0.209410,0.016061, 0.351135,0.725680, 0.093636, 0.166603,0.064910,0.850324);
  1455. const float3x3 File5=float3x3(0.377923, 0.195679,0.010514, 0.317366,0.722319, 0.097826, 0.207738,0.082002,1.076960);
  1456. const float3x3 ToRGB=float3x3(3.240970,-0.969244,0.055630,-1.537383,1.875968,-0.203977,-0.498611,0.041555,1.056972);
  1457. const float3x3 ToMDN=float3x3(2.791723,-0.894766,0.041678,-1.173165,1.815586,-0.130886,-0.440973,0.032000,1.002034);
  1458. const float3x3 ToDCI=float3x3(2.493497,-0.829489,0.035846,-0.931384,1.762664,-0.076172,-0.402711,0.023625,0.956885);
  1459. const float3x3 ToADB=float3x3(2.041588,-0.969244,0.013444,-0.565007,1.875968,-0.118360,-0.344731,0.041555,1.015175);
  1460. const float3x3 ToREC=float3x3(1.716651,-0.666684,0.017640,-0.355671,1.616481,-0.042771,-0.253366,0.015769,0.942103);
  1461. const float3x3 D65_to_D55=float3x3(0.4850339153,0.2500956126,0.0227359648,0.3488957224,0.6977914447,0.1162985741,0.1302823568,0.0521129427,0.6861537456);
  1462. const float3x3 D65_to_D93=float3x3(0.3412754080,0.1759701322,0.0159972847,0.3646170520,0.7292341040,0.1215390173,0.2369894093,0.0947957637,1.2481442225);
  1463. float4 imgColor=COMPAT_TEXTURE(CRTHD_S0,texcoord.xy);
  1464. float4 aftrglow=COMPAT_TEXTURE(CRTHD_S1,texcoord.xy);
  1465. float w=1.0-aftrglow.w;
  1466. float l=length(aftrglow.rgb);
  1467. aftrglow.rgb=AS*w*normalize(pow(aftrglow.rgb+0.01,sat))*l;
  1468. float bp=w*BP/255.0;
  1469. if(sega_fix>0.5)imgColor.rgb=imgColor.rgb*(255.0/239.0);
  1470. imgColor.rgb=min(imgColor.rgb,1.0);
  1471. float3 color=imgColor.rgb;
  1472. if(int(TNTC)==0)
  1473. {
  1474. color.rgb=imgColor.rgb;
  1475. }else
  1476. {
  1477. float lutlow=LUTLOW/255.0;float invLS=1.0/32.0;
  1478. float3 lut_ref=imgColor.rgb+lutlow*(1.0-pow(imgColor.rgb,0.333.xxx));
  1479. float lutb=lut_ref.b*(1.0-0.5*invLS);
  1480. lut_ref.rg=lut_ref.rg*(1.0-invLS)+0.5*invLS;
  1481. float tile1=ceil(lutb*(32.0-1.0));
  1482. float tile0=max(tile1-1.0,0.0);
  1483. float f=frac(lutb*(32.0-1.0));if(f==0.0)f=1.0;
  1484. float2 coord0=float2(tile0+lut_ref.r,lut_ref.g)*float2(invLS,1.0);
  1485. float2 coord1=float2(tile1+lut_ref.r,lut_ref.g)*float2(invLS,1.0);
  1486. float4 color1,color2,res;
  1487. if(int(TNTC)==1)
  1488. {
  1489. color1=COMPAT_TEXTURE(CRTHD_L1,coord0);
  1490. color2=COMPAT_TEXTURE(CRTHD_L1,coord1);
  1491. res=lerp(color1,color2,f);
  1492. }else
  1493. if(int(TNTC)==2)
  1494. {
  1495. color1=COMPAT_TEXTURE(CRTHD_L2,coord0);
  1496. color2=COMPAT_TEXTURE(CRTHD_L2,coord1);
  1497. res=lerp(color1,color2,f);
  1498. }else
  1499. if(int(TNTC)==3)
  1500. {
  1501. color1=COMPAT_TEXTURE(CRTHD_L3,coord0);
  1502. color2=COMPAT_TEXTURE(CRTHD_L3,coord1);
  1503. res=lerp(color1,color2,f);
  1504. }else
  1505. if(int(TNTC)==4)
  1506. {
  1507. color1=COMPAT_TEXTURE(CRTHD_L4,coord0);
  1508. color2=COMPAT_TEXTURE(CRTHD_L4,coord1);
  1509. res=lerp(color1,color2,f);
  1510. }
  1511. res.rgb=fix_lut(res.rgb,imgColor.rgb);
  1512. color=lerp(imgColor.rgb,res.rgb,min(TNTC,1.0));
  1513. }
  1514. float3 c=clamp(color,0.0,1.0);
  1515. float3x3 m_o;
  1516. float p;
  1517. if(CS==0.0){p=2.2;m_o=ToRGB;}else
  1518. if(CS==1.0){p=2.2;m_o=ToMDN;}else
  1519. if(CS==2.0){p=2.6;m_o=ToDCI;}else
  1520. if(CS==3.0){p=2.2;m_o=ToADB;}else
  1521. if(CS==4.0){p=2.4;m_o=ToREC;}
  1522. color=pow(c,p);
  1523. float3x3 m_i;
  1524. if(CP==0.0){m_i=File0;}else
  1525. if(CP==1.0){m_i=File1;}else
  1526. if(CP==2.0){m_i=File2;}else
  1527. if(CP==3.0){m_i=File3;}else
  1528. if(CP==4.0){m_i=File4;}else
  1529. if(CP==5.0){m_i=File5;}
  1530. color=mul(color,m_i);
  1531. color=mul(color,m_o);
  1532. color=clamp(color,0.0,1.0);
  1533. color=pow(color,1.0/p);
  1534. if(CP==-1.0)color=c;
  1535. float3 scolor1=plant(pow(color,wp_saturation),max(max(color.r,color.g),color.b));
  1536. float luma=dot(color,float3(0.299,0.587,0.114));
  1537. float3 scolor2=lerp(luma,color,wp_saturation);
  1538. color=(wp_saturation>1.0)?scolor1:scolor2;
  1539. color=plant(color,contrast(max(max(color.r,color.g),color.b)));
  1540. p=2.2;
  1541. color=clamp(color,0.0,1.0);
  1542. color=pow(color,p);
  1543. float3 warmer=mul(color,D65_to_D55);
  1544. warmer=mul(warmer,ToRGB);
  1545. float3 cooler=mul(color,D65_to_D93);
  1546. cooler=mul(cooler,ToRGB);
  1547. float m=abs(WP)/100.0;
  1548. float3 comp=(WP<0.0)?cooler:warmer;
  1549. color=lerp(color,comp,m);
  1550. color=pow(max(color,0.0),1.0/p);
  1551. if(BP>-0.5)color=color+aftrglow.rgb+bp;else
  1552. {
  1553. color=max(color+BP/255.0,0.0)/(1.0+BP/255.0*step(-BP/255.0,max(max(color.r,color.g),color.b)))+aftrglow.rgb;
  1554. }
  1555. color=min(color*pre_bb,1.0);
  1556. return float4(color,vignette(texcoord.xy));
  1557. }
  1558.  
  1559. float4 LinearizePS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1560. {
  1561. float3 c1=tex2Dlod(CRTHD_S2,float4(texcoord,0.0,0.0)).rgb;
  1562. float3 c2=tex2Dlod(CRTHD_S2,float4(texcoord+float2(0.0,OrgSize.w),0.0,0.0)).rgb;
  1563. float3 c=c1;
  1564. float intera=1.0;
  1565. float gamma_in=clamp(gamma_i,1.0,5.0);
  1566. float m1=max(max(c1.r,c1.g),c1.b);
  1567. float m2=max(max(c2.r,c2.g),c2.b);
  1568. float3 df=abs(c1-c2);
  1569. float d=max(max(df.r,df.g),df.b);
  1570. if(interm==2.0)d=lerp(0.1*d,10.0*d,step(m1/(m2+0.0001),m2/(m1+0.0001)));
  1571. float r=m1;
  1572. float yres_div=1.0;if(intres>1.25)yres_div=intres;
  1573. if(inter<=OrgSize.y/yres_div&&interm>0.5&&intres!=1.0&&intres!=0.5)
  1574. {
  1575. intera=0.25;
  1576. float liine_no=clamp(floor( mod(OrgSize.y*texcoord.y,2.0)),0.0,1.0);
  1577. float frame_no=clamp(floor( mod(float(framecount),2.0)),0.0,1.0);
  1578. float ii=abs(liine_no-frame_no);
  1579. if(interm< 3.5)
  1580. {
  1581. c2=plant(lerp(c2,c2*c2,iscans),max(max(c2.r,c2.g),c2.b));
  1582. r=clamp(max(m1*ii,(1.0-iscan)*min(m1,m2)),0.0,1.0);
  1583. 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);
  1584. if(interm==3.0)c=(1.0-0.5*iscan)*lerp(c2,c1,ii);
  1585. }
  1586. 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);}
  1587. }
  1588. c=pow(c,gamma_in);
  1589. if(texcoord.x>0.5){gamma_in=intera;}else{gamma_in=1.0/gamma_in;}
  1590. return float4(c,gamma_in);
  1591. }
  1592.  
  1593. float4 HGaussianPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1594. {
  1595. float4 GaussSize=float4(OrgSize.x,OrgSize.y,OrgSize.z,OrgSize.w);
  1596. float f=frac(GaussSize.x*texcoord.x);
  1597. f=0.5-f;
  1598. float2 tex=floor(GaussSize.xy*texcoord)*GaussSize.zw+0.5*GaussSize.zw;
  1599. float3 color=0.0;
  1600. float2 dx=float2(GaussSize.z,0.0);
  1601. float3 pixel;
  1602. float w;
  1603. float wsum=0.0;
  1604. float n=-SIZEH;
  1605. do
  1606. {
  1607. pixel=tex2Dlod(CRTHD_S3,float4(tex+n*dx,0.0,0.0)).rgb;
  1608. if(m_glow>0.5)
  1609. {
  1610. pixel=max(pixel-m_glow_cutoff,0.0);
  1611. pixel=plant(pixel,max(max(max(pixel.r,pixel.g),pixel.b)-m_glow_cutoff,0.0));
  1612. }
  1613. w=gauss_h(n+f);
  1614. color=color+w*pixel;
  1615. wsum=wsum+w;
  1616. n=n+1.0;
  1617. }while(n<=SIZEH);
  1618. color=color/wsum;
  1619. return float4(color,1.0);
  1620. }
  1621.  
  1622. float4 VGaussianPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1623. {
  1624. float4 GaussSize=float4(SrcSize.x,OrgSize.y,SrcSize.z,OrgSize.w);
  1625. float f=frac(GaussSize.y*texcoord.y);
  1626. f=0.5-f;
  1627. float2 tex=floor(GaussSize.xy*texcoord)*GaussSize.zw+0.5*GaussSize.zw;
  1628. float3 color=0.0;
  1629. float2 dy=float2(0.0,GaussSize.w);
  1630. float3 pixel;
  1631. float w;
  1632. float wsum=0.0;
  1633. float n=-SIZEV;
  1634. do
  1635. {
  1636. pixel=tex2Dlod(CRTHD_S5,float4(tex+n*dy,0.0,0.0)).rgb;
  1637. w=gauss_v(n+f);
  1638. color=color+w*pixel;
  1639. wsum=wsum+w;
  1640. n=n+1.0;
  1641. }while(n<=SIZEV);
  1642. color=color/wsum;
  1643. return float4(color,1.0);
  1644. }
  1645.  
  1646. float4 BloomHorzPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1647. {
  1648. float4 BloomSize=float4(OrgSize.x,OrgSize.y,OrgSize.z,OrgSize.w);
  1649. float f=frac(BloomSize.x*texcoord.x);
  1650. f=0.5-f;
  1651. float2 tex=floor(BloomSize.xy*texcoord)*BloomSize.zw+0.5*BloomSize.zw;
  1652. float4 color=0.0;
  1653. float2 dx=float2(BloomSize.z,0.0);
  1654. float4 pixel;
  1655. float w;
  1656. float wsum=0.0;
  1657. float n=-SIZEX;
  1658. do
  1659. {
  1660. pixel=tex2Dlod(CRTHD_S3,float4(tex+n*dx,0.0,0.0));
  1661. w=max(gauss_x(n+f)-BLOOMCUT_X,0.0);
  1662. pixel.a =max(max(pixel.r,pixel.g),pixel.b);
  1663. pixel.a*=pixel.a*pixel.a;
  1664. color=color+w*pixel;
  1665. wsum=wsum+w;
  1666. n=n+1.0;
  1667. }while(n<=SIZEX);
  1668. color=color/wsum;
  1669. return float4(color.rgb,pow(color.a,0.333333));
  1670. }
  1671.  
  1672. float4 BloomVertPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1673. {
  1674. float4 BloomSize=float4(SrcSize.x,OrgSize.y,SrcSize.z,OrgSize.w);
  1675. float f=frac(BloomSize.y*texcoord.y);
  1676. f=0.5-f;
  1677. float2 tex=floor(BloomSize.xy*texcoord)*BloomSize.zw+0.5*BloomSize.zw;
  1678. float4 color=0.0;
  1679. float2 dy=float2(0.0,BloomSize.w);
  1680. float4 pixel;
  1681. float w;
  1682. float wsum=0.0;
  1683. float n=-SIZEY;
  1684. do
  1685. {
  1686. pixel=tex2Dlod(CRTHD_S7,float4(tex+n*dy,0.0,0.0));
  1687. w=max(gauss_y(n+f)-BLOOMCUT_Y,0.0);
  1688. pixel.a*=pixel.a*pixel.a;
  1689. color=color+w*pixel;
  1690. wsum=wsum+w;
  1691. n=n+1.0;
  1692. }while(n<=SIZEY);
  1693. color=color/wsum;
  1694. return float4(color.rgb,pow(color.a,0.175000));
  1695. }
  1696.  
  1697. float4 HD_Pass1_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1698. {
  1699. float2 prescalex=float2(tex2Dsize(CRTHD_S3,0))/OrgSize.xy;
  1700. float4 HD1Size=OrgSize*float4(prescalex.x,prescalex.y,1.0/prescalex.x,1.0/prescalex.y);
  1701. float f=frac(HD1Size.x*texcoord.x);
  1702. f=0.5-f;
  1703. float2 tex=floor(HD1Size.xy*texcoord)*HD1Size.zw+0.5*HD1Size.zw;
  1704. float3 color=0.0.xxx;
  1705. float scolor=0.0;
  1706. float2 dx=float2(HD1Size.z,0.0);
  1707. float w=0.0;
  1708. float swsum=0.0;
  1709. float wsum=0.0;
  1710. float3 pixel;
  1711. float hsharpness=HSHARPNESS*internal_res;
  1712. float3 cmax=0.0.xxx;
  1713. float3 cmin=1.0.xxx;
  1714. float sharp=crthd_h(hsharpness)*S_SHARPH;
  1715. float maxsharp=MAXS;
  1716. float FPR=hsharpness;
  1717. float fpx=0.0;
  1718. float sp=0.0;
  1719. float sw=0.0;
  1720. float ts=0.025;
  1721. float3 luma=float3(0.2126,0.7152,0.0722);
  1722. float LOOPSIZE=ceil(2.0*FPR);
  1723. float CLAMPSIZE=round(2.0*LOOPSIZE/3.0);
  1724. float n=-LOOPSIZE;
  1725. do
  1726. {
  1727. pixel=tex2Dlod(CRTHD_S3,float4(tex+n*dx,0.0,0.0)).rgb;
  1728. sp=max(max(pixel.r,pixel.g),pixel.b);
  1729. w=crthd_h(n+f)-sharp;
  1730. fpx=abs(n+f-sign(n)*FPR)/FPR;
  1731. if(abs(n)<=CLAMPSIZE)cmax=max(cmax,pixel);cmin=min(cmin,pixel);
  1732. if(w<0.0)w=clamp(w,lerp(-maxsharp,0.0,pow(clamp(fpx,0.0,1.0),HSHARP)),0.0);
  1733. color=color+w*pixel;
  1734. wsum=wsum+w;
  1735. sw=max(w,0.0)*(dot(pixel,luma)+ts);
  1736. scolor=scolor+sw*sp;
  1737. swsum=swsum+sw;
  1738. n=n+1.0;
  1739. }while(n<=LOOPSIZE);
  1740. color=color/wsum;
  1741. scolor=scolor/swsum;
  1742. color=clamp(lerp(clamp(color,cmin,cmax),color,HARNG),0.0,1.0);
  1743. scolor=clamp(lerp(max(max(color.r,color.g),color.b),scolor,spike),0.0,1.0);
  1744. return float4(color,scolor);
  1745. }
  1746.  
  1747. float4 HD_Pass2_PS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1748. {
  1749. float2 prescalex=float2(tex2Dsize(CRTHD_S3,0))/OrgSize.xy;
  1750. float4 HD2Size=float4(OrgSize.x,OrgSize.y,OrgSize.z,OrgSize.w);
  1751. float gamma_in=1.0/COMPAT_TEXTURE(CRTHD_S3,0.25).a;
  1752. float intera=COMPAT_TEXTURE(CRTHD_S3,float2(0.75,0.25)).a;
  1753. bool interb=((intera<0.5)||(no_scanlines>0.025));
  1754. float SourceY=HD2Size.y;
  1755. float sy=1.0;
  1756. if(intres==1.0)sy=SourceY/224.0;
  1757. if(intres>0.25&&intres!=1.0)sy=intres;
  1758. HD2Size*=float4(1.0,1.0/sy,1.0,sy);
  1759. if(IOS> 0.0&&!interb)
  1760. {
  1761. float2 ofactor=OptSize.xy/OrgSize.xy;
  1762. float2 intfactor=(IOS<2.5)?floor(ofactor):ceil(ofactor);
  1763. float2 diff=ofactor/intfactor;
  1764. float scan=diff.y;
  1765. texcoord=overscan(texcoord,scan,scan);
  1766. if(IOS==1.0||IOS==3.0)texcoord=float2(texcoord.x,texcoord.y);
  1767. }
  1768. texcoord=overscan(texcoord,(OrgSize.x-overscanX)/OrgSize.x,(OrgSize.y-overscanY)/OrgSize.y);
  1769. float2 pos=warp(texcoord);
  1770. float coffset=0.5;
  1771. float2 ps=HD2Size.zw;
  1772. float OGL2Pos=pos.y*HD2Size.y-coffset;
  1773. float f=frac(OGL2Pos);
  1774. float2 dx=float2(ps.x,0.0);
  1775. float2 dy=float2(0.0,ps.y);
  1776. float2 pC4;
  1777. pC4.y=floor(OGL2Pos)*ps.y+0.5*ps.y;
  1778. pC4.x=pos.x;
  1779. if( intres==0.5&&prescalex.y<1.5)pC4.y=floor(pC4.y*OrgSize.y)*OrgSize.w+0.5*OrgSize.w;
  1780. if( interb&&no_scanlines>0.025)pC4.y=pC4.y+smoothstep(0.40-0.5*no_scanlines,0.60+0.5*no_scanlines,f)*HD2Size.w;
  1781. float3 color1=tex2Dlod(CRTHD_S4,float4(pC4,0.0,0.0)).rgb;
  1782. float3 scolor1=tex2Dlod(CRTHD_S4,float4(pC4,0.0,0.0)).aaa;
  1783. color1=pow(color1,scangamma/gamma_in);
  1784. float prescaley=float(tex2Dsize(CRTHD_S3,0).y)/OrgSize.y;
  1785. if( interb&&no_scanlines<0.05)color1=v_resample(pos,HD2Size*float4(1.0,prescaley,1.0,1.0/prescaley));
  1786. pC4+=dy;
  1787. if( intres==0.5&&prescalex.y<1.5)pC4.y=floor((pos.y+0.33*dy.y)*OrgSize.y)*OrgSize.w+0.5*OrgSize.w;
  1788. float3 color2=tex2Dlod(CRTHD_S4,float4(pC4,0.0,0.0)).rgb;
  1789. float3 scolor2=tex2Dlod(CRTHD_S4,float4(pC4,0.0,0.0)).aaa;
  1790. color2=pow(color2,scangamma/gamma_in);
  1791. float3 ctmp=color1;float w3=1.0;float3 color=color1;
  1792. if(!interb)
  1793. {
  1794. float shape1=lerp(scanline1,scanline2, f);
  1795. float shape2=lerp(scanline1,scanline2,1.0-f);
  1796. float wt1=st0( f);
  1797. float wt2=st0(1.0-f);
  1798. float3 color00= color1*wt1+ color2*wt2;
  1799. float3 scolor0=scolor1*wt1+scolor2*wt2;
  1800. ctmp=color00/(wt1+wt2);
  1801. float3 sctmp=max(scolor0/(wt1+wt2),ctmp);
  1802. float wf1,wf2;
  1803. float3 cref1=lerp(sctmp,scolor1,beam_size);float creff1=pow(max(max(cref1.r,cref1.g),cref1.b),scan_falloff);
  1804. float3 cref2=lerp(sctmp,scolor2,beam_size);float creff2=pow(max(max(cref2.r,cref2.g),cref2.b),scan_falloff);
  1805. float f1= f;
  1806. float f2=1.0-f;
  1807. if(gsl< 0.5)
  1808. {wf1=sw0(f1,creff1,shape1);wf2=sw0(f2,creff2,shape2);}else
  1809. if(gsl==1.0)
  1810. {wf1=sw1(f1,creff1,shape1);wf2=sw1(f2,creff2,shape2);}else
  1811. {wf1=sw2(f1,creff1,shape1);wf2=sw2(f2,creff2,shape2);}
  1812. if((wf1+wf2)>1.0){float wtmp=1.0/(wf1+wf2);wf1*=wtmp;wf2*=wtmp;}
  1813. float3 w1=wf1;float3 w2=wf2;
  1814. w3=wf1+wf2;
  1815. float mc1=max(max(color1.r,color1.g),color1.b)+eps;
  1816. float mc2=max(max(color2.r,color2.g),color2.b)+eps;
  1817. cref1=color1/mc1;
  1818. cref2=color2/mc2;
  1819. float scanpow1=(scans>0.0)?1.0:pow(f1,0.375);
  1820. float scanpow2=(scans>0.0)?1.0:pow(f2,0.375);
  1821. w1=pow(w1,lerp(2.0*abs(scans).xxx+1.0,1.0.xxx,lerp(1.0.xxx,cref1,scanpow1)));
  1822. w2=pow(w2,lerp(2.0*abs(scans).xxx+1.0,1.0.xxx,lerp(1.0.xxx,cref2,scanpow2)));
  1823. color=(gc(color1)*w1+gc(color2)*w2);
  1824. color=min(color,1.0);
  1825. }
  1826. if( interb)
  1827. {
  1828. color=gc(color1);
  1829. }
  1830. float colmx=max(max(ctmp.r,ctmp.g),ctmp.b);
  1831. if(!interb)color=pow(color,gamma_in/scangamma);
  1832. return float4(color,colmx);
  1833. }
  1834.  
  1835. float4 ChromaticPS(float4 position:SV_Position,float2 texcoord:TEXCOORD):SV_Target
  1836. {
  1837. float gamma_in=1.0/COMPAT_TEXTURE(CRTHD_S3,0.25).a;
  1838. float intera=COMPAT_TEXTURE(CRTHD_S3,float2(0.75,0.25)).a;
  1839. bool interb=(intera<0.5||no_scanlines>0.025);
  1840. if(IOS> 0.0&&!interb)
  1841. {
  1842. float2 ofactor=OptSize.xy/OrgSize.xy;
  1843. float2 intfactor=(IOS<2.5)?floor(ofactor):ceil(ofactor);
  1844. float2 diff=ofactor/intfactor;
  1845. float scan=diff.y;
  1846. texcoord=overscan(texcoord,scan,scan);
  1847. if(IOS==1.0||IOS==3.0)texcoord=float2(texcoord.x,texcoord.y);
  1848. }
  1849. texcoord=overscan(texcoord,(OrgSize.x-overscanX)/OrgSize.x,(OrgSize.y-overscanY)/OrgSize.y);
  1850. float2 pos0=warp(texcoord.xy);
  1851. float2 pos1=texcoord.xy;
  1852. float2 pos=warp(texcoord);
  1853. float3 color=COMPAT_TEXTURE(CRTHD_S9,pos1).rgb;
  1854. float3 Bloom=COMPAT_TEXTURE(CRTHD_S8,pos).rgb;
  1855. if((abs(deconrx)+abs(deconry)+abs(decongx)+abs(decongy)+abs(deconbx)+abs(deconby))>0.2)
  1856. bring_pixel(color,Bloom,pos1,pos);
  1857. float cm=igc(max(max(color.r,color.g),color.b));
  1858. float mx1=COMPAT_TEXTURE(CRTHD_S9,pos1 ).a;
  1859. float colmx=max(mx1,cm);
  1860. float w3=min((cm+0.0001)/(colmx+0.0005),1.0);
  1861. float2 dx=float2(0.001,0.0);
  1862. float mx0=COMPAT_TEXTURE(CRTHD_S9,pos1-dx).a;
  1863. float mx2=COMPAT_TEXTURE(CRTHD_S9,pos1+dx).a;
  1864. float mxg=max(max(mx0,mx1),max(mx2,cm));
  1865. float mx=pow(mxg,1.40/gamma_in);
  1866. dx=float2(OrgSize.z,0.0)*0.25;
  1867. mx0=COMPAT_TEXTURE(CRTHD_S9,pos1-dx).a;
  1868. mx2=COMPAT_TEXTURE(CRTHD_S9,pos1+dx).a;
  1869. float mb=1.0-min(abs(mx0-mx2)/(0.5+mx1),1.0);
  1870. float3 orig1=color;
  1871. float3 one=1.0;
  1872. float3 cmask=one;
  1873. float2 maskcoord=FragCoord.xy*1.00001;
  1874. float2 scoord=maskcoord;
  1875. float mwidths[14]={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};
  1876. float mwidth=mwidths[int(shadowMask)];
  1877. float mask_compensate=frac(mwidth);
  1878. mwidth=floor(mwidth)*masksize;
  1879. float swidth=mwidth;
  1880. bool zoomed=(abs(mask_zoom)>0.75);
  1881. float mscale=1.0;
  1882. float2 maskcoord0=maskcoord;
  1883. maskcoord.y=floor(maskcoord.y/masksize);
  1884. if(abs(mshift)>0.75)
  1885. {
  1886. float stagg_lvl=1.0;if(frac(abs(mshift))>0.25&&abs(mshift)>1.25)stagg_lvl=2.0;
  1887. float next_line=float(frac((maskcoord.y/stagg_lvl)*0.5)>0.25);
  1888. maskcoord0.x=(mshift>-0.25)?(maskcoord0.x+next_line*floor(mshift)):(maskcoord0.x+floor(maskcoord.y/stagg_lvl)*floor(abs(mshift)));
  1889. }
  1890. maskcoord=maskcoord0/masksize;if(mask_zoom>=0.0)maskcoord=floor(maskcoord);
  1891. if(!zoomed)cmask*=crt_mask(maskcoord,mx,mb);else
  1892. {
  1893. float mwidth1=max(mwidth+mask_zoom,2.0);
  1894. mscale=mwidth1/mwidth;
  1895. float mlerp=frac(maskcoord.x/mscale);
  1896. float mcoord=floor(maskcoord.x/mscale); if(shadowMask==12.0&&mask_zoom==-2.0)mcoord=ceil(maskcoord.x/mscale);
  1897. cmask*=lerp(crt_mask(float2(mcoord,maskcoord.y),mx,mb),crt_mask(float2(mcoord+1.0,maskcoord.y),mx,mb),mlerp);
  1898. }
  1899. if(slotwidth>0.5)swidth=slotwidth;float smask=1.0;
  1900. float sm_offset=0.0;bool bsm_offset=(shadowMask==0.0||shadowMask==2.0||shadowMask==5.0||shadowMask==6.0||shadowMask==8.0||shadowMask==11.0);
  1901. if( zoomed)
  1902. {
  1903. if(mask_layout<0.5&&bsm_offset)sm_offset=1.0;else
  1904. if(bsm_offset)sm_offset=-1.0;
  1905. }
  1906. swidth=round(swidth*mscale);
  1907. smask=slt_mask(scoord+float2(sm_offset,0.0),mx,swidth);
  1908. 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);
  1909. cmask*=smask;
  1910. float3 cmask1=cmask;
  1911. if(mask_bloom>0.025)
  1912. {
  1913. float maxbl=max(max(max(Bloom.r,Bloom.g),Bloom.b),mxg);
  1914. maxbl=maxbl*lerp(1.0,2.0-colmx,bloom_dist);
  1915. cmask=max(min(cmask+maxbl*mask_bloom,1.0),cmask);
  1916. }
  1917. color=pow(color,mask_gamma/gamma_in);
  1918. color=color*cmask;
  1919. color=min(color,1.0);
  1920. color=pow(color,gamma_in/mask_gamma);
  1921. cmask=min(cmask,1.0);
  1922. cmask1=min(cmask1,1.0);
  1923. 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);
  1924. float bb=lerp(brightboost1,brightboost2,mx)*dark_compensate;
  1925. color*=bb;
  1926. float3 Glow=COMPAT_TEXTURE(CRTHD_S6,pos).rgb;
  1927. float3 Ref=COMPAT_TEXTURE(CRTHD_S3,pos).rgb;
  1928. float maxb=COMPAT_TEXTURE(CRTHD_S8,pos).a;
  1929. float vig=COMPAT_TEXTURE(CRTHD_S2,clamp(pos,0.0+0.5*OrgSize.zw,1.0-0.5*OrgSize.zw)).a;
  1930. float3 Bloom1=Bloom;
  1931. if(abs(bloom)>0.025)
  1932. {
  1933. if(bloom<-0.01)Bloom1=plant(Bloom,maxb);
  1934. Bloom1=min(Bloom1*(orig1+color),max(0.5*(colmx+orig1-color),0.001*Bloom1));
  1935. Bloom1=0.5*(Bloom1+lerp(Bloom1,lerp(colmx*orig1,Bloom1,0.5),1.0-color));
  1936. Bloom1=Bloom1*lerp(1.0,2.0-colmx,bloom_dist);
  1937. color=pow(pow(color,mask_gamma/gamma_in)+abs(bloom)*pow(Bloom1,mask_gamma/gamma_in),gamma_in/mask_gamma);
  1938. }
  1939. color=min(color,lerp(one,cmask1,mclip));
  1940. if(!interb)color=declip(color,lerp(1.0,w3,0.6));else
  1941. {
  1942. w3=1.0;
  1943. }
  1944. if(halation> 0.01)
  1945. {
  1946. Bloom=lerp(0.5*(Bloom+Bloom*Bloom),0.75*Bloom*Bloom,colmx);
  1947. 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)*lerp(one,cmask,0.6)*Bloom*halation;
  1948. }else
  1949. if(halation<-0.01)
  1950. {
  1951. float mbl=max(max(Bloom.r,Bloom.g),Bloom.b);
  1952. Bloom=plant(Bloom+Ref+orig1+Bloom*Bloom*Bloom,min(mbl*mbl,0.75));
  1953. color=color+2.0*lerp(1.0,w3,0.5*colmx)*lerp(one,cmask,0.5)*Bloom*(-halation);
  1954. }
  1955. float w=0.25+0.60*lerp(w3,1.0,sqrt(colmx));
  1956. if(smoothmask>0.5)
  1957. {
  1958. w3=lerp(1.0,w3,smoothstep(0.3,0.6,mx1));color=max(min(color/w3,1.0)*w3,min(color,color*(1.0-w3)));
  1959. }
  1960. if(m_glow<0.5)Glow=lerp(Glow,0.25*color,0.7*colmx);else
  1961. {
  1962. maxb=max(max(Glow.r,Glow.g),Glow.b);
  1963. orig1=plant(orig1+0.001*Ref,1.0);
  1964. Bloom=plant(Glow,1.0);
  1965. Ref=abs(orig1-Bloom);
  1966. mx0=max(max(orig1.g,orig1.g),orig1.b)-min(min(orig1.g,orig1.g),orig1.b);
  1967. mx2=max(max(Bloom.g,Bloom.g),Bloom.b)-min(min(Bloom.g,Bloom.g),Bloom.b);
  1968. Bloom=lerp(maxb*min(Bloom,orig1),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));
  1969. Glow=lerp(m_glow_low*Glow,m_glow_high*Bloom,pow(colmx,m_glow_dist/gamma_in));
  1970. }
  1971. if(glow>=0.0&&m_glow<0.5)color=color+0.5*Glow*glow;else
  1972. {
  1973. if(m_glow>0.5)cmask1=max(lerp(one,cmask1,m_glow_mask),0.0);color=color+abs(glow)*cmask1*Glow;
  1974. }
  1975. color=min(color,1.0);
  1976. color=pow(color,1.0/gamma_o);
  1977. float rc=0.6*sqrt(max(max(color.r,color.g),color.b))+0.4;
  1978. if(abs(addnoised)>0.01)
  1979. {
  1980. float3 noise0=noise(float3(floor(OptSize.xy*texcoord/noiseresd),float(framecount)));
  1981. if(noisetype<0.5)color=lerp(color,noise0,0.25*abs(addnoised)*rc);
  1982. else color=min(color*lerp(1.0,1.5*noise0.x,0.5*abs(addnoised)),1.0);
  1983. }
  1984. return float4(color*vig*humbars(lerp(pos.y,pos.x,bardir))*post_br*corner(pos0),1.0);
  1985. }
  1986.  
  1987. technique CRT_Guest_HD
  1988. {
  1989. pass Afterglow
  1990. {
  1991. VertexShader=PostProcessVS;
  1992. PixelShader=AfterglowPS;
  1993. RenderTarget=CRTHD_T1;
  1994. }
  1995. pass PreShader
  1996. {
  1997. VertexShader=PostProcessVS;
  1998. PixelShader=PreShaderPS;
  1999. RenderTarget=CRTHD_T2;
  2000. }
  2001. pass Linearize
  2002. {
  2003. VertexShader=PostProcessVS;
  2004. PixelShader=LinearizePS;
  2005. RenderTarget=CRTHD_T3;
  2006. }
  2007. pass CRT_Pass1
  2008. {
  2009. VertexShader=PostProcessVS;
  2010. PixelShader=HD_Pass1_PS;
  2011. RenderTarget=CRTHD_T4;
  2012. }
  2013. pass GaussianX
  2014. {
  2015. VertexShader=PostProcessVS;
  2016. PixelShader=HGaussianPS;
  2017. RenderTarget=CRTHD_T5;
  2018. }
  2019. pass GaussianY
  2020. {
  2021. VertexShader=PostProcessVS;
  2022. PixelShader=VGaussianPS;
  2023. RenderTarget=CRTHD_T6;
  2024. }
  2025. pass BloomHorz
  2026. {
  2027. VertexShader=PostProcessVS;
  2028. PixelShader=BloomHorzPS;
  2029. RenderTarget=CRTHD_T7;
  2030. }
  2031. pass BloomVert
  2032. {
  2033. VertexShader=PostProcessVS;
  2034. PixelShader=BloomVertPS;
  2035. RenderTarget=CRTHD_T8;
  2036. }
  2037. pass CRT_Pass2
  2038. {
  2039. VertexShader=PostProcessVS;
  2040. PixelShader=HD_Pass2_PS;
  2041. RenderTarget=CRTHD_T9;
  2042. }
  2043. pass Chromatic
  2044. {
  2045. VertexShader=PostProcessVS;
  2046. PixelShader=ChromaticPS;
  2047. }
  2048. }
Add Comment
Please, Sign In to add comment