Main.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*-------------------------.
  2. | :: Defining constants :: |
  3. '-------------------------*/
  4. //These values are normally defined by the injector dlls, but not when analyzed by GPU Shaderanalyzer
  5. //I need to ensure they always have a value to be able to compile them whenever I'm not using the injector.
  6. #ifdef SMAA_PIXEL_SIZE
  7. #ifndef BUFFER_RCP_WIDTH
  8. #define BUFFER_RCP_WIDTH SMAA_PIXEL_SIZE.x
  9. #define BUFFER_RCP_HEIGHT SMAA_PIXEL_SIZE.y
  10. #define BUFFER_WIDTH (1.0 / SMAA_PIXEL_SIZE.x)
  11. #define BUFFER_HEIGHT (1.0 / SMAA_PIXEL_SIZE.y)
  12. #endif
  13. #endif
  14. #ifndef BUFFER_RCP_WIDTH
  15. #define BUFFER_RCP_WIDTH (1.0 / 1680)
  16. #define BUFFER_RCP_HEIGHT (1.0 / 1050)
  17. #define BUFFER_WIDTH 1680
  18. #define BUFFER_HEIGHT 1050
  19. #endif
  20. #define screen_size float2(BUFFER_WIDTH,BUFFER_HEIGHT)
  21. #define px BUFFER_RCP_WIDTH
  22. #define py BUFFER_RCP_HEIGHT
  23. #define pixel float2(px,py)
  24. // -- Define DirectX9 FXAA specific aliases --
  25. #if FXAA_HLSL_3 == 1
  26. #define myTex2D(s,p) tex2D(s,p)
  27. //#define s0 colorTexG
  28. //#define s1 colorTexG //TODO make a nearest sampler if needed
  29. #endif
  30. // -- Define DirectX10/11 FXAA specific aliases --
  31. #if FXAA_HLSL_4 == 1
  32. //#define myTex2D(s,p) s.SampleLevel(screenSampler, p, 0)
  33. #define myTex2D(s,p) s.Sample(screenSampler, p)
  34. #define s0 gLumaTexture
  35. #define s1 gLumaTexture //TODO make a nearest sampler if needed
  36. #endif
  37. // -- Define DirectX9 specific aliases --
  38. #if SMAA_HLSL_3 == 1
  39. #define myTex2D(s,p) tex2D(s,p)
  40. #define s0 colorTexG
  41. #define s1 colorTexG //TODO make a nearest sampler if needed
  42. #endif
  43. // -- Define DirectX10/11 specific aliases --
  44. #if SMAA_HLSL_4 == 1 || SMAA_HLSL_4_1 == 1
  45. //#define myTex2D(s,p) s.SampleLevel(LinearSampler, p, 0)
  46. #define myTex2D(s,p) s.Sample(LinearSampler, p)
  47. #define s0 colorTexGamma
  48. #define s1 colorTexGamma //TODO make a nearest sampler if needed
  49. #endif
  50. /*------------------------------.
  51. | :: Include enabled shaders :: |
  52. '------------------------------*/
  53. #if (USE_CUSTOM == 1)
  54. #include "SweetFX\Shaders\Custom.h"
  55. #define Need_sRGB 1
  56. #endif
  57. #if (USE_EXPLOSION == 1)
  58. #include "SweetFX\Shaders\Explosion.h"
  59. #define Need_sRGB 1
  60. #endif
  61. #if (USE_CARTOON == 1)
  62. #include "SweetFX\Shaders\Cartoon.h"
  63. #define Need_sRGB 1
  64. #endif
  65. #if (USE_ADVANCED_CRT == 1)
  66. #include "SweetFX\Shaders\AdvancedCRT.h"
  67. #define Need_sRGB 1
  68. #endif
  69. #if (USE_SWEETCRT == 1)
  70. #include "SweetFX\Shaders\SweetCRT.h"
  71. #define Need_sRGB 1
  72. #endif
  73. #if (USE_BLOOM == 1)
  74. #include "SweetFX\Shaders\Bloom.h"
  75. #define Need_sRGB 1
  76. #endif
  77. #if (USE_HDR == 1)
  78. #include "SweetFX\Shaders\HDR.h"
  79. #define Need_sRGB 1
  80. #endif
  81. #if (USE_LUMASHARPEN == 1)
  82. #include "SweetFX\Shaders\LumaSharpen.h"
  83. #define Need_sRGB 1
  84. #endif
  85. #if (USE_LEVELS == 1)
  86. #include "SweetFX\Shaders\Levels.h"
  87. #define Need_sRGB 1
  88. #endif
  89. #if (USE_TECHNICOLOR == 1)
  90. #include "SweetFX\Shaders\Technicolor.h"
  91. #define Need_sRGB 1
  92. #endif
  93. #if (USE_DPX == 1)
  94. #include "SweetFX\Shaders\DPX.h"
  95. #define Need_sRGB 1
  96. #endif
  97. #if (USE_MONOCHROME == 1)
  98. #include "SweetFX\Shaders\Monochrome.h"
  99. #define Need_sRGB 1
  100. #endif
  101. #if (USE_LIFTGAMMAGAIN == 1)
  102. #include "SweetFX\Shaders\LiftGammaGain.h"
  103. #define Need_sRGB 1
  104. #endif
  105. #if (USE_TONEMAP == 1)
  106. #include "SweetFX\Shaders\Tonemap.h"
  107. #define Need_sRGB 1
  108. #endif
  109. #if (USE_SEPIA == 1)
  110. #include "SweetFX\Shaders\Sepia.h"
  111. #define Need_sRGB 1
  112. #endif
  113. #if (USE_VIBRANCE == 1)
  114. #include "SweetFX\Shaders\Vibrance.h"
  115. #define Need_sRGB 1
  116. #endif
  117. #if (USE_CURVES == 1)
  118. #include "SweetFX\Shaders\Curves.h"
  119. #define Need_sRGB 1
  120. #endif
  121. #if (USE_VIGNETTE == 1)
  122. #include "SweetFX\Shaders\Vignette.h"
  123. #define Need_sRGB 1
  124. #endif
  125. #if (USE_DITHER == 1)
  126. #include "SweetFX\Shaders\Dither.h"
  127. #define Need_sRGB 1
  128. #endif
  129. #if (USE_BORDER == 1)
  130. #include "SweetFX\Shaders\Border.h"
  131. #define Need_sRGB 1
  132. #endif
  133. #if (USE_SPLITSCREEN == 1)
  134. #include "SweetFX\Shaders\Splitscreen.h"
  135. #define Need_sRGB 1
  136. #endif
  137. /*--------------------.
  138. | :: Effect passes :: |
  139. '--------------------*/
  140. float4 SweetFX_main(float2 tex, float4 FinalColor)
  141. {
  142. /*--------------------------------------.
  143. | :: Linear to sRGB Gamma correction :: |
  144. '--------------------------------------*/
  145. //#if Need_sRGB
  146. // Linear to sRGB Gamma correction. Needed here because SMAA uses linear for it's final step while the other shaders use SRGB.
  147. #if (USE_SMAA_ANTIALIASING == 1 && Need_sRGB == 1)
  148. //FinalColor.rgb = (FinalColor.rgb <= 0.00304) ? saturate(FinalColor.rgb) * 12.92 : 1.055 * pow( saturate(FinalColor.rgb), 1.0/2.4 ) - 0.055; // Linear to SRGB
  149. FinalColor.rgb = (FinalColor.rgb <= 0.00304) ? saturate(FinalColor.rgb * 12.92) : 1.055 * saturate(pow(FinalColor.rgb, 1.0/2.4 )) - 0.055; // Linear to SRGB
  150. #endif
  151. /*--------------------.
  152. | :: Effect passes :: |
  153. '--------------------*/
  154. // Custom
  155. #if (USE_CUSTOM == 1)
  156. FinalColor = CustomPass(FinalColor,tex);
  157. #endif
  158. // Explosion
  159. #if (USE_EXPLOSION == 1)
  160. FinalColor = ExplosionPass(FinalColor,tex);
  161. #endif
  162. // Cartoon
  163. #if (USE_CARTOON == 1)
  164. FinalColor = CartoonPass(FinalColor,tex);
  165. #endif
  166. // Advanced CRT
  167. #if (USE_ADVANCED_CRT == 1)
  168. FinalColor = AdvancedCRTPass(FinalColor,tex);
  169. #endif
  170. // SweetCRT
  171. #if (USE_SWEETCRT == 1)
  172. FinalColor = SweetCRTPass(FinalColor,tex);
  173. #endif
  174. // Bloom
  175. #if (USE_BLOOM == 1)
  176. FinalColor = BloomPass (FinalColor,tex);
  177. #endif
  178. // HDR
  179. #if (USE_HDR == 1)
  180. FinalColor = HDRPass (FinalColor,tex);
  181. #endif
  182. // LumaSharpen
  183. #if (USE_LUMASHARPEN == 1)
  184. FinalColor = LumaSharpenPass(FinalColor,tex);
  185. #endif
  186. // Levels
  187. #if (USE_LEVELS == 1)
  188. FinalColor = LevelsPass(FinalColor);
  189. #endif
  190. // Technicolor
  191. #if (USE_TECHNICOLOR == 1)
  192. FinalColor = TechnicolorPass(FinalColor);
  193. #endif
  194. // DPX
  195. #if (USE_DPX == 1)
  196. FinalColor = DPXPass(FinalColor);
  197. #endif
  198. // Monochrome
  199. #if (USE_MONOCHROME == 1)
  200. FinalColor = MonochromePass(FinalColor);
  201. #endif
  202. // Lift Gamma Gain
  203. #if (USE_LIFTGAMMAGAIN == 1)
  204. FinalColor = LiftGammaGainPass(FinalColor);
  205. #endif
  206. // Tonemap
  207. #if (USE_TONEMAP == 1)
  208. FinalColor = TonemapPass(FinalColor);
  209. #endif
  210. // Vibrance
  211. #if (USE_VIBRANCE == 1)
  212. FinalColor = VibrancePass(FinalColor);
  213. #endif
  214. // Curves
  215. #if (USE_CURVES == 1)
  216. FinalColor = CurvesPass(FinalColor);
  217. #endif
  218. // Sepia
  219. #if (USE_SEPIA == 1)
  220. FinalColor = SepiaPass(FinalColor);
  221. #endif
  222. // Vignette
  223. #if (USE_VIGNETTE == 1)
  224. FinalColor = VignettePass(FinalColor,tex);
  225. #endif
  226. // Dither (should go near the end as it only dithers what went before it)
  227. #if (USE_DITHER == 1)
  228. FinalColor = DitherPass(FinalColor,tex);
  229. #endif
  230. // Border
  231. #if (USE_BORDER == 1)
  232. FinalColor = BorderPass(FinalColor,tex);
  233. #endif
  234. // Splitscreen
  235. #if (USE_SPLITSCREEN == 1)
  236. FinalColor = SplitscreenPass(FinalColor,tex);
  237. #endif
  238. /*--------------------------------------.
  239. | :: sRGB to Linear Gamma correction :: |
  240. '--------------------------------------*/
  241. // sRGB to Linear gamma correction.
  242. #if (SMAA_HLSL_3 != 1 && FXAA_HLSL_3 != 1) //If we are not using DirectX 9.. (and therefore are using DX10/11)
  243. #if (USE_SMAA_ANTIALIASING == 1 && Need_sRGB != 1) //and if we used SMAA (and thus Linear) and we didn't earlier convert to sRGB
  244. //..then we are already linear and don't need to do anything
  245. #else //if not, then we are currently sRGB and need to be Linear. - convert to Linear
  246. FinalColor.rgb = saturate(FinalColor.rgb);
  247. FinalColor.rgb = (FinalColor.rgb <= 0.03928) ? FinalColor.rgb / 12.92 : pow( (FinalColor.rgb + 0.055) / 1.055, 2.4 ); // sRGB to Linear
  248. #endif
  249. //But if we were using DirectX 9 then no matter what we should be sRGB at this point and don't need to do anything further.
  250. #endif
  251. // Return FinalColor
  252. FinalColor.a = 1.0; //Clear alpha channel to reduce filesize of screenshots that are converted to png and avoid problems when viewing the screenshots.
  253. return FinalColor;
  254. }