SHARE
TWEET

Untitled

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