Advertisement
Guest User

CRTHyllian-Final1

a guest
Mar 30th, 2017
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.36 KB | None | 0 0
  1. #include "ReShade.fxh"
  2.  
  3. uniform float CRT_MULRES_X <
  4. ui_type = "drag";
  5. ui_min = 1.0;
  6. ui_max = 8.0;
  7. ui_step = 1.0;
  8. ui_label = "Internal X Res Multiplier [CRT-Hyllian]";
  9. > = 2.0;
  10.  
  11. uniform float CRT_MULRES_Y <
  12. ui_type = "drag";
  13. ui_min = 1.0;
  14. ui_max = 8.0;
  15. ui_step = 1.0;
  16. ui_label = "Internal Y Res Multiplier [CRT-Hyllian]";
  17. > = 2.0;
  18.  
  19. uniform float texture_sizeX <
  20. ui_type = "drag";
  21. ui_min = 1.0;
  22. ui_max = BUFFER_WIDTH;
  23. ui_label = "Screen Width [CRT-Hyllian]";
  24. > = 320.0;
  25.  
  26. uniform float texture_sizeY <
  27. ui_type = "drag";
  28. ui_min = 1.0;
  29. ui_max = BUFFER_HEIGHT;
  30. ui_label = "Screen Height [CRT-Hyllian]";
  31. > = 240.0;
  32.  
  33. uniform bool PHOSPHOR <
  34. ui_type = "bool";
  35. ui_label = "Toggle Phosphor [CRT-Hyllian]";
  36. > = true;
  37.  
  38. uniform float VSCANLINES <
  39. ui_type = "drag";
  40. ui_min = 0.0;
  41. ui_max = 1.0;
  42. ui_step = 1.0;
  43. ui_label = "Scanlines Direction [CRT-Hyllian]";
  44. > = 0.0;
  45.  
  46. uniform float InputGamma <
  47. ui_type = "drag";
  48. ui_min = 0.0;
  49. ui_max = 5.0;
  50. ui_step = 0.1;
  51. ui_label = "Input Gamma [CRT-Hyllian]";
  52. > = 2.5;
  53.  
  54. uniform float OutputGamma <
  55. ui_type = "drag";
  56. ui_min = 0.0;
  57. ui_max = 5.0;
  58. ui_step = 0.1;
  59. ui_label = "Output Gamma [CRT-Hyllian]";
  60. > = 2.2;
  61.  
  62. uniform float SHARPNESS <
  63. ui_type = "drag";
  64. ui_min = 1.0;
  65. ui_max = 5.0;
  66. ui_step = 1.0;
  67. ui_label = "Sharpness Hack [CRT-Hyllian]";
  68. > = 1.0;
  69.  
  70. uniform float COLOR_BOOST <
  71. ui_type = "drag";
  72. ui_min = 1.0;
  73. ui_max = 2.0;
  74. ui_step = 0.05;
  75. ui_label = "Color Boost [CRT-Hyllian]";
  76. > = 1.5;
  77.  
  78. uniform float RED_BOOST <
  79. ui_type = "drag";
  80. ui_min = 1.0;
  81. ui_max = 2.0;
  82. ui_step = 0.01;
  83. ui_label = "Red Boost [CRT-Hyllian]";
  84. > = 1.0;
  85.  
  86. uniform float GREEN_BOOST <
  87. ui_type = "drag";
  88. ui_min = 1.0;
  89. ui_max = 2.0;
  90. ui_step = 0.01;
  91. ui_label = "Green Boost [CRT-Hyllian]";
  92. > = 1.0;
  93.  
  94. uniform float BLUE_BOOST<
  95. ui_type = "drag";
  96. ui_min = 1.0;
  97. ui_max = 2.0;
  98. ui_step = 0.01;
  99. ui_label = "Blue Boost [CRT-Hyllian]";
  100. > = 1.0;
  101.  
  102. uniform float SCANLINES_STRENGTH<
  103. ui_type = "drag";
  104. ui_min = 0.0;
  105. ui_max = 1.0;
  106. ui_step = 0.02;
  107. ui_label = "Scanlines Strength [CRT-Hyllian]";
  108. > = 0.05;
  109.  
  110. uniform float BEAM_MIN_WIDTH <
  111. ui_type = "drag";
  112. ui_min = 0.0;
  113. ui_max = 1.0;
  114. ui_step = 0.02;
  115. ui_label = "Min Beam Width [CRT-Hyllian]";
  116. > = 0.86;
  117.  
  118. uniform float BEAM_MAX_WIDTH <
  119. ui_type = "drag";
  120. ui_min = 0.0;
  121. ui_max = 1.0;
  122. ui_step = 0.02;
  123. ui_label = "Max Beam Width [CRT-Hyllian]";
  124. > = 1.0;
  125.  
  126. uniform float CRT_ANTI_RINGING <
  127. ui_type = "drag";
  128. ui_min = 0.0;
  129. ui_max = 1.0;
  130. ui_step = 0.1;
  131. ui_label = "CRT Anti-Ringing [CRT-Hyllian]";
  132. > = 0.8;
  133.  
  134. /* COMPATIBILITY
  135. - HLSL compilers
  136. - Cg compilers
  137. */
  138.  
  139. /*
  140. Hyllian's CRT Shader
  141.  
  142. Copyright (C) 2011-2016 Hyllian - sergiogdb@gmail.com
  143.  
  144. Permission is hereby granted, free of charge, to any person obtaining a copy
  145. of this software and associated documentation files (the "Software"), to deal
  146. in the Software without restriction, including without limitation the rights
  147. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  148. copies of the Software, and to permit persons to whom the Software is
  149. furnished to do so, subject to the following conditions:
  150.  
  151. The above copyright notice and this permission notice shall be included in
  152. all copies or substantial portions of the Software.
  153.  
  154. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  155. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  156. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  157. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  158. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  159. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  160. THE SOFTWARE.
  161.  
  162. */
  163.  
  164. #define GAMMA_IN(color) pow(color, float4(InputGamma, InputGamma, InputGamma,1.0))
  165. #define GAMMA_OUT(color) pow(color, float3(1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma))
  166.  
  167. // Horizontal cubic filter.
  168.  
  169. // Some known filters use these values:
  170.  
  171. // B = 0.0, C = 0.0 => Hermite cubic filter.
  172. // B = 1.0, C = 0.0 => Cubic B-Spline filter.
  173. // B = 0.0, C = 0.5 => Catmull-Rom Spline filter. This is the default used in this shader.
  174. // B = C = 1.0/3.0 => Mitchell-Netravali cubic filter.
  175. // B = 0.3782, C = 0.3109 => Robidoux filter.
  176. // B = 0.2620, C = 0.3690 => Robidoux Sharp filter.
  177. // B = 0.36, C = 0.28 => My best config for ringing elimination in pixel art (Hyllian).
  178.  
  179.  
  180. // For more info, see: http://www.imagemagick.org/Usage/img_diagrams/cubic_survey.gif
  181.  
  182. // Change these params to configure the horizontal filter.
  183.  
  184. uniform float B <
  185. ui_type = "drag";
  186. ui_min = 0.0;
  187. ui_max = 0.5;
  188. ui_step = 0.1;
  189. ui_label = "Horizontal Filter B [CRT-Hyllian]";
  190. > = 0.0;
  191.  
  192. uniform float C <
  193. ui_type = "drag";
  194. ui_min = 0.0;
  195. ui_max = 0.5;
  196. ui_step = 0.1;
  197. ui_label = "Horizontal Filter C [CRT-Hyllian]";
  198. > = 0.5;
  199.  
  200. float fmod(float a, float b)
  201. {
  202. float c = frac(abs(a/b))*abs(b);
  203. return (a < 0) ? -c : c; /* if ( a < 0 ) c = 0-c */
  204. }
  205.  
  206. float4 PS_CRTHyllian(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target{
  207.  
  208. float4x4 invX = float4x4( (-B - 6.0*C)/6.0, (3.0*B + 12.0*C)/6.0, (-3.0*B - 6.0*C)/6.0, B/6.0,
  209. (12.0 - 9.0*B - 6.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, 0.0, (6.0 - 2.0*B)/6.0,
  210. -(12.0 - 9.0*B - 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, (3.0*B + 6.0*C)/6.0, B/6.0,
  211. (B + 6.0*C)/6.0, -C, 0.0, 0.0);
  212.  
  213. float3 color;
  214.  
  215. float2 TextureSize = float2(SHARPNESS*texture_sizeX, texture_sizeY)/float2(CRT_MULRES_X, CRT_MULRES_Y);
  216.  
  217. float2 dx = lerp(float2(1.0/TextureSize.x, 0.0), float2(0.0, 1.0/TextureSize.y), VSCANLINES);
  218. float2 dy = lerp(float2(0.0, 1.0/TextureSize.y), float2(1.0/TextureSize.x, 0.0), VSCANLINES);
  219.  
  220. float2 pix_coord = uv*TextureSize+float2(-0.5,0.5);
  221.  
  222. float2 tc = lerp((floor(pix_coord)+float2(0.5,0.5))/TextureSize, (floor(pix_coord)+float2(1.0,-0.5))/TextureSize, VSCANLINES);
  223.  
  224. float2 fp = lerp(frac(pix_coord), frac(pix_coord.yx), VSCANLINES);
  225.  
  226. float4 c00 = GAMMA_IN(tex2D(ReShade::BackBuffer, tc - dx - dy));
  227. float4 c01 = GAMMA_IN(tex2D(ReShade::BackBuffer, tc - dy));
  228. float4 c02 = GAMMA_IN(tex2D(ReShade::BackBuffer, tc + dx - dy));
  229. float4 c03 = GAMMA_IN(tex2D(ReShade::BackBuffer, tc + 2.0*dx - dy));
  230. float4 c10 = GAMMA_IN(tex2D(ReShade::BackBuffer, tc - dx));
  231. float4 c11 = GAMMA_IN(tex2D(ReShade::BackBuffer, tc ));
  232. float4 c12 = GAMMA_IN(tex2D(ReShade::BackBuffer, tc + dx));
  233. float4 c13 = GAMMA_IN(tex2D(ReShade::BackBuffer, tc + 2.0*dx));
  234.  
  235. // Get min/max samples
  236. float3 min_sample = min(min(c01.xyz,c11.xyz), min(c02.xyz,c12.xyz));
  237. float3 max_sample = max(max(c01.xyz,c11.xyz), max(c02.xyz,c12.xyz));
  238.  
  239. float4x4 color_matrix0 = float4x4(c00, c01, c02, c03);
  240. float4x4 color_matrix1 = float4x4(c10, c11, c12, c13);
  241.  
  242. float4 invX_Px = mul(invX, float4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0));
  243. float4 color0 = mul(invX_Px, color_matrix0);
  244. float4 color1 = mul(invX_Px, color_matrix1);
  245.  
  246. // Anti-ringing
  247. float4 aux = color0;
  248. color0.xyz = clamp(color0.xyz, min_sample, max_sample);
  249. color0.xyz = lerp(aux.xyz, color0.xyz, CRT_ANTI_RINGING);
  250. aux = color1;
  251. color1.xyz = clamp(color1.xyz, min_sample, max_sample);
  252. color1.xyz = lerp(aux.xyz, color1.xyz, CRT_ANTI_RINGING);
  253.  
  254. float pos0 = fp.y;
  255. float pos1 = 1 - fp.y;
  256.  
  257. float3 lum0 = lerp(float3(BEAM_MIN_WIDTH,BEAM_MIN_WIDTH,BEAM_MIN_WIDTH), float3(BEAM_MAX_WIDTH,BEAM_MAX_WIDTH,BEAM_MAX_WIDTH), color0.xyz);
  258. float3 lum1 = lerp(float3(BEAM_MIN_WIDTH,BEAM_MIN_WIDTH,BEAM_MIN_WIDTH), float3(BEAM_MAX_WIDTH,BEAM_MAX_WIDTH,BEAM_MAX_WIDTH), color1.xyz);
  259.  
  260. float3 d0 = clamp(pos0/(lum0+0.0000001), 0.0, 1.0);
  261. float3 d1 = clamp(pos1/(lum1+0.0000001), 0.0, 1.0);
  262.  
  263. d0 = exp(-10.0*SCANLINES_STRENGTH*d0*d0);
  264. d1 = exp(-10.0*SCANLINES_STRENGTH*d1*d1);
  265.  
  266. color = clamp(color0.xyz*d0+color1.xyz*d1, 0.0, 1.0);
  267.  
  268. color *= COLOR_BOOST*float3(RED_BOOST, GREEN_BOOST, BLUE_BOOST);
  269.  
  270. float mod_factor = lerp(uv.x * ReShade::ScreenSize.x * texture_sizeX / texture_sizeX, uv.y * ReShade::ScreenSize.y * texture_sizeY / texture_sizeY, VSCANLINES);
  271.  
  272. float3 dotMaskWeights = lerp(
  273. float3(1.0, 0.7, 1.0),
  274. float3(0.7, 1.0, 0.7),
  275. floor(fmod(mod_factor, 2.0))
  276. );
  277.  
  278. color.rgb *= lerp(float3(1.0,1.0,1.0), dotMaskWeights, PHOSPHOR);
  279.  
  280. color = GAMMA_OUT(color);
  281.  
  282. return float4(color, 1.0);
  283. }
  284.  
  285. technique CRTHyllian {
  286. pass CRTHyllian {
  287. VertexShader=PostProcessVS;
  288. PixelShader=PS_CRTHyllian;
  289. }
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement