Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. #include "ReShade.fxh"
  2.  
  3. uniform float F_COL <
  4. ui_type = "drag";
  5. ui_min = 0.25;
  6. ui_max = 0.5;
  7. ui_step = 0.25;
  8. ui_label = "F Col";
  9. > = 0.25;
  10.  
  11. uniform float FIR_SIZE <
  12. ui_type = "drag";
  13. ui_min = 1.0;
  14. ui_max = 50.0;
  15. ui_step = 1.0;
  16. ui_label = "FIR Size";
  17. > = 29.0;
  18.  
  19. uniform float F_LUMA_LP <
  20. ui_type = "drag";
  21. ui_min = 0.0001;
  22. ui_max = 0.333333;
  23. ui_step = 0.02;
  24. ui_label = "F Luma LP";
  25. > = 0.16667;
  26.  
  27. uniform float F_COL_BW <
  28. ui_type = "drag";
  29. ui_min = 10.0;
  30. ui_max = 200.0;
  31. ui_step = 1.0;
  32. ui_label = "F Col BW";
  33. > = 50.0;
  34.  
  35. uniform float SATURATION <
  36. ui_type = "drag";
  37. ui_min = 0.0;
  38. ui_max = 100.0;
  39. ui_step = 1.0;
  40. ui_label = "Saturation";
  41. > = 30.0;
  42.  
  43. uniform float BRIGHTNESS <
  44. ui_type = "drag";
  45. ui_min = 0.0;
  46. ui_max = 2.0;
  47. ui_label = "Brightness";
  48. ui_step = 0.01;
  49. > = 1.0;
  50.  
  51. uniform float HUE <
  52. ui_type = "drag";
  53. ui_min = 0.0;
  54. ui_max = 1.0;
  55. ui_step = 0.01;
  56. ui_label = "Hue";
  57. > = 0.0;
  58.  
  59. uniform int Viewmode <
  60. ui_type = "drag";
  61. ui_min = 0;
  62. ui_max = 5;
  63. ui_label = "View Mode";
  64. > = 0;
  65.  
  66. sampler ColorHD { Texture = ReShade::BackBufferTex; Format = RGBA32F;};
  67.  
  68. texture iChannel2_Tex
  69. {
  70. Width = BUFFER_WIDTH;
  71. Height = BUFFER_HEIGHT;
  72. Format = RGBA32F;
  73. };
  74. sampler iChannel2 { Texture = iChannel2_Tex; };
  75.  
  76. texture iChannel0_Tex
  77. {
  78. Width = BUFFER_WIDTH;
  79. Height = BUFFER_HEIGHT;
  80. Format = RGBA32F;
  81. };
  82. sampler iChannel0 { Texture = iChannel0_Tex; };
  83.  
  84. texture iChannel1_Tex
  85. {
  86. Width = BUFFER_WIDTH;
  87. Height = BUFFER_HEIGHT;
  88. Format = RGBA32F;
  89. };
  90. sampler iChannel1 { Texture = iChannel1_Tex; };
  91.  
  92. //Pass 1 Releated Stuff
  93. static const float pi = 3.141592654;
  94. static const float tau = 6.283185308;
  95.  
  96. float3x3 rgb2yiq = float3x3(0.299, 0.596, 0.211,
  97. 0.587,-0.274,-0.523,
  98. 0.114,-0.322, 0.312);
  99.  
  100. float2 Oscillator(float Fo, float Fs, float n)
  101. {
  102. float phase = (tau*Fo*floor(n))/Fs;
  103. return float2(cos(phase),sin(phase));
  104. }
  105.  
  106. float4 PS_Stock(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
  107. {
  108. return tex2D(ColorHD, texcoord).rgba;
  109. }
  110.  
  111. void PS_ArtifactColors0(in float4 pos : SV_POSITION, in float2 uv : TEXCOORD0, out float4 col : COLOR0)
  112. {
  113. float2 texcoord = uv * ReShade::ScreenSize; //this is because the original shader uses OpenGL's fragCoord, which is in texels rather than pixels
  114. float Fs = ReShade::ScreenSize.x;
  115. float Fcol = Fs * F_COL;
  116. float n = floor(texcoord.x);
  117.  
  118. float3 cRGB = tex2D(iChannel0, texcoord / ReShade::ScreenSize.xy).rgb;
  119. float3 cYIQ = rgb2yiq * cRGB;
  120.  
  121. float2 cOsc = Oscillator(Fcol, Fs, n);
  122.  
  123. float sig = cYIQ.x + dot(cOsc, cYIQ.yz);
  124.  
  125. col = float4(sig,0,0,0);
  126. }
  127.  
  128. //Pass 2 Releated Stuff
  129. float4 sample2D(sampler2D sam,float2 resolution, float2 uv)
  130. {
  131. return tex2D(sam, uv / resolution);
  132. }
  133.  
  134. float2 cmul(float2 a, float2 b)
  135. {
  136. return float2((a.x * b.x) - (a.y * b.y), (a.x * b.y) + (a.y * b.x));
  137. }
  138.  
  139. float sinc(float x)
  140. {
  141. return (x == 0.0) ? 1.0 : sin(x*pi)/(x*pi);
  142. }
  143.  
  144. //https://en.wikipedia.org/wiki/Window_function
  145. float WindowBlackman(float a, int N, int i)
  146. {
  147. float a0 = (1.0 - a) / 2.0;
  148. float a1 = 0.5;
  149. float a2 = a / 2.0;
  150.  
  151. float wnd = a0;
  152. wnd -= a1 * cos(2.0 * pi * (float(i) / float(N - 1)));
  153. wnd += a2 * cos(4.0 * pi * (float(i) / float(N - 1)));
  154.  
  155. return wnd;
  156. }
  157.  
  158. //FIR lowpass filter
  159. //Fc = Cutoff freq., Fs = Sample freq., N = # of taps, i = Tap index
  160. float Lowpass(float Fc, float Fs, int N, int i)
  161. {
  162. float wc = (Fc/Fs);
  163.  
  164. float wnd = WindowBlackman(0.16, N, i);
  165.  
  166. return 2.0*wc * wnd * sinc(2.0*wc * float(i - N/2));
  167. }
  168.  
  169. //FIR bandpass filter
  170. //Fa/Fb = Low/High cutoff freq., Fs = Sample freq., N = # of taps, i = Tap index
  171. float Bandpass(float Fa, float Fb, float Fs, int N, int i)
  172. {
  173. float wa = (Fa/Fs);
  174. float wb = (Fb/Fs);
  175.  
  176. float wnd = WindowBlackman(0.16, N, i);
  177.  
  178. return 2.0*(wb-wa) * wnd * (sinc(2.0*wb * float(i - N/2)) - sinc(2.0*wa * float(i - N/2)));
  179. }
  180.  
  181. void PS_ArtifactColors1(in float4 pos : SV_POSITION, in float2 uv : TEXCOORD0, out float4 col : COLOR0)
  182. {
  183. float2 texcoord = uv * ReShade::ScreenSize; //this is because the original shader uses OpenGL's fragCoord, which is in texels rather than pixels
  184. float Fs = ReShade::ScreenSize.x;
  185. float Fcol = Fs * F_COL;
  186. float Fcolbw = Fs * F_COL_BW;
  187. float Flumlp = Fs * F_LUMA_LP;
  188. float n = floor(texcoord.x);
  189.  
  190. float y_sig = 0.0;
  191. float iq_sig = 0.0;
  192.  
  193. float2 cOsc = Oscillator(Fcol, Fs, n);
  194.  
  195. n += float(FIR_SIZE)/2.0;
  196.  
  197. //Separate luma(Y) & chroma(IQ) signals
  198. for(int i = 0;i < FIR_SIZE;i++)
  199. {
  200. int tpidx = FIR_SIZE - i - 1;
  201. float lp = Lowpass(Flumlp, Fs, FIR_SIZE, tpidx);
  202. float bp = Bandpass(Fcol - Fcolbw, Fcol + Fcolbw, Fs, FIR_SIZE, tpidx);
  203.  
  204. y_sig += sample2D(iChannel1, ReShade::ScreenSize.xy, float2(n - float(i), texcoord.y)).r * lp;
  205. iq_sig += sample2D(iChannel1, ReShade::ScreenSize.xy, float2(n - float(i), texcoord.y)).r * bp;
  206. }
  207.  
  208. //Shift IQ signal down from Fcol to DC
  209. float2 iq_sig_mix = cmul(float2(iq_sig, 0), cOsc);
  210.  
  211. col = float4(y_sig, iq_sig_mix, 0);
  212. }
  213.  
  214. //Pass 3 Releated Stuff
  215. float2x2 rotate(float a)
  216. {
  217. return float2x2( cos(a), sin(a),
  218. -sin(a), cos(a));
  219. }
  220.  
  221. float3x3 yiq2rgb = float3x3(1.000, 1.000, 1.000,
  222. 0.956,-0.272,-1.106,
  223. 0.621,-0.647, 1.703);
  224.  
  225. void PS_ArtifactColors2 (in float4 pos : SV_POSITION, in float2 txcoord : TEXCOORD0, out float4 col : COLOR0)
  226. {
  227. float2 texcoord = txcoord * ReShade::ScreenSize; //this is because the original shader uses OpenGL's fragCoord, which is in texels rather than pixels
  228. float Fs = ReShade::ScreenSize.x;
  229. float Fcol = Fs * F_COL;
  230. float Flumlp = Fs * F_LUMA_LP;
  231. float n = floor(texcoord.x);
  232.  
  233. float2 uv = texcoord.xy;
  234.  
  235. float luma = sample2D(iChannel0, ReShade::ScreenSize.xy, uv).r;
  236. float2 chroma = float2(0,0);
  237.  
  238. //Filtering out unwanted high freqency content from the chroma(IQ) signal.
  239. for(int i = 0;i < FIR_SIZE;i++)
  240. {
  241. int tpidx = FIR_SIZE - i - 1;
  242. float lp = Lowpass(Flumlp, Fs, FIR_SIZE, tpidx);
  243. chroma += sample2D(iChannel0, ReShade::ScreenSize.xy, uv - float2(i - FIR_SIZE / 2, 0)).yz * lp;
  244. }
  245.  
  246. chroma *= mul(chroma,rotate(tau * HUE));
  247.  
  248. float3 color = yiq2rgb * float3(BRIGHTNESS * luma, chroma * SATURATION);
  249.  
  250. if(Viewmode == 0){
  251. col = float4(color, 0); //Result
  252. } else if (Viewmode == 1){
  253. col = tex2D(iChannel1, uv / ReShade::ScreenSize.xy); //Stock
  254. } else if (Viewmode == 2){
  255. col = float4(luma,luma,luma,luma); //Luma
  256. } else if (Viewmode == 3){
  257. col = float4(40.0*chroma+0.5,0,0); //Chroma
  258. } else if (Viewmode == 4){
  259. col = 0.5 * tex2D(iChannel2, uv / ReShade::ScreenSize.xy).rrrr+0.25; //Signal
  260. } else {
  261. if(uv.x < ReShade::ScreenSize.x/2.0)
  262. {
  263. col = tex2D(iChannel1, uv / ReShade::ScreenSize.xy);
  264. } else {
  265. col = float4(color, 0);
  266. }
  267. }
  268. }
  269.  
  270. technique ArtifactColors {
  271. pass ArtifactColorsStock{
  272. RenderTarget = iChannel1_Tex;
  273. VertexShader=PostProcessVS;
  274. PixelShader=PS_Stock;
  275. }
  276. pass ArtifactColors0 {
  277. RenderTarget = iChannel2_Tex;
  278. VertexShader=PostProcessVS;
  279. PixelShader=PS_ArtifactColors0;
  280. }
  281. pass ArtifactColors1 {
  282. RenderTarget = iChannel0_Tex;
  283. VertexShader=PostProcessVS;
  284. PixelShader=PS_ArtifactColors1;
  285. }
  286. pass ArtifactColors2 {
  287. //RenderTarget = iChannel1_Tex;
  288. VertexShader=PostProcessVS;
  289. PixelShader=PS_ArtifactColors2;
  290. }
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement