Guest User

Untitled

a guest
Mar 26th, 2019
174
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * _______ ___ ___ ___ ___
  3. * / || \/ | / \ / \
  4. * | (---- | \ / | / ^ \ / ^ \
  5. * \ \ | |\/| | / /_\ \ / /_\ \
  6. * ----) | | | | | / _____ \ / _____ \
  7. * |_______/ |__| |__| /__/ \__\ /__/ \__\
  8. *
  9. * E N H A N C E D
  10. * S U B P I X E L M O R P H O L O G I C A L A N T I A L I A S I N G
  11. *
  12. * for ReShade 3.0+
  13. */
  14.  
  15. //------------------- Preprocessor Settings -------------------
  16.  
  17. #ifndef SMAA_PREDICATION
  18. #define SMAA_PREDICATION 0 // Disable predication by default
  19. #endif
  20.  
  21. #if !defined(SMAA_PRESET_LOW) && !defined(SMAA_PRESET_MEDIUM) && !defined(SMAA_PRESET_HIGH) && !defined(SMAA_PRESET_ULTRA)
  22. #define SMAA_PRESET_CUSTOM // Do not use a quality preset by default
  23. #endif
  24.  
  25. //----------------------- UI Variables ------------------------
  26.  
  27. #include "ReShadeUI.fxh"
  28.  
  29. uniform int EdgeDetectionType <
  30. ui_type = "combo";
  31. ui_items = "Luminance edge detection\0Color edge detection\0Depth edge detection\0";
  32. ui_label = "Edge Detection Type";
  33. > = 1;
  34.  
  35. #ifdef SMAA_PRESET_CUSTOM
  36. uniform float EdgeDetectionThreshold <
  37. ui_type = "drag";
  38. ui_min = 0.05; ui_max = 0.20; ui_step = 0.01;
  39. ui_tooltip = "Edge detection threshold. If SMAA misses some edges try lowering this slightly.";
  40. ui_label = "Edge Detection Threshold";
  41. > = 0.05;
  42.  
  43. uniform float DepthEdgeDetectionThreshold <
  44. ui_type = "drag";
  45. ui_min = 0.001; ui_max = 0.10; ui_step = 0.01;
  46. ui_tooltip = "Depth Edge detection threshold. If SMAA misses some edges try lowering this slightly.";
  47. ui_label = "Depth Edge Detection Threshold";
  48. > = 0.01;
  49.  
  50. uniform int MaxSearchSteps < __UNIFORM_SLIDER_INT1
  51. ui_min = 0; ui_max = 112;
  52. ui_label = "Max Search Steps";
  53. ui_tooltip = "Determines the radius SMAA will search for aliased edges.";
  54. > = 64;
  55.  
  56. uniform int MaxSearchStepsDiagonal < __UNIFORM_SLIDER_INT1
  57. ui_min = 0; ui_max = 20;
  58. ui_label = "Max Search Steps Diagonal";
  59. ui_tooltip = "Determines the radius SMAA will search for diagonal aliased edges";
  60. > = 20;
  61.  
  62. uniform int CornerRounding < __UNIFORM_SLIDER_INT1
  63. ui_min = 0; ui_max = 100;
  64. ui_label = "Corner Rounding";
  65. ui_tooltip = "Determines the percent of anti-aliasing to apply to corners.";
  66. > = 0;
  67.  
  68. #if SMAA_PREDICATION
  69. uniform float PredicationThreshold <
  70. ui_type = "drag";
  71. ui_min = 0.005; ui_max = 1.00; ui_step = 0.01;
  72. ui_tooltip = "Threshold to be used in the additional predication buffer.";
  73. ui_label = "Predication Threshold";
  74. > = 0.01;
  75.  
  76. uniform float PredicationScale < __UNIFORM_SLIDER_FLOAT1
  77. ui_min = 1; ui_max = 5;
  78. ui_tooltip = "How much to scale the global threshold used for luma or color edge.";
  79. ui_label = "Predication Scale";
  80. > = 2.0;
  81.  
  82. uniform float PredicationStrength < __UNIFORM_SLIDER_FLOAT1
  83. ui_min = 0; ui_max = 1;
  84. ui_tooltip = "How much to locally decrease the threshold.";
  85. ui_label = "Predication Strength";
  86. > = 0.4;
  87. #endif
  88. #endif
  89.  
  90. uniform int DebugOutput <
  91. ui_type = "combo";
  92. ui_items = "None\0View edges\0View weights\0";
  93. ui_label = "Debug Output";
  94. > = false;
  95.  
  96. #ifdef SMAA_PRESET_CUSTOM
  97. #define SMAA_THRESHOLD EdgeDetectionThreshold
  98. #define SMAA_DEPTH_THRESHOLD DepthEdgeDetectionThreshold
  99. #define SMAA_MAX_SEARCH_STEPS MaxSearchSteps
  100. #define SMAA_MAX_SEARCH_STEPS_DIAG MaxSearchStepsDiagonal
  101. #define SMAA_CORNER_ROUNDING CornerRounding
  102. #if SMAA_PREDICATION
  103. #define SMAA_PREDICATION_THRESHOLD PredicationThreshold
  104. #define SMAA_PREDICATION_SCALE PredicationScale
  105. #define SMAA_PREDICATION_STRENGTH PredicationStrength
  106. #endif
  107. #endif
  108.  
  109. #define SMAA_RT_METRICS float4(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT, BUFFER_WIDTH, BUFFER_HEIGHT)
  110. #define SMAA_CUSTOM_SL 1
  111.  
  112. #define SMAATexture2D(tex) sampler tex
  113. #define SMAATexturePass2D(tex) tex
  114. #define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, coord))
  115. #define SMAASampleLevelZeroPoint(tex, coord) SMAASampleLevelZero(tex, coord)
  116. #define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlodoffset(tex, float4(coord, coord), offset)
  117. #define SMAASample(tex, coord) tex2D(tex, coord)
  118. #define SMAASamplePoint(tex, coord) SMAASample(tex, coord)
  119. #define SMAASampleOffset(tex, coord, offset) tex2Doffset(tex, coord, offset)
  120. #define SMAA_BRANCH [branch]
  121. #define SMAA_FLATTEN [flatten]
  122.  
  123. #if (__RENDERER__ == 0xb000 || __RENDERER__ == 0xb100)
  124. #define SMAAGather(tex, coord) tex2Dgather(tex, coord, 0)
  125. #endif
  126.  
  127. #include "SMAA.fxh"
  128. #include "ReShade.fxh"
  129.  
  130. // Textures
  131.  
  132. texture depthTex
  133. {
  134. Width = BUFFER_WIDTH;
  135. Height = BUFFER_HEIGHT;
  136. Format = R16F;
  137. };
  138.  
  139. texture edgesTex
  140. {
  141. Width = BUFFER_WIDTH;
  142. Height = BUFFER_HEIGHT;
  143. Format = RG8;
  144. };
  145. texture blendTex
  146. {
  147. Width = BUFFER_WIDTH;
  148. Height = BUFFER_HEIGHT;
  149. Format = RGBA8;
  150. };
  151.  
  152. texture areaTex < source = "AreaTex.dds"; >
  153. {
  154. Width = 160;
  155. Height = 560;
  156. Format = RG8;
  157. };
  158. texture searchTex < source = "SearchTex.dds"; >
  159. {
  160. Width = 64;
  161. Height = 16;
  162. Format = R8;
  163. };
  164.  
  165. // Samplers
  166.  
  167. sampler depthLinearSampler
  168. {
  169. Texture = depthTex;
  170. };
  171.  
  172. sampler colorGammaSampler
  173. {
  174. Texture = ReShade::BackBufferTex;
  175. AddressU = Clamp; AddressV = Clamp;
  176. MipFilter = Point; MinFilter = Linear; MagFilter = Linear;
  177. SRGBTexture = false;
  178. };
  179. sampler colorLinearSampler
  180. {
  181. Texture = ReShade::BackBufferTex;
  182. AddressU = Clamp; AddressV = Clamp;
  183. MipFilter = Point; MinFilter = Linear; MagFilter = Linear;
  184. SRGBTexture = true;
  185. };
  186. sampler edgesSampler
  187. {
  188. Texture = edgesTex;
  189. AddressU = Clamp; AddressV = Clamp;
  190. MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
  191. SRGBTexture = false;
  192. };
  193. sampler blendSampler
  194. {
  195. Texture = blendTex;
  196. AddressU = Clamp; AddressV = Clamp;
  197. MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
  198. SRGBTexture = false;
  199. };
  200. sampler areaSampler
  201. {
  202. Texture = areaTex;
  203. AddressU = Clamp; AddressV = Clamp; AddressW = Clamp;
  204. MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
  205. SRGBTexture = false;
  206. };
  207. sampler searchSampler
  208. {
  209. Texture = searchTex;
  210. AddressU = Clamp; AddressV = Clamp; AddressW = Clamp;
  211. MipFilter = Point; MinFilter = Point; MagFilter = Point;
  212. SRGBTexture = false;
  213. };
  214.  
  215. // Vertex shaders
  216.  
  217. void SMAAEdgeDetectionWrapVS(
  218. in uint id : SV_VertexID,
  219. out float4 position : SV_Position,
  220. out float2 texcoord : TEXCOORD0,
  221. out float4 offset[3] : TEXCOORD1)
  222. {
  223. PostProcessVS(id, position, texcoord);
  224. SMAAEdgeDetectionVS(texcoord, offset);
  225. }
  226. void SMAABlendingWeightCalculationWrapVS(
  227. in uint id : SV_VertexID,
  228. out float4 position : SV_Position,
  229. out float2 texcoord : TEXCOORD0,
  230. out float2 pixcoord : TEXCOORD1,
  231. out float4 offset[3] : TEXCOORD2)
  232. {
  233. PostProcessVS(id, position, texcoord);
  234. SMAABlendingWeightCalculationVS(texcoord, pixcoord, offset);
  235. }
  236. void SMAANeighborhoodBlendingWrapVS(
  237. in uint id : SV_VertexID,
  238. out float4 position : SV_Position,
  239. out float2 texcoord : TEXCOORD0,
  240. out float4 offset : TEXCOORD1)
  241. {
  242. PostProcessVS(id, position, texcoord);
  243. SMAANeighborhoodBlendingVS(texcoord, offset);
  244. }
  245.  
  246. // Pixel shaders
  247.  
  248. float SMAADepthLinearizationPS(
  249. float4 position : SV_Position,
  250. float2 texcoord : TEXCOORD0) : SV_Target
  251. {
  252. return ReShade::GetLinearizedDepth(texcoord);
  253. }
  254.  
  255. float2 SMAAEdgeDetectionWrapPS(
  256. float4 position : SV_Position,
  257. float2 texcoord : TEXCOORD0,
  258. float4 offset[3] : TEXCOORD1) : SV_Target
  259. {
  260. if (EdgeDetectionType == 0)
  261. return SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaSampler
  262. #if SMAA_PREDICATION
  263. , depthLinearSampler
  264. #endif
  265. );
  266. if (EdgeDetectionType == 2)
  267. return SMAADepthEdgeDetectionPS(texcoord, offset, depthLinearSampler);
  268.  
  269. return SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaSampler
  270. #if SMAA_PREDICATION
  271. , depthLinearSampler
  272. #endif
  273. );
  274. }
  275. float4 SMAABlendingWeightCalculationWrapPS(
  276. float4 position : SV_Position,
  277. float2 texcoord : TEXCOORD0,
  278. float2 pixcoord : TEXCOORD1,
  279. float4 offset[3] : TEXCOORD2) : SV_Target
  280. {
  281. return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesSampler, areaSampler, searchSampler, 0.0);
  282. }
  283.  
  284. float3 SMAANeighborhoodBlendingWrapPS(
  285. float4 position : SV_Position,
  286. float2 texcoord : TEXCOORD0,
  287. float4 offset : TEXCOORD1) : SV_Target
  288. {
  289. if (DebugOutput == 1)
  290. return tex2D(edgesSampler, texcoord).rgb;
  291. if (DebugOutput == 2)
  292. return tex2D(blendSampler, texcoord).rgb;
  293.  
  294. return SMAANeighborhoodBlendingPS(texcoord, offset, colorLinearSampler, blendSampler).rgb;
  295. }
  296.  
  297. // Rendering passes
  298.  
  299. technique SMAA
  300. {
  301. pass LinearizeDepthPass
  302. {
  303. VertexShader = PostProcessVS;
  304. PixelShader = SMAADepthLinearizationPS;
  305. RenderTarget = depthTex;
  306. }
  307. pass EdgeDetectionPass
  308. {
  309. VertexShader = SMAAEdgeDetectionWrapVS;
  310. PixelShader = SMAAEdgeDetectionWrapPS;
  311. RenderTarget = edgesTex;
  312. ClearRenderTargets = true;
  313. StencilEnable = true;
  314. StencilPass = REPLACE;
  315. StencilRef = 1;
  316. }
  317. pass BlendWeightCalculationPass
  318. {
  319. VertexShader = SMAABlendingWeightCalculationWrapVS;
  320. PixelShader = SMAABlendingWeightCalculationWrapPS;
  321. RenderTarget = blendTex;
  322. ClearRenderTargets = true;
  323. StencilEnable = true;
  324. StencilPass = KEEP;
  325. StencilFunc = EQUAL;
  326. StencilRef = 1;
  327. }
  328. pass NeighborhoodBlendingPass
  329. {
  330. VertexShader = SMAANeighborhoodBlendingWrapVS;
  331. PixelShader = SMAANeighborhoodBlendingWrapPS;
  332. StencilEnable = false;
  333. SRGBWriteEnable = true;
  334. }
  335. }
RAW Paste Data