S0N0S

>GeDoSaTo>config>DarkSoulsII>post.fx

Oct 24th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 65.04 KB | None | 0 0
  1. // Post processing effect file
  2. // most shader code taken from SweetFX 1.5.1
  3.  
  4. // -------------------- Settings -----------------------------------------------
  5.  
  6. // Set to 1 for ON or 0 for OFF
  7. #define USE_BLOOM 1 //[0 or 1] Bloom : Makes bright lights bleed their light into their surroundings (relatively high performance cost)
  8. #define USE_HDR 1 //[0 or 1] HDR : Not actual HDR - It just tries to mimic an HDR look (relatively high performance cost)
  9. #define USE_LUMASHARPEN 1 //[0 or 1] LumaSharpen
  10. #define USE_VIBRANCE 0 //[0 or 1] Vibrance : Intelligently saturates (or desaturates if you use negative values) the pixels depending on their original saturation.
  11. #define USE_TONEMAP 0 //[0 or 1] Tonemap : Adjust gamma, exposure, saturation, bleach and defog. (may cause clipping)
  12. #define USE_CA 0 //[0 or 1] Chromatic aberration. You can only use Chromatic Aberration OR the Explosion Shader. Not both at the same time.
  13. #define USE_CURVES 1 //[0 or 1] Curves : Contrast adjustments using S-curves.
  14. #define USE_DITHER 1 //[0 or 1] Dither : Applies dithering to simulate more colors than your monitor can display. This lessens banding artifacts (mostly caused by Vignette)
  15. #define USE_ADVANCED_CRT 0 //[0 or 1] Advanced CRT : Simulates an old CRT TV display. Set gaussian blur along with it to get a halation effect
  16. #define USE_TECHNICOLOR 0 //[0 or 1] TECHNICOLOR : Attempts to mimic the look of an old movie using the Technicolor three-strip color process (Techicolor Process 4)
  17. #define USE_DPX 1 //[0 or 1] Cineon DPX : Should make the image look like it's been converted to DXP Cineon - basically it's another movie-like look similar to technicolor.
  18. #define USE_GRAIN 1 //[0 or 1] Film Grain: Adds an active graininess to the image. Helps with banding and can add the illusion of detail
  19. #define USE_BORDER 0 //[0 or 1] Border : Makes the screenedge black as a workaround for the bright edge that forcing some AA modes sometimes causes.
  20. #define USE_SPLITSCREEN 0 //[0 or 1] Splitscreen : Enables the before-and-after splitscreen comparison mode.
  21. #define USE_SINCITY 0 //[0 or 1] SinCity : Make the game look like the movie Sin City. Use with Tonemap gamma, default value of 0.6.
  22.  
  23. // Bloom settings
  24. #define BloomThreshold 20.25 // [0.00 to 50.00] Threshold for what is a bright light (that causes bloom) and what isn't.
  25. #define BloomPower 1.000 // [0.00 to 8.00] Strength of the bloom
  26. #define BloomWidth 0.035 // [0.00 to 1.00] Width of the bloom
  27.  
  28. // HDR settings
  29. #define HDRPower 1.15 // [0.00 to 8.00] Strangely lowering this makes the image brighter
  30. #define radius2 0.82 // [0.00 to 8.00] Raising this seems to make the effect stronger and also brighter
  31.  
  32. // LumaSharpen settings
  33. #define sharp_strength 0.75 // [0.10 to 3.00] Strength of the sharpening
  34. #define sharp_clamp 0.035 // [0.00 to 1.00] Limits maximum amount of sharpening a pixel recieves - Default is 0.035
  35. #define pattern 2 // [1|2|3|4] Choose a sample pattern. 1 = Fast, 2 = Normal, 3 = Wider, 4 = Pyramid shaped.
  36.  
  37. // Vibrance settings
  38. #define Vibrance -0.01 // [-1.00 to 1.00] Intelligently saturates (or desaturates if you use negative values) the pixels depending on their original saturation.
  39. #define Vibrance_RGB_balance float3(1.00, 1.00, 1.00) // [-10.00 to 10.00,-10.00 to 10.00,-10.00 to 10.00] A per channel multiplier to the Vibrance strength so you can give more boost to certain colors over others
  40.  
  41. // Tonemap settings
  42. #define Gamma 1.1 //[0.000 to 2.000] Adjust midtones
  43. #define Exposure 0.0 //[-1.000 to 1.000] Adjust exposure
  44. #define Saturation 0.0 //[-1.000 to 1.000] Adjust saturation
  45. #define Bleach 0.0 //[0.000 to 1.000] Brightens the shadows and fades the colors
  46. #define Defog 1.0 //[0.000 to 1.000] How much of the color tint to remove
  47. #define FogColor float3(0.0, 0.0, 0.0) //[0.00 to 2.55, 0.00 to 2.55, 0.00 to 2.55] What color to remove - default is blue
  48.  
  49. // Chromatic Abberation settings
  50. #define outfocus 0.001 //[0.00 to 1.000] How strong the effect should be.
  51.  
  52. // Curves settings
  53. #define Curves_mode 2 //[0|1|2] Choose what to apply contrast to. 0 = Luma, 1 = Chroma, 2 = both Luma and Chroma. Default is 0 (Luma)
  54. #define Curves_contrast 0.2 //[-1.00 to 1.00] The amount of contrast you want
  55.  
  56. // -- Advanced curve settings --
  57. #define Curves_formula 7 //[1|2|3|4|5|6|7|8|9|10] The contrast s-curve you want to use.
  58. //1 = Sine, 2 = Abs split, 3 = Smoothstep, 4 = Exp formula, 5 = Simplified Catmull-Rom (0,0,1,1), 6 = Perlins Smootherstep
  59. //Note that Technicolor Cinestyle is practically identical to Sine, but runs slower. In fact I think the difference might only be due to rounding errors.
  60. //I prefer 2 myself, but 3 is a nice alternative with a little more effect (but harsher on the highlight and shadows) and it's the fastest formula.
  61.  
  62. // Dither settings
  63. #define dither_method 2 //[1 or 2] 1 = Ordered dithering (very good and very fast), 2 = Random dithering (different but slightly slower dithering)
  64. //Note that the patterns used by Dither, makes an image harder to compress.
  65. //This can make your screenshots and video recordings take up more space.
  66.  
  67. // Advanced CRT settings
  68. #define CRTAmount 1.00 //[0.00 to 1.00] Amount of CRT effect you want
  69.  
  70. #define CRTResolutionX (SCREEN_SIZE.x) / 4 //[1 to 2048] Original input width of the game. Default is 1/4 horizontal screen resolution
  71. #define CRTResolutionY (SCREEN_SIZE.y) / 4 //[1 to 2048] Original input height of the game. Default is 1/4 vertical screen resolution
  72. #define CRTgamma 2.2 //[0.0 to 4.0] Gamma of simulated CRT (default 2.2)
  73. #define CRTmonitorgamma 2.4 //[0.0 to 4.0] Gamma of display monitor (typically 2.2 is correct)
  74. #define CRTBrightness 1.2 //[1.0 to 3.0] Used to boost brightness a little. Default is 1.0
  75. #define CRTScanlineIntensity 2.0 //[2.0 to 4.0] Scanlines intensity (use integer values preferably). Default is 2.0
  76. #define CRTScanlineGaussian 1 //[0 or 1] Use the "new nongaussian scanlines bloom effect". Default is on
  77.  
  78. #define CRTCurvature 1 //[[0 or 1] "Barrel effect" enabled (1) or off (0)
  79. #define CRTCurvatureRadius 2.0 //[0.0 to 2.0] Curvature Radius (only effective when Curvature is enabled). Default is 1.5
  80. #define CRTCornerSize 0.0100 //[0.0000 to 0.0020] Higher values, more rounded corner. Default is 0.001
  81. #define CRTDistance 2.00 //[0.00 to 4.00] Simulated distance from viewer to monitor. Default is 2.00
  82. #define CRTAngleX 0.00 //[-0.20 to 0.20] Tilt angle in radians (X coordinates)
  83. #define CRTAngleY -0.15 //[-0.20 to 0.20] Tilt angle in radians (Y coordinates). (Value of -0.15 gives the 'arcade tilt' look)
  84. #define CRTOverScan 1.00 //[1.00 to 1.10] Overscan (e.g. 1.02 for 2% overscan). Default is 1.01
  85. #define CRTOversample 0 //[0 or 1] Enable 3x oversampling of the beam profile (warning : performance hit)
  86.  
  87. // ----Advanced Advanced CRT settings
  88. //Amount of R,G,B tint for even scanlines, and amount of R,G,B tint for the odd scanlines. 1.0 is unchanged color
  89. #define R1 1 //[0.0 to 1.0] Amount of red color for even scanlines
  90. #define G1 0.7 //[0.0 to 1.0] Amount of green color for even scanlines
  91. #define B1 1 //[0.0 to 1.0] Amount of blue color for even scanlines
  92.  
  93. #define R2 0.7 //[0.0 to 1.0] Amount of red color for odd scanlines
  94. #define G2 1.0 //[0.0 to 1.0] Amount of green color for odd scanlines
  95. #define B2 0.7 //[0.0 to 1.0] Amount of blue color for odd scanlines
  96.  
  97. // Technicolor settings
  98. #define TechniAmount 0.46 //[0.00 to 1.00]
  99. #define TechniPower 4.0 //[0.00 to 8.00]
  100. #define redNegativeAmount 0.74 //[0.00 to 1.00]
  101. #define greenNegativeAmount 0.83 //[0.00 to 1.00]
  102. #define blueNegativeAmount 0.9 //[0.00 to 1.00]
  103.  
  104. // Cineon DPX settings
  105. #define Red 9.0 //[1.0 to 15.0]
  106. #define Green 9.0 //[1.0 to 15.0]
  107. #define Blue 9.0 //[1.0 to 15.0]
  108.  
  109. #define ColorGamma 2.5 //[0.1 to 2.5] Adjusts the colorfulness of the effect in a manner similar to Vibrance. 1.0 is neutral.
  110. #define DPXSaturation 1.0 //[0.0 to 8.0] Adjust saturation of the effect. 1.0 is neutral.
  111.  
  112. #define RedC 0.42 //[0.60 to 0.20]
  113. #define GreenC 0.40 //[0.60 to 0.20]
  114. #define BlueC 0.40 //[0.60 to 0.20]
  115.  
  116. #define Blend 0.1 //[0.00 to 1.00] How strong the effect should be
  117.  
  118. // Grain Settings
  119. #define GrainPower 0.04 //[0.00 to 1.00] Intensity of applied grain
  120. #define GrainColored 1 //[0 or 1] Whether grain should be colored or not
  121. #define GrainColorAmount 0.6//[0.00 to 1.00] Amount of color to add to grain
  122. #define GrainSize 1.5//[1.50 to 2.50] Size of individual pieces of grain
  123. #define GrainLuma 1.0//[0.00 to 1.00] Grain brightness
  124.  
  125. // Border settings
  126. #define border_width float2(0,0) //[0 to 2048, 0 to 2048] (X,Y)-width of the border. Measured in pixels. If this is set to 0,0 then the border_ratio will be used instead
  127. #define border_ratio float(0.75 / 1.0) //[0.1000 to 10.0000] Set the desired ratio for the visible area. You MUST use floating point - Integers do not work right.
  128. //Examples that work: (1680.0 / 1050.0), (16.0 / 10.0), (1.6) Examples that does NOT work right: (1680 / 1050), (16 / 10)
  129. #define border_color float3(0, 0, 0) //[0 to 255, 0 to 255, 0 to 255] What color the border should be. In integer RGB colors, meaning 0,0,0 is black and 255,255,255 is full white.
  130.  
  131. // Splitscreen settings
  132. #define splitscreen_mode 1 //[1|2|3|4|5|6] 1 = Vertical 50/50 split, 2 = Vertical 25/50/25 split, 3 = Vertical 50/50 angled split,
  133. // 4 = Horizontal 50/50 split, 5 = Horizontal 25/50/25 split, 6 = Curvy vertical 50/50 split
  134.  
  135. // SinCity settings
  136. #define sincity_strength 1.00 //[0.00 to 1.00] This setting is a placeholder and does nothing at the moment.
  137.  
  138. // -------------------- Interface -----------------------------------------------
  139.  
  140. texture2D thisframeTex;
  141.  
  142. static float2 rcpres = PIXEL_SIZE;
  143.  
  144. const float timer;
  145.  
  146. #ifndef USE_SRGB
  147. #define USE_SRGB true
  148. #endif
  149.  
  150. sampler s0 = sampler_state
  151. {
  152. texture = <thisframeTex>;
  153. AddressU = CLAMP;
  154. AddressV = CLAMP;
  155. MINFILTER = LINEAR;
  156. MAGFILTER = LINEAR;
  157. SRGBTexture = USE_SRGB;
  158. };
  159.  
  160. struct VSOUT
  161. {
  162. float4 vertPos : POSITION;
  163. float2 UVCoord : TEXCOORD0;
  164. };
  165.  
  166. struct VSIN
  167. {
  168. float4 vertPos : POSITION0;
  169. float2 UVCoord : TEXCOORD0;
  170. };
  171.  
  172. VSOUT FrameVS(VSIN IN)
  173. {
  174. VSOUT OUT;
  175. OUT.vertPos = IN.vertPos;
  176. OUT.UVCoord = IN.UVCoord;
  177. return OUT;
  178. }
  179.  
  180. // -------------------- Effects -----------------------------------------------
  181.  
  182. /*
  183. _____________________
  184.  
  185. LumaSharpen 1.4.1
  186. _____________________
  187.  
  188. by Christian Cann Schuldt Jensen ~ CeeJay.dk
  189.  
  190. It blurs the original pixel with the surrounding pixels and then subtracts this blur to sharpen the image.
  191. It does this in luma to avoid color artifacts and allows limiting the maximum sharpening to avoid or lessen halo artifacts.
  192.  
  193. This is similar to using Unsharp Mask in Photoshop.
  194.  
  195. Compiles with 3.0
  196. */
  197.  
  198. #ifndef offset_bias
  199. #define offset_bias 1.0
  200. #endif
  201.  
  202. #define px (rcpres.x)
  203. #define py (rcpres.y)
  204.  
  205. /*-----------------------------------------------------------.
  206. / Developer settings /
  207. '-----------------------------------------------------------*/
  208. #define CoefLuma float3(0.2126, 0.7152, 0.0722) // BT.709 & sRBG luma coefficient (Monitors and HD Television)
  209. //#define CoefLuma float3(0.299, 0.587, 0.114) // BT.601 luma coefficient (SD Television)
  210. //#define CoefLuma float3(1.0/3.0, 1.0/3.0, 1.0/3.0) // Equal weight coefficient
  211.  
  212. /*-----------------------------------------------------------.
  213. / Main code /
  214. '-----------------------------------------------------------*/
  215.  
  216. float4 LumaSharpenPass(float4 inputcolor, float2 tex )
  217. {
  218. // -- Get the original pixel --
  219. float3 ori = tex2D(s0, tex).rgb; // ori = original pixel
  220.  
  221. // -- Combining the strength and luma multipliers --
  222. float3 sharp_strength_luma = (CoefLuma * sharp_strength); //I'll be combining even more multipliers with it later on
  223.  
  224. /*-----------------------------------------------------------.
  225. / Sampling patterns /
  226. '-----------------------------------------------------------*/
  227. // [ NW, , NE ] Each texture lookup (except ori)
  228. // [ ,ori, ] samples 4 pixels
  229. // [ SW, , SE ]
  230.  
  231. // -- Pattern 1 -- A (fast) 7 tap gaussian using only 2+1 texture fetches.
  232. #if pattern == 1
  233.  
  234. // -- Gaussian filter --
  235. // [ 1/9, 2/9, ] [ 1 , 2 , ]
  236. // [ 2/9, 8/9, 2/9] = [ 2 , 8 , 2 ]
  237. // [ , 2/9, 1/9] [ , 2 , 1 ]
  238.  
  239. float3 blur_ori = tex2D(s0, tex + (float2(px,py) / 3.0) * offset_bias).rgb; // North West
  240. blur_ori += tex2D(s0, tex + (float2(-px,-py) / 3.0) * offset_bias).rgb; // South East
  241.  
  242. //blur_ori += tex2D(s0, tex + float2(px,py) / 3.0 * offset_bias); // North East
  243. //blur_ori += tex2D(s0, tex + float2(-px,-py) / 3.0 * offset_bias); // South West
  244.  
  245. blur_ori /= 2; //Divide by the number of texture fetches
  246.  
  247. sharp_strength_luma *= 1.5; // Adjust strength to aproximate the strength of pattern 2
  248.  
  249. #endif
  250.  
  251. // -- Pattern 2 -- A 9 tap gaussian using 4+1 texture fetches.
  252. #if pattern == 2
  253.  
  254. // -- Gaussian filter --
  255. // [ .25, .50, .25] [ 1 , 2 , 1 ]
  256. // [ .50, 1, .50] = [ 2 , 4 , 2 ]
  257. // [ .25, .50, .25] [ 1 , 2 , 1 ]
  258.  
  259.  
  260. float3 blur_ori = tex2D(s0, tex + float2(px,-py) * 0.5 * offset_bias).rgb; // South East
  261. blur_ori += tex2D(s0, tex + float2(-px,-py) * 0.5 * offset_bias).rgb; // South West
  262. blur_ori += tex2D(s0, tex + float2(px,py) * 0.5 * offset_bias).rgb; // North East
  263. blur_ori += tex2D(s0, tex + float2(-px,py) * 0.5 * offset_bias).rgb; // North West
  264.  
  265. blur_ori *= 0.25; // ( /= 4) Divide by the number of texture fetches
  266.  
  267. #endif
  268.  
  269. // -- Pattern 3 -- An experimental 17 tap gaussian using 4+1 texture fetches.
  270. #if pattern == 3
  271.  
  272. // -- Gaussian filter --
  273. // [ , 4 , 6 , , ]
  274. // [ ,16 ,24 ,16 , 4 ]
  275. // [ 6 ,24 , ,24 , 6 ]
  276. // [ 4 ,16 ,24 ,16 , ]
  277. // [ , , 6 , 4 , ]
  278.  
  279. float3 blur_ori = tex2D(s0, tex + float2(0.4*px,-1.2*py)* offset_bias).rgb; // South South East
  280. blur_ori += tex2D(s0, tex + float2(-1.2*px,-0.4*py) * offset_bias).rgb; // West South West
  281. blur_ori += tex2D(s0, tex + float2(1.2*px,0.4*py) * offset_bias).rgb; // East North East
  282. blur_ori += tex2D(s0, tex + float2(-0.4*px,1.2*py) * offset_bias).rgb; // North North West
  283.  
  284. blur_ori *= 0.25; // ( /= 4) Divide by the number of texture fetches
  285.  
  286. sharp_strength_luma *= 0.51;
  287. #endif
  288.  
  289. // -- Pattern 4 -- A 9 tap high pass (pyramid filter) using 4+1 texture fetches.
  290. #if pattern == 4
  291.  
  292. // -- Gaussian filter --
  293. // [ .50, .50, .50] [ 1 , 1 , 1 ]
  294. // [ .50, , .50] = [ 1 , , 1 ]
  295. // [ .50, .50, .50] [ 1 , 1 , 1 ]
  296.  
  297. float3 blur_ori = tex2D(s0, tex + float2(0.5 * px,-py * offset_bias)).rgb; // South South East
  298. blur_ori += tex2D(s0, tex + float2(offset_bias * -px,0.5 * -py)).rgb; // West South West
  299. blur_ori += tex2D(s0, tex + float2(offset_bias * px,0.5 * py)).rgb; // East North East
  300. blur_ori += tex2D(s0, tex + float2(0.5 * -px,py * offset_bias)).rgb; // North North West
  301.  
  302. //blur_ori += (2 * ori); // Probably not needed. Only serves to lessen the effect.
  303.  
  304. blur_ori /= 4.0; //Divide by the number of texture fetches
  305.  
  306. sharp_strength_luma *= 0.666; // Adjust strength to aproximate the strength of pattern 2
  307. #endif
  308.  
  309. // -- Pattern 8 -- A (slower) 9 tap gaussian using 9 texture fetches.
  310. #if pattern == 8
  311.  
  312. // -- Gaussian filter --
  313. // [ 1 , 2 , 1 ]
  314. // [ 2 , 4 , 2 ]
  315. // [ 1 , 2 , 1 ]
  316.  
  317. half3 blur_ori = tex2D(s0, tex + float2(-px,py) * offset_bias).rgb; // North West
  318. blur_ori += tex2D(s0, tex + float2(px,-py) * offset_bias).rgb; // South East
  319. blur_ori += tex2D(s0, tex + float2(-px,-py) * offset_bias).rgb; // South West
  320. blur_ori += tex2D(s0, tex + float2(px,py) * offset_bias).rgb; // North East
  321.  
  322. half3 blur_ori2 = tex2D(s0, tex + float2(0,py) * offset_bias).rgb; // North
  323. blur_ori2 += tex2D(s0, tex + float2(0,-py) * offset_bias).rgb; // South
  324. blur_ori2 += tex2D(s0, tex + float2(-px,0) * offset_bias).rgb; // West
  325. blur_ori2 += tex2D(s0, tex + float2(px,0) * offset_bias).rgb; // East
  326. blur_ori2 *= 2.0;
  327.  
  328. blur_ori += blur_ori2;
  329. blur_ori += (ori * 4); // Probably not needed. Only serves to lessen the effect.
  330.  
  331. // dot()s with gaussian strengths here?
  332.  
  333. blur_ori /= 16.0; //Divide by the number of texture fetches
  334.  
  335. //sharp_strength_luma *= 0.75; // Adjust strength to aproximate the strength of pattern 2
  336. #endif
  337.  
  338. // -- Pattern 9 -- A (slower) 9 tap high pass using 9 texture fetches.
  339. #if pattern == 9
  340.  
  341. // -- Gaussian filter --
  342. // [ 1 , 1 , 1 ]
  343. // [ 1 , 1 , 1 ]
  344. // [ 1 , 1 , 1 ]
  345.  
  346. float3 blur_ori = tex2D(s0, tex + float2(-px,py) * offset_bias).rgb; // North West
  347. blur_ori += tex2D(s0, tex + float2(px,-py) * offset_bias).rgb; // South East
  348. blur_ori += tex2D(s0, tex + float2(-px,-py) * offset_bias).rgb; // South West
  349. blur_ori += tex2D(s0, tex + float2(px,py) * offset_bias).rgb; // North East
  350.  
  351. blur_ori += ori.rgb; // Probably not needed. Only serves to lessen the effect.
  352.  
  353. blur_ori += tex2D(s0, tex + float2(0,py) * offset_bias).rgb; // North
  354. blur_ori += tex2D(s0, tex + float2(0,-py) * offset_bias).rgb; // South
  355. blur_ori += tex2D(s0, tex + float2(-px,0) * offset_bias).rgb; // West
  356. blur_ori += tex2D(s0, tex + float2(px,0) * offset_bias).rgb; // East
  357.  
  358. blur_ori /= 9; //Divide by the number of texture fetches
  359.  
  360. //sharp_strength_luma *= (8.0/9.0); // Adjust strength to aproximate the strength of pattern 2
  361. #endif
  362.  
  363.  
  364. /*-----------------------------------------------------------.
  365. / Sharpen /
  366. '-----------------------------------------------------------*/
  367.  
  368. // -- Calculate the sharpening --
  369. float3 sharp = ori - blur_ori; //Subtracting the blurred image from the original image
  370.  
  371. #if 0 //New experimental limiter .. not yet finished
  372. float sharp_luma = dot(sharp, sharp_strength_luma); //Calculate the luma
  373. sharp_luma = (abs(sharp_luma)*8.0) * exp(1.0-(abs(sharp_luma)*8.0)) * sign(sharp_luma) / 16.0; //I should probably move the strength modifier here
  374.  
  375. #elif 0 //SweetFX 1.4 code
  376. // -- Adjust strength of the sharpening --
  377. float sharp_luma = dot(sharp, sharp_strength_luma); //Calculate the luma and adjust the strength
  378.  
  379. // -- Clamping the maximum amount of sharpening to prevent halo artifacts --
  380. sharp_luma = clamp(sharp_luma, -sharp_clamp, sharp_clamp); //TODO Try a curve function instead of a clamp
  381.  
  382. #else //SweetFX 1.5.1 code
  383. // -- Adjust strength of the sharpening and clamp it--
  384. float4 sharp_strength_luma_clamp = float4(sharp_strength_luma * (0.5 / sharp_clamp),0.5); //Roll part of the clamp into the dot
  385.  
  386. //sharp_luma = saturate((0.5 / sharp_clamp) * sharp_luma + 0.5); //scale up and clamp
  387. float sharp_luma = saturate(dot(float4(sharp,1.0), sharp_strength_luma_clamp)); //Calculate the luma, adjust the strength, scale up and clamp
  388. sharp_luma = (sharp_clamp * 2.0) * sharp_luma - sharp_clamp; //scale down
  389. #endif
  390.  
  391. // -- Combining the values to get the final sharpened pixel --
  392. //float4 done = ori + sharp_luma; // Add the sharpening to the original.
  393. inputcolor.rgb = inputcolor.rgb + sharp_luma; // Add the sharpening to the input color.
  394.  
  395. /*-----------------------------------------------------------.
  396. / Returning the output /
  397. '-----------------------------------------------------------*/
  398. #ifndef show_sharpen
  399. #define show_sharpen 0
  400. #endif
  401. #if show_sharpen == 1
  402. //inputcolor.rgb = abs(sharp * 4.0);
  403. inputcolor.rgb = saturate(0.5 + (sharp_luma * 4)).rrr;
  404. #endif
  405.  
  406. return saturate(inputcolor);
  407.  
  408. }
  409.  
  410. // -------------------- Bloom -----------------------------------------------
  411.  
  412. float4 BloomPass(float4 ColorInput2, float2 Tex)
  413. {
  414. float3 BlurColor2 = 0;
  415. float3 Blurtemp = 0;
  416. float MaxDistance = 8*BloomWidth;
  417. float CurDistance = 0;
  418.  
  419. float Samplecount = 25.0;
  420.  
  421. float2 blurtempvalue = Tex * rcpres * BloomWidth;
  422.  
  423. float2 BloomSample = float2(2.5,-2.5);
  424. float2 BloomSampleValue;
  425.  
  426. for(BloomSample.x = (2.5); BloomSample.x > -2.0; BloomSample.x = BloomSample.x - 1.0) // runs 5 times
  427. {
  428. BloomSampleValue.x = BloomSample.x * blurtempvalue.x;
  429. float2 distancetemp = BloomSample.x * BloomSample.x * BloomWidth;
  430.  
  431. for(BloomSample.y = (- 2.5); BloomSample.y < 2.0; BloomSample.y = BloomSample.y + 1.0) // runs 5 ( * 5) times
  432. {
  433. distancetemp.y = BloomSample.y * BloomSample.y;
  434. CurDistance = (distancetemp.y * BloomWidth) + distancetemp.x;
  435.  
  436. BloomSampleValue.y = BloomSample.y * blurtempvalue.y;
  437. Blurtemp.rgb = tex2D(s0, float2(Tex + BloomSampleValue)).rgb;
  438.  
  439. BlurColor2.rgb += lerp(Blurtemp.rgb,ColorInput2.rgb, sqrt(CurDistance / MaxDistance));
  440. }
  441. }
  442. BlurColor2.rgb = (BlurColor2.rgb / (Samplecount - (BloomPower - BloomThreshold*5)));
  443. float Bloomamount = (dot(ColorInput2.rgb,float3(0.299f, 0.587f, 0.114f)));
  444. float3 BlurColor = BlurColor2.rgb * (BloomPower + 4.0);
  445.  
  446. ColorInput2.rgb = lerp(ColorInput2.rgb,BlurColor.rgb, Bloomamount);
  447. return saturate(ColorInput2);
  448. }
  449.  
  450. // -------------------- HDR -----------------------------------------------
  451.  
  452. float4 HDRPass(float4 colorInput, float2 Tex)
  453. {
  454. float3 c_center = tex2D(s0, Tex).rgb;
  455.  
  456. float radius1 = 0.793;
  457. float3 bloom_sum1 = tex2D(s0, Tex + float2(1.5, -1.5) * radius1).rgb;
  458. bloom_sum1 += tex2D(s0, Tex + float2(-1.5, -1.5) * radius1).rgb;
  459. bloom_sum1 += tex2D(s0, Tex + float2(1.5, 1.5) * radius1).rgb;
  460. bloom_sum1 += tex2D(s0, Tex + float2(-1.5, 1.5) * radius1).rgb;
  461.  
  462. bloom_sum1 += tex2D(s0, Tex + float2(0, -2.5) * radius1).rgb;
  463. bloom_sum1 += tex2D(s0, Tex + float2(0, 2.5) * radius1).rgb;
  464. bloom_sum1 += tex2D(s0, Tex + float2(-2.5, 0) * radius1).rgb;
  465. bloom_sum1 += tex2D(s0, Tex + float2(2.5, 0) * radius1).rgb;
  466.  
  467. bloom_sum1 *= 0.005;
  468.  
  469. float3 bloom_sum2 = tex2D(s0, Tex + float2(1.5, -1.5) * radius2).rgb;
  470. bloom_sum2 += tex2D(s0, Tex + float2(-1.5, -1.5) * radius2).rgb;
  471. bloom_sum2 += tex2D(s0, Tex + float2(1.5, 1.5) * radius2).rgb;
  472. bloom_sum2 += tex2D(s0, Tex + float2(-1.5, 1.5) * radius2).rgb;
  473.  
  474.  
  475. bloom_sum2 += tex2D(s0, Tex + float2(0, -2.5) * radius2).rgb;
  476. bloom_sum2 += tex2D(s0, Tex + float2(0, 2.5) * radius2).rgb;
  477. bloom_sum2 += tex2D(s0, Tex + float2(-2.5, 0) * radius2).rgb;
  478. bloom_sum2 += tex2D(s0, Tex + float2(2.5, 0) * radius2).rgb;
  479.  
  480. bloom_sum2 *= 0.010;
  481.  
  482. float dist = radius2 - radius1;
  483.  
  484. float3 HDR = (c_center + (bloom_sum2 - bloom_sum1)) * dist;
  485. float3 blend = HDR + colorInput.rgb;
  486. colorInput.rgb = HDR + pow(blend, HDRPower); // pow - don't use fractions for HDRpower
  487.  
  488. return saturate(colorInput);
  489. }
  490.  
  491. // -------------------- Vibrance -----------------------------------------------
  492.  
  493. float4 VibrancePass(float4 colorInput)
  494. {
  495. #define Vibrance_coeff float3(Vibrance_RGB_balance * Vibrance)
  496.  
  497. float4 color = colorInput; //original input color
  498. float3 lumCoeff = float3(0.212656, 0.715158, 0.072186); //Values to calculate luma with
  499.  
  500. float luma = dot(lumCoeff, color.rgb); //calculate luma (grey)
  501.  
  502. float max_color = max(colorInput.r, max(colorInput.g,colorInput.b)); //Find the strongest color
  503. float min_color = min(colorInput.r, min(colorInput.g,colorInput.b)); //Find the weakest color
  504.  
  505. float color_saturation = max_color - min_color; //The difference between the two is the saturation
  506.  
  507. color.rgb = lerp(luma, color.rgb, (1.0 + (Vibrance_coeff * (1.0 - (sign(Vibrance_coeff) * color_saturation)))));
  508. return color;
  509. }
  510.  
  511. // -------------------------Tonemap--------------------------------------------
  512.  
  513. float4 TonemapPass(float4 colorInput)
  514. {
  515. float3 color = colorInput.rgb;
  516.  
  517. color = saturate(color - Defog * FogColor); // Defog
  518.  
  519. color *= pow(2.0f, Exposure); // Exposure
  520.  
  521. color = pow(color, Gamma); // Gamma -- roll into the first gamma correction in main.h ?
  522.  
  523. //#define BlueShift 0.00 //Blueshift
  524. //float4 d = color * float4(1.05f, 0.97f, 1.27f, color.a);
  525. //color = lerp(color, d, BlueShift);
  526.  
  527. float3 lumCoeff = float3(0.2126, 0.7152, 0.0722);
  528. float lum = dot(lumCoeff, color.rgb);
  529.  
  530. float3 blend = lum.rrr; //dont use float3
  531.  
  532. float L = saturate( 10.0 * (lum - 0.45) );
  533.  
  534. float3 result1 = 2.0f * color.rgb * blend;
  535. float3 result2 = 1.0f - 2.0f * (1.0f - blend) * (1.0f - color.rgb);
  536.  
  537. float3 newColor = lerp(result1, result2, L);
  538. //float A2 = Bleach * color.rgb; //why use a float for A2 here and then multiply by color.rgb (a float3)?
  539. float3 A2 = Bleach * color.rgb; //
  540. float3 mixRGB = (A2 * newColor.r, A2 * newColor.g, A2*newColor.b);
  541.  
  542. color.rgb += ((1.0f - A2) * mixRGB);
  543.  
  544. //float3 middlegray = float(color.r + color.g + color.b) / 3;
  545. float3 middlegray = dot(color,(1.0/3.0)); //1fps slower than the original on nvidia, 2 fps faster on AMD
  546.  
  547. float3 diffcolor = color - middlegray; //float 3 here
  548. colorInput.rgb = (color + diffcolor * Saturation)/(1+(diffcolor*Saturation)); //saturation
  549.  
  550. return colorInput;
  551. }
  552.  
  553.  
  554. // ------------------------- Chromatic Abberation --------------------------------------------
  555.  
  556. #define CHROMA_POW 35.0
  557.  
  558. float3 fvChroma = float3(0.995, 1.000, 1.005);
  559.  
  560. float4 ChromaticAberrationFocus(float2 tex, float outOfFocus)
  561. {
  562. float3 chroma = pow(fvChroma, CHROMA_POW * outOfFocus);
  563.  
  564. float2 tr = ((2.0 * tex - 1.0) * chroma.r) * 0.5 + 0.5;
  565. float2 tg = ((2.0 * tex - 1.0) * chroma.g) * 0.5 + 0.5;
  566. float2 tb = ((2.0 * tex - 1.0) * chroma.b) * 0.5 + 0.5;
  567.  
  568. float3 color = float3(tex2D(s0, tr).r, tex2D(s0, tg).g, tex2D(s0, tb).b) * (1.0 - outOfFocus);
  569.  
  570. return float4(color, 1.0);
  571. }
  572.  
  573. float4 CAPass(float4 colorInput, float2 tex)
  574. {
  575. return ChromaticAberrationFocus(tex, outfocus);
  576. }
  577.  
  578. // ------------------------- Curves --------------------------------------------
  579.  
  580. float4 CurvesPass( float4 colorInput )
  581. {
  582. float3 lumCoeff = float3(0.2126, 0.7152, 0.0722); //Values to calculate luma with
  583. float Curves_contrast_blend = Curves_contrast;
  584. float PI = acos(-1); //3.1415926589
  585.  
  586. // --------------------------------- Separation of Luma and Chroma
  587.  
  588. // -- Calculate Luma and Chroma if needed --
  589. #if Curves_mode != 2
  590.  
  591. //calculate luma (grey)
  592. float luma = dot(lumCoeff, colorInput.rgb);
  593.  
  594. //calculate chroma
  595. float3 chroma = colorInput.rgb - luma;
  596. #endif
  597.  
  598. // -- Which value to put through the contrast formula? --
  599. // I name it x because makes it easier to copy-paste to Graphtoy or Wolfram Alpha or another graphing program
  600. #if Curves_mode == 2
  601. float3 x = colorInput.rgb; //if the curve should be applied to both Luma and Chroma
  602. #elif Curves_mode == 1
  603. float3 x = chroma; //if the curve should be applied to Chroma
  604. x = x * 0.5 + 0.5; //adjust range of Chroma from -1 -> 1 to 0 -> 1
  605. #else // Curves_mode == 0
  606. float x = luma; //if the curve should be applied to Luma
  607. #endif
  608.  
  609. // --------------------------------- Contrast formulas
  610.  
  611. // -- Curve 1 --
  612. #if Curves_formula == 1
  613. x = sin(PI * 0.5 * x); // Sin - 721 amd fps, +vign 536 nv
  614. x *= x;
  615.  
  616. //x = 0.5 - 0.5*cos(PI*x);
  617. //x = 0.5 * -sin(PI * -x + (PI*0.5)) + 0.5;
  618. #endif
  619.  
  620. // -- Curve 2 --
  621. #if Curves_formula == 2
  622. x = x - 0.5;
  623. x = ( x / (0.5 + abs(x)) ) + 0.5;
  624.  
  625. //x = ( (x - 0.5) / (0.5 + abs(x-0.5)) ) + 0.5;
  626. #endif
  627.  
  628. // -- Curve 3 --
  629. #if Curves_formula == 3
  630. //x = smoothstep(0.0,1.0,x); //smoothstep
  631. x = x*x*(3.0-2.0*x); //faster smoothstep alternative - 776 amd fps, +vign 536 nv
  632. //x = x - 2.0 * (x - 1.0) * x* (x- 0.5); //2.0 is contrast. Range is 0.0 to 2.0
  633. #endif
  634.  
  635. // -- Curve 4 --
  636. #if Curves_formula == 4
  637. x = (1.0524 * exp(6.0 * x) - 1.05248) / (20.0855 + exp(6.0 * x)); //exp formula
  638. #endif
  639.  
  640. // -- Curve 5 --
  641. #if Curves_formula == 5
  642. //x = 0.5 * (x + 3.0 * x * x - 2.0 * x * x * x); //a simplified catmull-rom (0,0,1,1) - btw smoothstep can also be expressed as a simplified catmull-rom using (1,0,1,0)
  643. //x = (0.5 * x) + (1.5 -x) * x*x; //estrin form - faster version
  644. x = x * (x * (1.5-x) + 0.5); //horner form - fastest version
  645.  
  646. Curves_contrast_blend = Curves_contrast * 2.0; //I multiply by two to give it a strength closer to the other curves.
  647. #endif
  648.  
  649. // -- Curve 6 --
  650. #if Curves_formula == 6
  651. x = x*x*x*(x*(x*6.0 - 15.0) + 10.0); //Perlins smootherstep
  652. #endif
  653.  
  654. // -- Curve 7 --
  655. #if Curves_formula == 7
  656. //x = ((x-0.5) / ((0.5/(4.0/3.0)) + abs((x-0.5)*1.25))) + 0.5;
  657. x = x - 0.5;
  658. x = x / ((abs(x)*1.25) + 0.375 ) + 0.5;
  659. //x = ( (x-0.5) / ((abs(x-0.5)*1.25) + (0.5/(4.0/3.0))) ) + 0.5;
  660. #endif
  661.  
  662. // -- Curve 8 --
  663. #if Curves_formula == 8
  664. x = (x * (x * (x * (x * (x * (x * (1.6 * x - 7.2) + 10.8) - 4.2) - 3.6) + 2.7) - 1.8) + 2.7) * x * x; //Techicolor Cinestyle - almost identical to curve 1
  665. #endif
  666.  
  667. // -- Curve 9 --
  668. #if Curves_formula == 9
  669. x = -0.5 * (x*2.0-1.0) * (abs(x*2.0-1.0)-2.0) + 0.5; //parabola
  670. #endif
  671.  
  672. // -- Curve 10 --
  673. #if Curves_formula == 10 //Half-circles
  674.  
  675. #if Curves_mode == 0
  676. float xstep = step(x,0.5);
  677. float xstep_shift = (xstep - 0.5);
  678. float shifted_x = x + xstep_shift;
  679. #else
  680. float3 xstep = step(x,0.5);
  681. float3 xstep_shift = (xstep - 0.5);
  682. float3 shifted_x = x + xstep_shift;
  683. #endif
  684.  
  685. x = abs(xstep - sqrt(-shifted_x * shifted_x + shifted_x) ) - xstep_shift;
  686.  
  687. //x = abs(step(x,0.5)-sqrt(-(x+step(x,0.5)-0.5)*(x+step(x,0.5)-0.5)+(x+step(x,0.5)-0.5)))-(step(x,0.5)-0.5); //single line version of the above
  688.  
  689. //x = 0.5 + (sign(x-0.5)) * sqrt(0.25-(x-trunc(x*2))*(x-trunc(x*2))); //worse
  690.  
  691. /* // if/else - even worse
  692. if (x-0.5)
  693. x = 0.5-sqrt(0.25-x*x);
  694. else
  695. x = 0.5+sqrt(0.25-(x-1)*(x-1));
  696. */
  697.  
  698. //x = (abs(step(0.5,x)-clamp( 1-sqrt(1-abs(step(0.5,x)- frac(x*2%1)) * abs(step(0.5,x)- frac(x*2%1))),0 ,1))+ step(0.5,x) )*0.5; //worst so far
  699.  
  700. //TODO: Check if I could use an abs split instead of step. It might be more efficient
  701.  
  702. Curves_contrast_blend = Curves_contrast * 0.5; //I divide by two to give it a strength closer to the other curves.
  703. #endif
  704.  
  705. // -- Curve 11 --
  706. #if Curves_formula == 11 //Cubic catmull
  707. float a = 1.00; //control point 1
  708. float b = 0.00; //start point
  709. float c = 1.00; //endpoint
  710. float d = 0.20; //control point 2
  711. x = 0.5 * ((-a + 3*b -3*c + d)*x*x*x + (2*a -5*b + 4*c - d)*x*x + (-a+c)*x + 2*b); //A customizable cubic catmull-rom spline
  712. #endif
  713.  
  714. // -- Curve 12 --
  715. #if Curves_formula == 12 //Cubic Bezier spline
  716. float a = 0.00; //start point
  717. float b = 0.00; //control point 1
  718. float c = 1.00; //control point 2
  719. float d = 1.00; //endpoint
  720.  
  721. float r = (1-x);
  722. float r2 = r*r;
  723. float r3 = r2 * r;
  724. float x2 = x*x;
  725. float x3 = x2*x;
  726. //x = dot(float4(a,b,c,d),float4(r3,3*r2*x,3*r*x2,x3));
  727.  
  728. //x = a * r*r*r + r * (3 * b * r * x + 3 * c * x*x) + d * x*x*x;
  729. //x = a*(1-x)*(1-x)*(1-x) +(1-x) * (3*b * (1-x) * x + 3 * c * x*x) + d * x*x*x;
  730. x = a*(1-x)*(1-x)*(1-x) + 3*b*(1-x)*(1-x)*x + 3*c*(1-x)*x*x + d*x*x*x;
  731. #endif
  732.  
  733. // -- Curve 13 --
  734. #if Curves_formula == 13 //Cubic Bezier spline - alternative implementation.
  735. float3 a = float3(0.00,0.00,0.00); //start point
  736. float3 b = float3(0.25,0.15,0.85); //control point 1
  737. float3 c = float3(0.75,0.85,0.15); //control point 2
  738. float3 d = float3(1.00,1.00,1.00); //endpoint
  739.  
  740. float3 ab = lerp(a,b,x); // point between a and b
  741. float3 bc = lerp(b,c,x); // point between b and c
  742. float3 cd = lerp(c,d,x); // point between c and d
  743. float3 abbc = lerp(ab,bc,x); // point between ab and bc
  744. float3 bccd = lerp(bc,cd,x); // point between bc and cd
  745. float3 dest = lerp(abbc,bccd,x); // point on the bezier-curve
  746. x = dest;
  747. #endif
  748.  
  749. // -- Curve 14 --
  750. #if Curves_formula == 14
  751. x = 1.0 / (1.0 + exp(-(x * 10.0 - 5.0))); //alternative exp formula
  752. #endif
  753.  
  754. // ---------------------------------Joining of Luma and Chroma
  755.  
  756. #if Curves_mode == 2 //Both Luma and Chroma
  757. float3 color = x; //if the curve should be applied to both Luma and Chroma
  758. colorInput.rgb = lerp(colorInput.rgb, color, Curves_contrast_blend); //Blend by Curves_contrast
  759.  
  760. #elif Curves_mode == 1 //Only Chroma
  761. x = x * 2.0 - 1.0; //adjust the Chroma range back to -1 -> 1
  762. float3 color = luma + x; //Luma + Chroma
  763. colorInput.rgb = lerp(colorInput.rgb, color, Curves_contrast_blend); //Blend by Curves_contrast
  764.  
  765. #else // Curves_mode == 0 //Only Luma
  766. x = lerp(luma, x, Curves_contrast_blend); //Blend by Curves_contrast
  767. colorInput.rgb = x + chroma; //Luma + Chroma
  768.  
  769. #endif
  770.  
  771. //Return the result
  772. return colorInput;
  773. }
  774.  
  775. // -------------------------Dither--------------------------------------------
  776.  
  777. #ifndef dither_method
  778. #define dither_method 1
  779. #endif
  780.  
  781. float4 DitherPass( float4 colorInput, float2 tex )
  782. {
  783. float3 color = colorInput.rgb;
  784.  
  785. float dither_bit = 8.0; //Number of bits per channel. Should be 8 for most monitors.
  786.  
  787. //color = (tex.x*0.3+0.1); //draw a gradient for testing.
  788. //#define dither_method 2 //override method for testing purposes
  789.  
  790. /*------------------------.
  791. | :: Ordered Dithering :: |
  792. '------------------------*/
  793. #if dither_method == 1 // Ordered dithering
  794. //Calculate grid position
  795. float grid_position = frac( dot(tex, (SCREEN_SIZE * float2(1.0/16.0,10.0/36.0) )+(0.25) ) );
  796.  
  797. //Calculate how big the shift should be
  798. float dither_shift = (0.25) * (1.0 / (pow(2,dither_bit) - 1.0));
  799.  
  800. //Shift the individual colors differently, thus making it even harder to see the dithering pattern
  801. float3 dither_shift_RGB = float3(dither_shift, -dither_shift, dither_shift); //subpixel dithering
  802.  
  803. //modify shift acording to grid position.
  804. dither_shift_RGB = lerp(2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position); //shift acording to grid position.
  805.  
  806. //shift the color by dither_shift
  807. color.rgb += dither_shift_RGB;
  808.  
  809.  
  810. /*-----------------------.
  811. | :: Random Dithering :: |
  812. '-----------------------*/
  813. #elif dither_method == 2 //Random dithering
  814.  
  815. //Pseudo Random Number Generator
  816. // -- PRNG 1 - Reference --
  817. float seed = dot(tex, float2(12.9898,78.233)); //I could add more salt here if I wanted to
  818. float sine = sin(seed); //cos also works well. Sincos too if you want 2D noise.
  819. float noise = frac(sine * 43758.5453 + tex.x); //tex.x is just some additional salt - it can be taken out.
  820.  
  821. //Calculate how big the shift should be
  822. float dither_shift = (1.0 / (pow(2,dither_bit) - 1.0)); // Using noise to determine shift. Will be 1/255 if set to 8-bit.
  823. float dither_shift_half = (dither_shift * 0.5); // The noise should vary between +- 0.5
  824. dither_shift = dither_shift * noise - dither_shift_half; // MAD
  825.  
  826. //shift the color by dither_shift
  827. color.rgb += float3(-dither_shift, dither_shift, -dither_shift); //subpixel dithering
  828.  
  829. /*--------------------.
  830. | :: New Dithering :: |
  831. '--------------------*/
  832. //#define dither_method 3
  833. #elif dither_method == 3 // New Ordered dithering
  834.  
  835. //Calculate grid position
  836. float grid_position = frac(dot(tex,(SCREEN_SIZE) * float2(0.75,0.5) /*+ (0.00025)*/)); //(0.6,0.8) is good too - TODO : experiment with values
  837.  
  838. //Calculate how big the shift should be
  839. float dither_shift = (0.25) * (1.0 / (pow(2,dither_bit) - 1.0)); // 0.25 seems good both when using math and when eyeballing it. So does 0.75 btw.
  840. dither_shift = lerp(2.0 * dither_shift, -2.0 * dither_shift, grid_position); //shift acording to grid position.
  841.  
  842. //shift the color by dither_shift
  843. color.rgb += float3(dither_shift, -dither_shift, dither_shift); //subpixel dithering
  844.  
  845. /*-------------------------.
  846. | :: A Dither Dithering :: |
  847. '-------------------------*/
  848. //#define dither_method 4
  849. #elif dither_method == 4 // New Ordered dithering
  850.  
  851. #define dither_pattern 11
  852. #define dither_levels 254
  853.  
  854. float x=tex.x * SCREEN_SIZE.x;// * 1.31;
  855. float y=tex.y * SCREEN_SIZE.y;// * 1.31;
  856.  
  857. //Calculate grid position
  858. float c = frac(dot(tex,(SCREEN_SIZE) * float2(1.0/4.0,3.0/4.0) + (0.00025) )); //the + (0.00025) part is to avoid errors with the floating point math
  859.  
  860. float mask;
  861.  
  862. #if dither_pattern == 1
  863. mask = ((x ^ y * 149) * 1234 & 511)/511.0; //requires bitwise XOR - doesn't work
  864. #elif dither_pattern == 2
  865. mask = (((x+c*17) ^ y * 149) * 1234 & 511)/511.0; //requires bitwise XOR - doesn't work
  866. #elif dither_pattern == 3
  867. mask = 256.0 * frac(((x + y * 237) * 119)/ 256.0 ) / 255.0 ;//1.00392 * frac(0.464844 * (x + 237.0 * y)); //256.0 * frac(((x + y * 237) * 119)/ 256.0 ) / 255.0
  868. #elif dither_pattern == 4
  869. mask = (256.0 * frac((((x+c*67.0) + y * 236.0) * 119.0) / 256.0)) / 255.0; //& 255 = 256 * frac(x / 256)
  870. #elif dither_pattern == 5
  871. mask = 0.5;
  872. #elif dither_pattern == 6
  873. mask = frac( dot(tex, float2(12.9898,78.233)) * 927.5453 );
  874. #elif dither_pattern == 7
  875. mask = frac( dot(tex, (SCREEN_SIZE * float2(1.0/7.0,9.0/17.0))+(0.00025) ) );
  876. #elif dither_pattern == 8
  877. mask = frac( dot(tex, (SCREEN_SIZE * float2(5.0/7.0,3.0/17.0))+(0.00025) ) );
  878. #elif dither_pattern == 9
  879. mask = frac( dot(tex, (SCREEN_SIZE * float2(1.0/4.0,3.0/5.0))+(0.000025) ) );
  880. #elif dither_pattern == 10
  881. mask = frac( dot(tex, (SCREEN_SIZE * float2(1.0/87.0,1.0/289.0))+(0.000025) ) ); //stylish pattern - but bad for dithering
  882. #elif dither_pattern == 11
  883. //mask = frac( dot(tex, (SCREEN_SIZE * float2(1.0/(floor(tex.y*10.0)/100.+16.0),87.0/289.0))+(0.000025) ) ); //
  884. //mask = frac( dot(float4(tex,tex), float4((SCREEN_SIZE * float2(0.666/16.0,6.66/36.)),(SCREEN_SIZE * float2(0.3344/16.0,3.34/36.)) ) ) ); //
  885. mask = frac( dot(tex, (SCREEN_SIZE * float2(1.0/16.0,10.0/36.0) )+(0.25) ) ); //
  886. //(floor(tex.y*10.0)/100.0 + 3.0)
  887. #else
  888. //return input;
  889. #endif
  890.  
  891. color.rgb = floor(dither_levels * color.rgb + mask) / dither_levels;
  892. color.rgb = mask.xxx;
  893.  
  894. /*---------------------------------------.
  895. | :: New Dithering - grid experiments :: |
  896. '---------------------------------------*/
  897. //#define dither_method 5
  898. #elif dither_method == 5 // New Ordered dithering
  899.  
  900. //Calculate grid position
  901. float grid_position = frac(dot(tex,floor(SCREEN_SIZE * float2(-0.5,-0.9) ) /*- (0.00025)*/ )); //(0.6,0.8) is good too - TODO : experiment with values
  902.  
  903. //Calculate grid position
  904. grid_position = frac(dot(tex,floor(SCREEN_SIZE * float2(0.4,0.70)) /*+ grid_position*/ /*+ (0.00025)*/ )); //
  905.  
  906. //Calculate how big the shift should be
  907. float dither_shift = (0.25) * (1.0 / (pow(2,dither_bit) - 1.0)); // 0.25 seems good both when using math and when eyeballing it. So does 0.75 btw.
  908. dither_shift = lerp(2.0 * dither_shift, -2.0 * dither_shift, grid_position); //shift acording to grid position.
  909.  
  910. //dither_shift = (2.0 * dither_shift) * grid_position + (2.0 * dither_shift) * grid_position;
  911. //dither_shift = 4.0 * dither_shift * grid_position;
  912.  
  913. //shift the color by dither_shift
  914. //color.rgb += lerp(2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position); //shift acording to grid position.
  915.  
  916. color.rgb += float3(dither_shift, -dither_shift, dither_shift); //subpixel dithering
  917.  
  918. /*-------------------.
  919. | :: Checkerboard :: |
  920. '-------------------*/
  921. #elif dither_method == 6 // Checkerboard Ordered dithering
  922. //Calculate grid position
  923. float grid_position = frac(dot(tex, SCREEN_SIZE * 0.5) + 0.25); //returns 0.25 and 0.75
  924.  
  925. //Calculate how big the shift should be
  926. float dither_shift = (0.25) * (1.0 / (pow(2,dither_bit) - 1.0)); // 0.25 seems good both when using math and when eyeballing it. So does 0.75 btw.
  927.  
  928. //Shift the individual colors differently, thus making it even harder to see the dithering pattern
  929. float3 dither_shift_RGB = float3(dither_shift, -dither_shift, dither_shift); //subpixel dithering
  930.  
  931. //modify shift acording to grid position.
  932. dither_shift_RGB = lerp(2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position); //shift acording to grid position.
  933.  
  934. //shift the color by dither_shift
  935. //color.rgb += lerp(2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position); //shift acording to grid position.
  936. color.rgb += dither_shift_RGB;
  937.  
  938. #endif
  939.  
  940. /*---------------------------.
  941. | :: Returning the output :: |
  942. '---------------------------*/
  943.  
  944. //color = (tex.x / 2.0); //draw a undithered gradient for testing.
  945.  
  946. colorInput.rgb = color.rgb;
  947.  
  948. return colorInput;
  949. }
  950.  
  951. // CRT shader
  952. //
  953. // Copyright (C) 2010-2012 cgwg, Themaister and DOLLS
  954. //
  955. // This program is free software; you can redistribute it and/or modify it
  956. // under the terms of the GNU General Public License as published by the Free
  957. // Software Foundation; either version 2 of the License, or (at your option)
  958. // any later version.
  959.  
  960. // Comment the next line to disable interpolation in linear gamma (and gain speed).
  961. //#define LINEAR_PROCESSING
  962.  
  963. // aspect ratio
  964. #define aspect float2(1.0, 0.75)
  965.  
  966. // Precalculate a bunch of useful values we'll need in the fragment
  967. // shader.
  968. #define sinangle sin(float2(CRTAngleX, CRTAngleY))
  969. #define cosangle cos(float2(CRTAngleX, CRTAngleY))
  970. #define stretch maxscale()
  971.  
  972. // Macros.
  973. #define FIX(c) max(abs(c), 1e-5);
  974. float PI = acos(-1); //#define PI 3.141592653589
  975.  
  976. // The size of one texel, in texture-coordinates.
  977. #define coone 1.0 / rubyTextureSize
  978.  
  979. #define mod_factor tex.x * rubyTextureSize.x * rubyOutputSize.x / rubyInputSize.x
  980.  
  981. #ifdef LINEAR_PROCESSING
  982. # define TEX2D(c) pow(tex2D(s0, (c)), CRTgamma)
  983. #else
  984. # define TEX2D(c) tex2D(s0, (c))
  985. #endif
  986.  
  987. float intersect(float2 xy)
  988. {
  989. float A = dot(xy,xy) + CRTDistance * CRTDistance;
  990. float B = 2.0 * (CRTCurvatureRadius * (dot(xy, sinangle) - CRTDistance * cosangle.x * cosangle.y) - CRTDistance * CRTDistance);
  991. float C = CRTDistance * CRTDistance + 2.0 * CRTCurvatureRadius * CRTDistance * cosangle.x * cosangle.y;
  992. return (-B - sqrt(B * B -4.0 * A * C)) / (2.0 * A);
  993. }
  994.  
  995. float2 bkwtrans(float2 xy)
  996. {
  997. float c = intersect(xy);
  998. float2 _point = float2(c, c) * xy;
  999. _point -= float2(-CRTCurvatureRadius, -CRTCurvatureRadius) * sinangle;
  1000. _point /= float2(CRTCurvatureRadius, CRTCurvatureRadius);
  1001. float2 tang = sinangle / cosangle;
  1002. float2 poc = _point / cosangle;
  1003. float A = dot(tang, tang) + 1.0;
  1004. float B = -2.0 * dot(poc, tang);
  1005. float C = dot(poc, poc) - 1.0;
  1006. float a = (-B + sqrt(B * B -4.0 * A * C)) / (2.0 * A);
  1007. float2 uv = (_point - a * sinangle) / cosangle;
  1008. float r = FIX(CRTCurvatureRadius * acos(a));
  1009. return uv * r / sin(r / CRTCurvatureRadius);
  1010. }
  1011.  
  1012. float2 fwtrans(float2 uv)
  1013. {
  1014. float r = FIX(sqrt(dot(uv, uv)));
  1015. uv *= sin(r / CRTCurvatureRadius) / r;
  1016. float x = 1.0 - cos(r / CRTCurvatureRadius);
  1017. float D = CRTDistance / CRTCurvatureRadius + x * cosangle.x * cosangle.y + dot(uv, sinangle);
  1018. return CRTDistance * (uv * cosangle - x * sinangle) / D;
  1019. }
  1020.  
  1021. float3 maxscale()
  1022. {
  1023. float2 c = bkwtrans(-CRTCurvatureRadius * sinangle / (1.0 + CRTCurvatureRadius / CRTDistance * cosangle.x * cosangle.y));
  1024. float2 a = float2(0.5, 0.5) * aspect;
  1025. float2 lo = float2(fwtrans(float2(-a.x, c.y)).x,
  1026. fwtrans(float2(c.x,-a.y)).y) / aspect;
  1027. float2 hi = float2(fwtrans(float2(+a.x, c.y)).x,
  1028. fwtrans(float2(c.x, +a.y)).y) / aspect;
  1029. return float3((hi + lo) * aspect * 0.5, max(hi.x - lo.x, hi.y - lo.y));
  1030. }
  1031.  
  1032. float2 transform(float2 coord, float2 textureSize, float2 inputSize)
  1033. {
  1034. coord *= textureSize / inputSize;
  1035. coord = (coord - 0.5) * aspect * stretch.z + stretch.xy;
  1036. return (bkwtrans(coord) / float2(CRTOverScan, CRTOverScan) / aspect + 0.5) * inputSize / textureSize;
  1037. }
  1038.  
  1039. float corner(float2 coord, float2 textureSize, float2 inputSize)
  1040. {
  1041. coord *= textureSize / inputSize;
  1042. coord = (coord - 0.5) * float2(CRTOverScan, CRTOverScan) + 0.5;
  1043. coord = min(coord, 1.0 - coord) * aspect;
  1044. float2 cdist = float2(CRTCornerSize, CRTCornerSize);
  1045. coord = (cdist - min(coord, cdist));
  1046. float dist = sqrt(dot(coord, coord));
  1047. return clamp((cdist.x-dist) * 1000.0, 0.0, 1.0);
  1048. }
  1049.  
  1050. // Calculate the influence of a scanline on the current pixel.
  1051. //
  1052. // 'distance' is the distance in texture coordinates from the current
  1053. // pixel to the scanline in question.
  1054. // 'color' is the colour of the scanline at the horizontal location of
  1055. // the current pixel.
  1056. float4 scanlineWeights(float distance, float4 color)
  1057. {
  1058. // "wid" controls the width of the scanline beam, for each RGB channel
  1059. // The "weights" lines basically specify the formula that gives
  1060. // you the profile of the beam, i.e. the intensity as
  1061. // a function of distance from the vertical center of the
  1062. // scanline. In this case, it is gaussian if width=2, and
  1063. // becomes nongaussian for larger widths. Ideally this should
  1064. // be normalized so that the integral across the beam is
  1065. // independent of its width. That is, for a narrower beam
  1066. // "weights" should have a higher peak at the center of the
  1067. // scanline than for a wider beam.
  1068. #if CRTScanlineGaussian == 0
  1069. float4 wid = 0.3 + 0.1 * pow(color, 3.0);
  1070. float4 weights = float4(distance / wid);
  1071. return 0.4 * exp(-weights * weights) / wid;
  1072. #else
  1073. float4 wid = 2.0 + 2.0 * pow(color, 4.0);
  1074. float calcdistance = distance / 0.3; // Optimization ?
  1075. //float4 weights = float4(distance / 0.3, distance / 0.3, distance / 0.3, distance / 0.3);
  1076. float4 weights = float4(calcdistance, calcdistance, calcdistance, calcdistance);
  1077. return 1.4 * exp(-pow(weights * rsqrt(0.5 * wid), wid)) / (0.6 + 0.2 * wid);
  1078. #endif
  1079. }
  1080.  
  1081. float4 AdvancedCRTPass( float4 colorInput, float2 tex )
  1082. {
  1083. // Here's a helpful diagram to keep in mind while trying to
  1084. // understand the code:
  1085. //
  1086. // | | | | |
  1087. // -------------------------------
  1088. // | | | | |
  1089. // | 01 | 11 | 21 | 31 | <-- current scanline
  1090. // | | @ | | |
  1091. // -------------------------------
  1092. // | | | | |
  1093. // | 02 | 12 | 22 | 32 | <-- next scanline
  1094. // | | | | |
  1095. // -------------------------------
  1096. // | | | | |
  1097. //
  1098. // Each character-cell represents a pixel on the output
  1099. // surface, "@" represents the current pixel (always somewhere
  1100. // in the bottom half of the current scan-line, or the top-half
  1101. // of the next scanline). The grid of lines represents the
  1102. // edges of the texels of the underlying texture.
  1103.  
  1104. float2 Resolution = float2(CRTResolutionX, CRTResolutionY);
  1105. float2 rubyTextureSize = Resolution;
  1106. float2 rubyInputSize = Resolution;
  1107. float2 rubyOutputSize = SCREEN_SIZE;
  1108.  
  1109. #if CRTCurvature == 1
  1110. float2 xy = transform(tex, rubyTextureSize, rubyInputSize);
  1111. #else
  1112. float2 xy = tex;
  1113. #endif
  1114. float cval = corner(xy, rubyTextureSize, rubyInputSize);
  1115.  
  1116. // Of all the pixels that are mapped onto the texel we are
  1117. // currently rendering, which pixel are we currently rendering?
  1118. float2 ratio_scale = xy * rubyTextureSize - 0.5;
  1119.  
  1120. #if CRTOversample == 1
  1121. float filter = fwidth(ratio_scale.y);
  1122. #endif
  1123. float2 uv_ratio = frac(ratio_scale);
  1124.  
  1125. // Snap to the center of the underlying texel.
  1126. xy = (floor(ratio_scale) + 0.5) / rubyTextureSize;
  1127.  
  1128. // Calculate Lanczos scaling coefficients describing the effect
  1129. // of various neighbour texels in a scanline on the current
  1130. // pixel.
  1131. float4 coeffs = PI * float4(1.0 + uv_ratio.x, uv_ratio.x, 1.0 - uv_ratio.x, 2.0 - uv_ratio.x);
  1132.  
  1133. // Prevent division by zero.
  1134. coeffs = FIX(coeffs);
  1135.  
  1136. // Lanczos2 kernel.
  1137. coeffs = 2.0 * sin(coeffs) * sin(coeffs / 2.0) / (coeffs * coeffs);
  1138.  
  1139. // Normalize.
  1140. coeffs /= dot(coeffs, 1.0);
  1141.  
  1142. // Calculate the effective colour of the current and next
  1143. // scanlines at the horizontal location of the current pixel,
  1144. // using the Lanczos coefficients above.
  1145. float4 col = clamp(mul(coeffs, float4x4(
  1146. TEX2D(xy + float2(-coone.x, 0.0)),
  1147. TEX2D(xy),
  1148. TEX2D(xy + float2(coone.x, 0.0)),
  1149. TEX2D(xy + float2(2.0 * coone.x, 0.0)))),
  1150. 0.0, 1.0);
  1151. float4 col2 = clamp(mul(coeffs, float4x4(
  1152. TEX2D(xy + float2(-coone.x, coone.y)),
  1153. TEX2D(xy + float2(0.0, coone.y)),
  1154. TEX2D(xy + coone),
  1155. TEX2D(xy + float2(2.0 * coone.x, coone.y)))),
  1156. 0.0, 1.0);
  1157.  
  1158. #ifndef LINEAR_PROCESSING
  1159. col = pow(col , CRTgamma);
  1160. col2 = pow(col2, CRTgamma);
  1161. #endif
  1162.  
  1163. // Calculate the influence of the current and next scanlines on
  1164. // the current pixel.
  1165. float4 weights = scanlineWeights(uv_ratio.y, col);
  1166. float4 weights2 = scanlineWeights(1.0 - uv_ratio.y, col2);
  1167.  
  1168. #if CRTOversample == 1
  1169. uv_ratio.y = uv_ratio.y + 1.0 / 3.0 * filter;
  1170. weights = (weights + scanlineWeights(uv_ratio.y, col)) / 3.0;
  1171. weights2 = (weights2 + scanlineWeights(abs(1.0 - uv_ratio.y), col2)) / 3.0;
  1172. uv_ratio.y = uv_ratio.y - 2.0 / 3.0 * filter;
  1173. weights = weights + scanlineWeights(abs(uv_ratio.y), col) / 3.0;
  1174. weights2 = weights2 + scanlineWeights(abs(1.0 - uv_ratio.y), col2) / 3.0;
  1175. #endif
  1176.  
  1177. float3 mul_res = (col * weights + col2 * weights2).rgb * float3(cval, cval, cval);
  1178.  
  1179. // dot-mask emulation:
  1180. // Output pixels are alternately tinted green and magenta.
  1181. float3 dotMaskWeights = lerp(float3(R1, G1, B1),
  1182. float3(R2, G2, B2),
  1183. floor(mod_factor % CRTScanlineIntensity));
  1184.  
  1185. mul_res *= dotMaskWeights * float3(0.83, 0.83, 0.83) * CRTBrightness;
  1186.  
  1187. // Convert the image gamma for display on our output device.
  1188. mul_res = pow(mul_res, 1.0 / CRTmonitorgamma);
  1189.  
  1190. //return saturate(lerp(colorInput, float4(mul_res, 1.0), CRTAmount));
  1191. colorInput.rgb = lerp(colorInput.rgb, mul_res, CRTAmount);
  1192. return saturate(colorInput);
  1193. }
  1194.  
  1195. // ------------------------- Technicolor --------------------------------------------
  1196.  
  1197. #define cyanfilter float3(0.0, 1.30, 1.0)
  1198. #define magentafilter float3(1.0, 0.0, 1.05)
  1199. #define yellowfilter float3(1.6, 1.6, 0.05)
  1200.  
  1201. #define redorangefilter float2(1.05, 0.620) //RG_
  1202. #define greenfilter float2(0.30, 1.0) //RG_
  1203. #define magentafilter2 magentafilter.rb //R_B
  1204.  
  1205. float4 TechnicolorPass( float4 colorInput )
  1206. {
  1207. float3 tcol = colorInput.rgb;
  1208.  
  1209. float2 rednegative_mul = tcol.rg * (1.0 / (redNegativeAmount * TechniPower));
  1210. float2 greennegative_mul = tcol.rg * (1.0 / (greenNegativeAmount * TechniPower));
  1211. float2 bluenegative_mul = tcol.rb * (1.0 / (blueNegativeAmount * TechniPower));
  1212.  
  1213. float rednegative = dot( redorangefilter, rednegative_mul );
  1214. float greennegative = dot( greenfilter, greennegative_mul );
  1215. float bluenegative = dot( magentafilter2, bluenegative_mul );
  1216.  
  1217. float3 redoutput = rednegative.rrr + cyanfilter;
  1218. float3 greenoutput = greennegative.rrr + magentafilter;
  1219. float3 blueoutput = bluenegative.rrr + yellowfilter;
  1220.  
  1221. float3 result = redoutput * greenoutput * blueoutput;
  1222. colorInput.rgb = lerp(tcol, result, TechniAmount);
  1223. return colorInput;
  1224. }
  1225.  
  1226. // ------------------------- DPX/Cineon --------------------------------------------
  1227.  
  1228. static float3x3 RGB =
  1229. {
  1230. 2.67147117265996,-1.26723605786241,-0.410995602172227,
  1231. -1.02510702934664,1.98409116241089,0.0439502493584124,
  1232. 0.0610009456429445,-0.223670750812863,1.15902104167061
  1233. };
  1234.  
  1235. static float3x3 XYZ =
  1236. {
  1237. 0.500303383543316,0.338097573222739,0.164589779545857,
  1238. 0.257968894274758,0.676195259144706,0.0658358459823868,
  1239. 0.0234517888692628,0.1126992737203,0.866839673124201
  1240. };
  1241.  
  1242. float4 DPXPass(float4 InputColor) : COLOR0 {
  1243.  
  1244. float DPXContrast = 0.1;
  1245.  
  1246. float DPXGamma = 1.0;
  1247.  
  1248. float RedCurve = Red;
  1249. float GreenCurve = Green;
  1250. float BlueCurve = Blue;
  1251.  
  1252. float3 B = InputColor.rgb;
  1253. //float3 Bn = B; // I used InputColor.rgb instead.
  1254.  
  1255. B = pow(B, 1.0/DPXGamma);
  1256.  
  1257. B.r = pow(B.r, 1.00);
  1258. B.g = pow(B.g, 1.00);
  1259. B.b = pow(B.b, 1.00);
  1260.  
  1261. B = (B * (1.0 - DPXContrast)) + DPXContrast / 2.0;
  1262.  
  1263. B.r = (1.0 /(1.0 + exp(- RedCurve * (B.r - RedC))) - (1.0 / (1.0 + exp(RedCurve / 2.0))))/(1.0 - 2.0 * (1.0 / (1.0 + exp(RedCurve / 2.0))));
  1264. B.g = (1.0 /(1.0 + exp(- GreenCurve * (B.g - GreenC))) - (1.0 / (1.0 + exp(GreenCurve / 2.0))))/(1.0 - 2.0 * (1.0 / (1.0 + exp(GreenCurve / 2.0))));
  1265. B.b = (1.0 /(1.0 + exp(- BlueCurve * (B.b - BlueC))) - (1.0 / (1.0 + exp(BlueCurve / 2.0))))/(1.0 - 2.0 * (1.0 / (1.0 + exp(BlueCurve / 2.0))));
  1266.  
  1267. //TODO use faster code for conversion between RGB/HSV - see http://www.chilliant.com/rgb2hsv.html
  1268. float value = max(max(B.r, B.g), B.b);
  1269. float3 color = B / value;
  1270.  
  1271. color = pow(color, 1.0/ColorGamma);
  1272.  
  1273. float3 c0 = color * value;
  1274.  
  1275. c0 = mul(XYZ, c0);
  1276.  
  1277. float luma = dot(c0, float3(0.30, 0.59, 0.11)); //Use BT 709 instead?
  1278. float3 chroma = c0 - luma;
  1279.  
  1280. c0 = luma + chroma * DPXSaturation;
  1281. c0 = mul(RGB, c0);
  1282.  
  1283. InputColor.rgb = lerp(InputColor.rgb, c0, Blend); //as long as Blend is always 0 we don't really need to lerp. The compiler *should* be smart enough to optimize this though (check to be sure)
  1284.  
  1285. return InputColor;
  1286. }
  1287.  
  1288. /* ------------------------- Grain --------------------------------------------
  1289.  
  1290. Film Grain post-process shader v1.1
  1291. Martins Upitis (martinsh) devlog-martinsh.blogspot.com
  1292. 2013
  1293. --------------------------
  1294. This work is licensed under a Creative Commons Attribution 3.0 Unported License.
  1295. So you are free to share, modify and adapt it for your needs, and even use it for commercial use.
  1296. I would also love to hear about a project you are using it.
  1297.  
  1298. Have fun,
  1299. Martins
  1300. ---------------------------
  1301. Ported to GeDoSaTo by Angelo Gonzalez
  1302. ---------------------------
  1303.  
  1304. Perlin noise shader by toneburst:
  1305. http://machinesdontcare.wordpress.com/2009/06/25/3d-perlin-noise-sphere-vertex-shader-sourcecode/
  1306. */
  1307.  
  1308. const float permTexUnit = 1.0/256.0; // Perm texture texel-size
  1309. const float permTexUnitHalf = 0.5/256.0; // Half perm texture texel-size
  1310.  
  1311. float width = SCREEN_SIZE.x;
  1312. float height = SCREEN_SIZE.y;
  1313.  
  1314. const float grainamount = GrainPower;
  1315. float colored = GrainColored;
  1316. float coloramount = GrainColorAmount;
  1317. float grainsize = GrainSize;
  1318. float lumamount = GrainLuma;
  1319.  
  1320. float fract (float inp)
  1321. {
  1322. return (inp-floor(inp));
  1323. }
  1324.  
  1325. float4 mix (float x, float y, float a)
  1326. {
  1327. return x * (1 - a) + y * a;
  1328. }
  1329.  
  1330. //a random texture generator, but you can also use a pre-computed perturbation texture
  1331. float4 rnm(in float2 tc)
  1332. {
  1333. float noise = sin(dot(tc + float2(timer,timer),float2(12.9898,78.233))) * 43758.5453;
  1334.  
  1335. float noiseR = frac(noise)*2.0-1.0;
  1336. float noiseG = frac(noise*1.2154)*2.0-1.0;
  1337. float noiseB = frac(noise*1.3453)*2.0-1.0;
  1338. float noiseA = frac(noise*1.3647)*2.0-1.0;
  1339.  
  1340. return float4(noiseR,noiseG,noiseB,noiseA);
  1341. }
  1342.  
  1343. float fade(in float t) {
  1344. return t*t*t*(t*(t*6.0-15.0)+10.0);
  1345. }
  1346.  
  1347. float pnoise3D(in float3 p)
  1348. {
  1349. float3 pi = permTexUnit*floor(p)+permTexUnitHalf; // Integer part, scaled so +1 moves permTexUnit texel
  1350. // and offset 1/2 texel to sample texel centers
  1351. float3 pf = frac(p); // Fractional part for interpolation
  1352.  
  1353. // Noise contributions from (x=0, y=0), z=0 and z=1
  1354. float perm00 = rnm(pi.xy).a ;
  1355. float3 grad000 = rnm(float2(perm00, pi.z)).rgb * 4.0 - 1.0;
  1356. float n000 = dot(grad000, pf);
  1357. float3 grad001 = rnm(float2(perm00, pi.z + permTexUnit)).rgb * 4.0 - 1.0;
  1358. float n001 = dot(grad001, pf - float3(0.0, 0.0, 1.0));
  1359.  
  1360. // Noise contributions from (x=0, y=1), z=0 and z=1
  1361. float perm01 = rnm(pi.xy + float2(0.0, permTexUnit)).a ;
  1362. float3 grad010 = rnm(float2(perm01, pi.z)).rgb * 4.0 - 1.0;
  1363. float n010 = dot(grad010, pf - float3(0.0, 1.0, 0.0));
  1364. float3 grad011 = rnm(float2(perm01, pi.z + permTexUnit)).rgb * 4.0 - 1.0;
  1365. float n011 = dot(grad011, pf - float3(0.0, 1.0, 1.0));
  1366.  
  1367. // Noise contributions from (x=1, y=0), z=0 and z=1
  1368. float perm10 = rnm(pi.xy + float2(permTexUnit, 0.0)).a ;
  1369. float3 grad100 = rnm(float2(perm10, pi.z)).rgb * 4.0 - 1.0;
  1370. float n100 = dot(grad100, pf - float3(1.0, 0.0, 0.0));
  1371. float3 grad101 = rnm(float2(perm10, pi.z + permTexUnit)).rgb * 4.0 - 1.0;
  1372. float n101 = dot(grad101, pf - float3(1.0, 0.0, 1.0));
  1373.  
  1374. // Noise contributions from (x=1, y=1), z=0 and z=1
  1375. float perm11 = rnm(pi.xy + float2(permTexUnit, permTexUnit)).a ;
  1376. float3 grad110 = rnm(float2(perm11, pi.z)).rgb * 4.0 - 1.0;
  1377. float n110 = dot(grad110, pf - float3(1.0, 1.0, 0.0));
  1378. float3 grad111 = rnm(float2(perm11, pi.z + permTexUnit)).rgb * 4.0 - 1.0;
  1379. float n111 = dot(grad111, pf - float3(1.0, 1.0, 1.0));
  1380.  
  1381. // Blend contributions along x
  1382. float4 n_x = lerp(float4(n000, n001, n010, n011), float4(n100, n101, n110, n111), fade(pf.x));
  1383.  
  1384. // Blend contributions along y
  1385. float2 n_xy = lerp(n_x.xy, n_x.zw, fade(pf.y));
  1386.  
  1387. // Blend contributions along z
  1388. float n_xyz = lerp(n_xy.x, n_xy.y, fade(pf.z));
  1389.  
  1390. // We're done, return the final noise value.
  1391. return n_xyz;
  1392. }
  1393.  
  1394. //2d coordinate orientation thing
  1395. float2 coordRot(in float2 tc, in float angle)
  1396. {
  1397. float aspectr = width/height;
  1398. float rotX = ((tc.x*2.0-1.0)*aspectr*cos(angle)) - ((tc.y*2.0-1.0)*sin(angle));
  1399. float rotY = ((tc.y*2.0-1.0)*cos(angle)) + ((tc.x*2.0-1.0)*aspectr*sin(angle));
  1400. rotX = ((rotX/aspectr)*0.5+0.5);
  1401. rotY = rotY*0.5+0.5;
  1402. return float2(rotX,rotY);
  1403. }
  1404.  
  1405. float4 GrainPass( float4 colorInput, float2 tex )
  1406. {
  1407. float3 rotOffset = float3(1.425,3.892,5.835); //rotation offset values
  1408. float2 rotCoordsR = coordRot(tex, timer + rotOffset.x);
  1409. float2 rot = rotCoordsR*float2(width/grainsize,height/grainsize);
  1410. float pNoise = pnoise3D(float3(rot.x,rot.y,0.0));
  1411. float3 noise = float3(pNoise, pNoise, pNoise);
  1412.  
  1413. if (colored == 1)
  1414. {
  1415. float2 rotCoordsG = coordRot(tex, timer + rotOffset.y);
  1416. float2 rotCoordsB = coordRot(tex, timer + rotOffset.z);
  1417. noise.g = lerp(noise.r,pnoise3D(float3(rotCoordsG*float2(width/grainsize,height/grainsize),1.0)),coloramount);
  1418. noise.b = lerp(noise.r,pnoise3D(float3(rotCoordsB*float2(width/grainsize,height/grainsize),2.0)),coloramount);
  1419. }
  1420.  
  1421. float3 col = colorInput.rgb;
  1422.  
  1423. //noisiness response curve based on scene luminance
  1424. float3 lumcoeff = float3(0.299,0.587,0.114);
  1425. float luminance = lerp(0.0,dot(col, lumcoeff),lumamount);
  1426. float lum = smoothstep(0.2,0.0,luminance);
  1427. lum += luminance;
  1428.  
  1429. float2 thepow = pow(lum, 4.0);
  1430.  
  1431. noise = lerp(noise,float3(0.0, 0.0, 0.0),pow(lum,4.0));
  1432. col += noise*grainamount;
  1433.  
  1434. return float4(col,1.0);
  1435. }
  1436.  
  1437. // ------------------------- Border --------------------------------------------
  1438.  
  1439. #ifndef border_width
  1440. #define border_width float2(1,0)
  1441. #endif
  1442.  
  1443. #ifndef border_color
  1444. #define border_color float3(0, 0, 0)
  1445. #endif
  1446.  
  1447. #define screen_ratio (SCREEN_SIZE.x / SCREEN_SIZE.y)
  1448.  
  1449. float4 BorderPass( float4 colorInput, float2 tex )
  1450. {
  1451. float3 border_color_float = border_color / 255.0;
  1452.  
  1453. float2 border_width_variable = border_width;
  1454.  
  1455. // -- calculate the right border_width for a given border_ratio --
  1456. if (!any(border_width)) //if border_width is not used
  1457. if (screen_ratio < border_ratio)
  1458. border_width_variable = float2(0.0, (SCREEN_SIZE.y - (SCREEN_SIZE.x / border_ratio)) * 0.5);
  1459. else
  1460. border_width_variable = float2((SCREEN_SIZE.x - (SCREEN_SIZE.y * border_ratio)) * 0.5, 0.0);
  1461.  
  1462. float2 border = (PIXEL_SIZE * border_width_variable); //Translate integer pixel width to floating point
  1463.  
  1464. float2 within_border = saturate((-tex * tex + tex) - (-border * border + border)); //becomes positive when inside the border and 0 when outside
  1465.  
  1466. colorInput.rgb = all(within_border) ? colorInput.rgb : border_color_float ; //if the pixel is within the border use the original color, if not use the border_color
  1467.  
  1468. return colorInput; //return the pixel
  1469. }
  1470.  
  1471.  
  1472. // ------------------------- Splitscreen --------------------------------------------
  1473.  
  1474. float4 SplitscreenPass( float4 colorInput, float2 tex )
  1475. {
  1476. // -- Vertical 50/50 split --
  1477. #if splitscreen_mode == 1
  1478. return (tex.x < 0.5) ? tex2D(s0, tex) : colorInput;
  1479. #endif
  1480.  
  1481. // -- Vertical 25/50/25 split --
  1482. #if splitscreen_mode == 2
  1483. //Calculate the distance from center
  1484. float distance = abs(tex.x - 0.5);
  1485.  
  1486. //Further than 1/4 away from center?
  1487. distance = saturate(distance - 0.25);
  1488.  
  1489. return distance ? tex2D(s0, tex) : colorInput;
  1490. #endif
  1491.  
  1492. // -- Vertical 50/50 angled split --
  1493. #if splitscreen_mode == 3
  1494. //Calculate the distance from center
  1495. float distance = ((tex.x - 3.0/8.0) + (tex.y * 0.25));
  1496.  
  1497. //Further than 1/4 away from center?
  1498. distance = saturate(distance - 0.25);
  1499.  
  1500. return distance ? colorInput : tex2D(s0, tex);
  1501. #endif
  1502.  
  1503. // -- Horizontal 50/50 split --
  1504. #if splitscreen_mode == 4
  1505. return (tex.y < 0.5) ? tex2D(s0, tex) : colorInput;
  1506. #endif
  1507.  
  1508. // -- Horizontal 25/50/25 split --
  1509. #if splitscreen_mode == 5
  1510. //Calculate the distance from center
  1511. float distance = abs(tex.y - 0.5);
  1512.  
  1513. //Further than 1/4 away from center?
  1514. distance = saturate(distance - 0.25);
  1515.  
  1516. return distance ? tex2D(s0, tex) : colorInput;
  1517. #endif
  1518.  
  1519. // -- Vertical 50/50 curvy split --
  1520. #if splitscreen_mode == 6
  1521. //Calculate the distance from center
  1522. float distance = (tex.x - 0.25) + (sin(tex.y * 10)*0.10);
  1523.  
  1524. //Further than 1/4 away from center?
  1525. distance = saturate(distance - 0.25);
  1526.  
  1527. return distance ? colorInput : tex2D(s0, tex);
  1528. #endif
  1529.  
  1530. }
  1531.  
  1532. // ------------------------- SinCity --------------------------------------------
  1533. // Original code by /r/TerrifyingCookie that was then ported to SweetFX by /r/PrydeRage.
  1534.  
  1535. float4 SinCityPass( float4 colorInput )
  1536. {
  1537. colorInput = pow(colorInput, .45f);
  1538. float3 bwcolor = dot(colorInput.rgb, 1.f.xxx) * 0.33333f;
  1539. float weight = smoothstep(0.1f, 0.25f, colorInput.r - bwcolor);
  1540. bwcolor = pow(bwcolor * 1.1f, 2.f);
  1541. float3 colorout = lerp(bwcolor, colorInput * float3(1.1f, 0.5f, 0.5f), weight);
  1542. return pow(float4(colorout, 1.f), 2.2f);
  1543. }
  1544.  
  1545. // -------------------- Main -----------------------------------------------
  1546.  
  1547. float4 postProcessing(VSOUT IN) : COLOR0
  1548. {
  1549. float2 tex = IN.UVCoord;
  1550. float4 c0 = tex2D(s0, tex);
  1551.  
  1552. #if (USE_BLOOM == 1)
  1553. c0 = BloomPass(c0, tex);
  1554. #endif
  1555.  
  1556. #if (USE_HDR == 1)
  1557. c0 = HDRPass(c0, tex);
  1558. #endif
  1559.  
  1560. #if (USE_LUMASHARPEN == 1)
  1561. c0 = LumaSharpenPass(c0, tex);
  1562. #endif
  1563.  
  1564. #if (USE_VIBRANCE == 1)
  1565. c0 = VibrancePass(c0);
  1566. #endif
  1567.  
  1568. #if (USE_TONEMAP == 1)
  1569. c0 = TonemapPass(c0);
  1570. #endif
  1571.  
  1572. #if (USE_CA == 1)
  1573. c0 = CAPass(c0, tex);
  1574. #endif
  1575.  
  1576. #if (USE_CURVES == 1)
  1577. c0 = CurvesPass(c0);
  1578. #endif
  1579.  
  1580. #if (USE_ADVANCED_CRT == 1)
  1581. c0 = AdvancedCRTPass(c0, tex);
  1582. #endif
  1583.  
  1584. #if (USE_DITHER == 1)
  1585. c0 = DitherPass(c0, tex);
  1586. #endif
  1587.  
  1588. #if (USE_TECHNICOLOR == 1)
  1589. c0 = TechnicolorPass(c0);
  1590. #endif
  1591.  
  1592. #if (USE_DPX == 1)
  1593. c0 = DPXPass(c0);
  1594. #endif
  1595.  
  1596. #if (USE_GRAIN == 1)
  1597. c0 = GrainPass(c0, tex);
  1598. #endif
  1599.  
  1600. #if (USE_BORDER == 1)
  1601. c0 = BorderPass(c0, tex);
  1602. #endif
  1603.  
  1604. #if (USE_SPLITSCREEN == 1)
  1605. c0 = SplitscreenPass(c0, tex);
  1606. #endif
  1607.  
  1608. #if (USE_SINCITY == 1)
  1609. c0 = SinCityPass(c0);
  1610. #endif
  1611.  
  1612. c0.w = 1.0;
  1613. return saturate(c0);
  1614. }
  1615.  
  1616. technique t0
  1617. {
  1618. pass P0
  1619. {
  1620. VertexShader = compile vs_3_0 FrameVS();
  1621. PixelShader = compile ps_3_0 postProcessing();
  1622. ZEnable = false;
  1623. SRGBWriteEnable = USE_SRGB;
  1624. AlphaBlendEnable = false;
  1625. AlphaTestEnable = false;
  1626. ColorWriteEnable = RED|GREEN|BLUE|ALPHA;
  1627. }
  1628. }
Advertisement
Add Comment
Please, Sign In to add comment