Guest User

CRT

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