You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1534 lines
58 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Kicad Developers, see change_log.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include "gl_builtin_shaders.h"
  24. namespace KIGFX {
  25. namespace BUILTIN_SHADERS {
  26. const char ssaa_x4_fragment_shader[] = R"SHADER_SOURCE(
  27. #version 120
  28. varying vec2 texcoord;
  29. uniform sampler2D source;
  30. void main()
  31. {
  32. float step_x = dFdx(texcoord.x)/4.;
  33. float step_y = dFdy(texcoord.y)/4.;
  34. vec4 q00 = texture2D( source, texcoord + vec2(-step_x, -step_y) );
  35. vec4 q01 = texture2D( source, texcoord + vec2( step_x, -step_y) );
  36. vec4 q10 = texture2D( source, texcoord + vec2(-step_x, step_y) );
  37. vec4 q11 = texture2D( source, texcoord + vec2( step_x, step_y) );
  38. gl_FragColor = (q00+q01+q10+q11)/4;
  39. }
  40. )SHADER_SOURCE";
  41. const char smaa_base_shader_p1[] = R"SHADER_SOURCE(
  42. /**
  43. * Copyright (C) 2013 Jorge Jimenez (jorge@iryoku.com)
  44. * Copyright (C) 2013 Jose I. Echevarria (joseignacioechevarria@gmail.com)
  45. * Copyright (C) 2013 Belen Masia (bmasia@unizar.es)
  46. * Copyright (C) 2013 Fernando Navarro (fernandn@microsoft.com)
  47. * Copyright (C) 2013 Diego Gutierrez (diegog@unizar.es)
  48. *
  49. * Made compatible to OpenGL 2.1 (KiCad Developers 2016)
  50. *
  51. * Permission is hereby granted, free of charge, to any person obtaining a copy
  52. * this software and associated documentation files (the "Software"), to deal in
  53. * the Software without restriction, including without limitation the rights to
  54. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  55. * of the Software, and to permit persons to whom the Software is furnished to
  56. * do so, subject to the following conditions:
  57. *
  58. * The above copyright notice and this permission notice shall be included in
  59. * all copies or substantial portions of the Software. As clarification, there
  60. * is no requirement that the copyright notice and permission be included in
  61. * binary distributions of the Software.
  62. *
  63. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  64. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  65. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  66. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  67. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  68. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  69. * SOFTWARE.
  70. */
  71. /**
  72. * _______ ___ ___ ___ ___
  73. * / || \/ | / \ / \
  74. * | (---- | \ / | / ^ \ / ^ \
  75. * \ \ | |\/| | / /_\ \ / /_\ \
  76. * ----) | | | | | / _____ \ / _____ \
  77. * |_______/ |__| |__| /__/ \__\ /__/ \__\
  78. *
  79. * E N H A N C E D
  80. * 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
  81. *
  82. * http://www.iryoku.com/smaa/
  83. *
  84. * Hi, welcome aboard!
  85. *
  86. * Here you'll find instructions to get the shader up and running as fast as
  87. * possible.
  88. *
  89. * IMPORTANTE NOTICE: when updating, remember to update both this file and the
  90. * precomputed textures! They may change from version to version.
  91. *
  92. * The shader has three passes, chained together as follows:
  93. *
  94. * |input|------------------\
  95. * v |
  96. * [ SMAA*EdgeDetection ] |
  97. * v |
  98. * |edgesTex| |
  99. * v |
  100. * [ SMAABlendingWeightCalculation ] |
  101. * v |
  102. * |blendTex| |
  103. * v |
  104. * [ SMAANeighborhoodBlending ] <------/
  105. * v
  106. * |output|
  107. *
  108. * Note that each [pass] has its own vertex and pixel shader. Remember to use
  109. * oversized triangles instead of quads to avoid overshading along the
  110. * diagonal.
  111. *
  112. * You've three edge detection methods to choose from: luma, color or depth.
  113. * They represent different quality/performance and anti-aliasing/sharpness
  114. * tradeoffs, so our recommendation is for you to choose the one that best
  115. * suits your particular scenario:
  116. *
  117. * - Depth edge detection is usually the fastest but it may miss some edges.
  118. *
  119. * - Luma edge detection is usually more expensive than depth edge detection,
  120. * but catches visible edges that depth edge detection can miss.
  121. *
  122. * - Color edge detection is usually the most expensive one but catches
  123. * chroma-only edges.
  124. *
  125. * For quickstarters: just use luma edge detection.
  126. *
  127. * The general advice is to not rush the integration process and ensure each
  128. * step is done correctly (don't try to integrate SMAA T2x with predicated edge
  129. * detection from the start!). Ok then, let's go!
  130. *
  131. * 1. The first step is to create two RGBA temporal render targets for holding
  132. * |edgesTex| and |blendTex|.
  133. *
  134. * In DX10 or DX11, you can use a RG render target for the edges texture.
  135. * In the case of NVIDIA GPUs, using RG render targets seems to actually be
  136. * slower.
  137. *
  138. * On the Xbox 360, you can use the same render target for resolving both
  139. * |edgesTex| and |blendTex|, as they aren't needed simultaneously.
  140. *
  141. * 2. Both temporal render targets |edgesTex| and |blendTex| must be cleared
  142. * each frame. Do not forget to clear the alpha channel!
  143. *
  144. * 3. The next step is loading the two supporting precalculated textures,
  145. * 'areaTex' and 'searchTex'. You'll find them in the 'Textures' folder as
  146. * C++ headers, and also as regular DDS files. They'll be needed for the
  147. * 'SMAABlendingWeightCalculation' pass.
  148. *
  149. * If you use the C++ headers, be sure to load them in the format specified
  150. * inside of them.
  151. *
  152. * You can also compress 'areaTex' and 'searchTex' using BC5 and BC4
  153. * respectively, if you have that option in your content processor pipeline.
  154. * When compressing then, you get a non-perceptible quality decrease, and a
  155. * marginal performance increase.
  156. *
  157. * 4. All samplers must be set to linear filtering and clamp.
  158. *
  159. * After you get the technique working, remember that 64-bit inputs have
  160. * half-rate linear filtering on GCN.
  161. *
  162. * If SMAA is applied to 64-bit color buffers, switching to point filtering
  163. * when accessing them will increase the performance. Search for
  164. * 'SMAASamplePoint' to see which textures may benefit from point
  165. * filtering, and where (which is basically the color input in the edge
  166. * detection and resolve passes).
  167. *
  168. * 5. All texture reads and buffer writes must be non-sRGB, with the exception
  169. * of the input read and the output write in
  170. * 'SMAANeighborhoodBlending' (and only in this pass!). If sRGB reads in
  171. * this last pass are not possible, the technique will work anyway, but
  172. * will perform antialiasing in gamma space.
  173. *
  174. * IMPORTANT: for best results the input read for the color/luma edge
  175. * detection should *NOT* be sRGB.
  176. *
  177. * 6. Before including SMAA.h you'll have to setup the render target metrics,
  178. * the target and any optional configuration defines. Optionally you can
  179. * use a preset.
  180. *
  181. * You have the following targets available:
  182. * SMAA_HLSL_3
  183. * SMAA_HLSL_4
  184. * SMAA_HLSL_4_1
  185. * SMAA_GLSL_3 *
  186. * SMAA_GLSL_4 *
  187. *
  188. * * (See SMAA_INCLUDE_VS and SMAA_INCLUDE_PS below).
  189. *
  190. * And four presets:
  191. * SMAA_PRESET_LOW (%60 of the quality)
  192. * SMAA_PRESET_MEDIUM (%80 of the quality)
  193. * SMAA_PRESET_HIGH (%95 of the quality)
  194. * SMAA_PRESET_ULTRA (%99 of the quality)
  195. *
  196. * For example:
  197. * #define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0)
  198. * #define SMAA_HLSL_4
  199. * #define SMAA_PRESET_HIGH
  200. * #include "SMAA.h"
  201. *
  202. * Note that SMAA_RT_METRICS doesn't need to be a macro, it can be a
  203. * uniform variable. The code is designed to minimize the impact of not
  204. * using a constant value, but it is still better to hardcode it.
  205. *
  206. * Depending on how you encoded 'areaTex' and 'searchTex', you may have to
  207. * add (and customize) the following defines before including SMAA.h:
  208. * #define SMAA_AREATEX_SELECT(sample) sample.rg
  209. * #define SMAA_SEARCHTEX_SELECT(sample) sample.r
  210. *
  211. * If your engine is already using porting macros, you can define
  212. * SMAA_CUSTOM_SL, and define the porting functions by yourself.
  213. *
  214. * 7. Then, you'll have to setup the passes as indicated in the scheme above.
  215. * You can take a look into SMAA.fx, to see how we did it for our demo.
  216. * Checkout the function wrappers, you may want to copy-paste them!
  217. *
  218. * 8. It's recommended to validate the produced |edgesTex| and |blendTex|.
  219. * You can use a screenshot from your engine to compare the |edgesTex|
  220. * and |blendTex| produced inside of the engine with the results obtained
  221. * with the reference demo.
  222. *
  223. * 9. After you get the last pass to work, it's time to optimize. You'll have
  224. * to initialize a stencil buffer in the first pass (discard is already in
  225. * the code), then mask execution by using it the second pass. The last
  226. * pass should be executed in all pixels.
  227. *
  228. *
  229. * After this point you can choose to enable predicated thresholding,
  230. * temporal supersampling and motion blur integration:
  231. *
  232. * a) If you want to use predicated thresholding, take a look into
  233. * SMAA_PREDICATION; you'll need to pass an extra texture in the edge
  234. * detection pass.
  235. *
  236. * b) If you want to enable temporal supersampling (SMAA T2x):
  237. *
  238. * 1. The first step is to render using subpixel jitters. I won't go into
  239. * detail, but it's as simple as moving each vertex position in the
  240. * vertex shader, you can check how we do it in our DX10 demo.
  241. *
  242. * 2. Then, you must setup the temporal resolve. You may want to take a look
  243. * into SMAAResolve for resolving 2x modes. After you get it working, you'll
  244. * probably see ghosting everywhere. But fear not, you can enable the
  245. * CryENGINE temporal reprojection by setting the SMAA_REPROJECTION macro.
  246. * Check out SMAA_DECODE_VELOCITY if your velocity buffer is encoded.
  247. *
  248. * 3. The next step is to apply SMAA to each subpixel jittered frame, just as
  249. * done for 1x.
  250. *
  251. * 4. At this point you should already have something usable, but for best
  252. * results the proper area textures must be set depending on current jitter.
  253. * For this, the parameter 'subsampleIndices' of
  254. * 'SMAABlendingWeightCalculationPS' must be set as follows, for our T2x
  255. * mode:
  256. *
  257. * @SUBSAMPLE_INDICES
  258. *
  259. * | S# | Camera Jitter | subsampleIndices |
  260. * +----+------------------+---------------------+
  261. * | 0 | ( 0.25, -0.25) | float4(1, 1, 1, 0) |
  262. * | 1 | (-0.25, 0.25) | float4(2, 2, 2, 0) |
  263. *
  264. * These jitter positions assume a bottom-to-top y axis. S# stands for the
  265. * sample number.
  266. *
  267. * More information about temporal supersampling here:
  268. * http://iryoku.com/aacourse/downloads/13-Anti-Aliasing-Methods-in-CryENGINE-3.pdf
  269. *
  270. * c) If you want to enable spatial multisampling (SMAA S2x):
  271. *
  272. * 1. The scene must be rendered using MSAA 2x. The MSAA 2x buffer must be
  273. * created with:
  274. * - DX10: see below (*)
  275. * - DX10.1: D3D10_STANDARD_MULTISAMPLE_PATTERN or
  276. * - DX11: D3D11_STANDARD_MULTISAMPLE_PATTERN
  277. *
  278. * This allows one to ensure that the subsample order matches the table in
  279. * @SUBSAMPLE_INDICES.
  280. *
  281. * (*) In the case of DX10, we refer the reader to:
  282. * - SMAA::detectMSAAOrder and
  283. * - SMAA::msaaReorder
  284. *
  285. * These functions allows one to match the standard multisample patterns by
  286. * detecting the subsample order for a specific GPU, and reordering
  287. * them appropriately.
  288. *
  289. * 2. A shader must be run to output each subsample into a separate buffer
  290. * (DX10 is required). You can use SMAASeparate for this purpose, or just do
  291. * it in an existing pass (for example, in the tone mapping pass, which has
  292. * the advantage of feeding tone mapped subsamples to SMAA, which will yield
  293. * better results).
  294. *
  295. * 3. The full SMAA 1x pipeline must be run for each separated buffer, storing
  296. * the results in the final buffer. The second run should alpha blend with
  297. * the existing final buffer using a blending factor of 0.5.
  298. * 'subsampleIndices' must be adjusted as in the SMAA T2x case (see point
  299. * b).
  300. *
  301. * d) If you want to enable temporal supersampling on top of SMAA S2x
  302. * (which actually is SMAA 4x):
  303. *
  304. * 1. SMAA 4x consists on temporally jittering SMAA S2x, so the first step is
  305. * to calculate SMAA S2x for current frame. In this case, 'subsampleIndices'
  306. * must be set as follows:
  307. *
  308. * | F# | S# | Camera Jitter | Net Jitter | subsampleIndices |
  309. * +----+----+--------------------+-------------------+----------------------+
  310. * | 0 | 0 | ( 0.125, 0.125) | ( 0.375, -0.125) | float4(5, 3, 1, 3) |
  311. * | 0 | 1 | ( 0.125, 0.125) | (-0.125, 0.375) | float4(4, 6, 2, 3) |
  312. * +----+----+--------------------+-------------------+----------------------+
  313. * | 1 | 2 | (-0.125, -0.125) | ( 0.125, -0.375) | float4(3, 5, 1, 4) |
  314. * | 1 | 3 | (-0.125, -0.125) | (-0.375, 0.125) | float4(6, 4, 2, 4) |
  315. *
  316. * These jitter positions assume a bottom-to-top y axis. F# stands for the
  317. * frame number. S# stands for the sample number.
  318. *
  319. * 2. After calculating SMAA S2x for current frame (with the new subsample
  320. * indices), previous frame must be reprojected as in SMAA T2x mode (see
  321. * point b).
  322. *
  323. * e) If motion blur is used, you may want to do the edge detection pass
  324. * together with motion blur. This has two advantages:
  325. *
  326. * 1. Pixels under heavy motion can be omitted from the edge detection process.
  327. * For these pixels we can just store "no edge", as motion blur will take
  328. * care of them.
  329. * 2. The center pixel tap is reused.
  330. *
  331. * Note that in this case depth testing should be used instead of stenciling,
  332. * as we have to write all the pixels in the motion blur pass.
  333. *
  334. * That's it!
  335. */
  336. //-----------------------------------------------------------------------------
  337. // SMAA Presets
  338. /**
  339. * Note that if you use one of these presets, the following configuration
  340. * macros will be ignored if set in the "Configurable Defines" section.
  341. */
  342. #if defined(SMAA_PRESET_LOW)
  343. #define SMAA_THRESHOLD 0.15
  344. #define SMAA_MAX_SEARCH_STEPS 4
  345. #define SMAA_DISABLE_DIAG_DETECTION
  346. #define SMAA_DISABLE_CORNER_DETECTION
  347. #elif defined(SMAA_PRESET_MEDIUM)
  348. #define SMAA_THRESHOLD 0.1
  349. #define SMAA_MAX_SEARCH_STEPS 8
  350. #define SMAA_DISABLE_DIAG_DETECTION
  351. #define SMAA_DISABLE_CORNER_DETECTION
  352. #elif defined(SMAA_PRESET_HIGH)
  353. #define SMAA_THRESHOLD 0.1
  354. #define SMAA_MAX_SEARCH_STEPS 16
  355. #define SMAA_MAX_SEARCH_STEPS_DIAG 8
  356. #define SMAA_CORNER_ROUNDING 25
  357. #elif defined(SMAA_PRESET_ULTRA)
  358. #define SMAA_THRESHOLD 0.05
  359. #define SMAA_MAX_SEARCH_STEPS 32
  360. #define SMAA_MAX_SEARCH_STEPS_DIAG 16
  361. #define SMAA_CORNER_ROUNDING 25
  362. #endif
  363. //-----------------------------------------------------------------------------
  364. // Configurable Defines
  365. /**
  366. * SMAA_THRESHOLD specifies the threshold or sensitivity to edges.
  367. * Lowering this value you will be able to detect more edges at the expense of
  368. * performance.
  369. *
  370. * Range: [0, 0.5]
  371. * 0.1 is a reasonable value, and allows one to catch most visible edges.
  372. * 0.05 is a rather overkill value, that allows one to catch 'em all.
  373. *
  374. * If temporal supersampling is used, 0.2 could be a reasonable value, as low
  375. * contrast edges are properly filtered by just 2x.
  376. */
  377. #ifndef SMAA_THRESHOLD
  378. #define SMAA_THRESHOLD 0.1
  379. #endif
  380. /**
  381. * SMAA_DEPTH_THRESHOLD specifies the threshold for depth edge detection.
  382. *
  383. * Range: depends on the depth range of the scene.
  384. */
  385. #ifndef SMAA_DEPTH_THRESHOLD
  386. #define SMAA_DEPTH_THRESHOLD (0.1 * SMAA_THRESHOLD)
  387. #endif
  388. /**
  389. * SMAA_MAX_SEARCH_STEPS specifies the maximum steps performed in the
  390. * horizontal/vertical pattern searches, at each side of the pixel.
  391. *
  392. * In number of pixels, it's actually the double. So the maximum line length
  393. * perfectly handled by, for example 16, is 64 (by perfectly, we meant that
  394. * longer lines won't look as good, but still antialiased).
  395. *
  396. * Range: [0, 112]
  397. */
  398. #ifndef SMAA_MAX_SEARCH_STEPS
  399. #define SMAA_MAX_SEARCH_STEPS 16
  400. #endif
  401. )SHADER_SOURCE";
  402. const char smaa_base_shader_p2[] = R"SHADER_SOURCE(
  403. /**
  404. * SMAA_MAX_SEARCH_STEPS_DIAG specifies the maximum steps performed in the
  405. * diagonal pattern searches, at each side of the pixel. In this case we jump
  406. * one pixel at time, instead of two.
  407. *
  408. * Range: [0, 20]
  409. *
  410. * On high-end machines it is cheap (between a 0.8x and 0.9x slower for 16
  411. * steps), but it can have a significant impact on older machines.
  412. *
  413. * Define SMAA_DISABLE_DIAG_DETECTION to disable diagonal processing.
  414. */
  415. #ifndef SMAA_MAX_SEARCH_STEPS_DIAG
  416. #define SMAA_MAX_SEARCH_STEPS_DIAG 8
  417. #endif
  418. /**
  419. * SMAA_CORNER_ROUNDING specifies how much sharp corners will be rounded.
  420. *
  421. * Range: [0, 100]
  422. *
  423. * Define SMAA_DISABLE_CORNER_DETECTION to disable corner processing.
  424. */
  425. #ifndef SMAA_CORNER_ROUNDING
  426. #define SMAA_CORNER_ROUNDING 25
  427. #endif
  428. /**
  429. * If there is an neighbor edge that has SMAA_LOCAL_CONTRAST_FACTOR times
  430. * bigger contrast than current edge, current edge will be discarded.
  431. *
  432. * This allows one to eliminate spurious crossing edges, and is based on the fact
  433. * that, if there is too much contrast in a direction, that will hide
  434. * perceptually contrast in the other neighbors.
  435. */
  436. #ifndef SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR
  437. #define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0
  438. #endif
  439. /**
  440. * Predicated thresholding allows one to better preserve texture details and to
  441. * improve performance, by decreasing the number of detected edges using an
  442. * additional buffer like the light accumulation buffer, object ids or even the
  443. * depth buffer (the depth buffer usage may be limited to indoor or short range
  444. * scenes).
  445. *
  446. * It locally decreases the luma or color threshold if an edge is found in an
  447. * additional buffer (so the global threshold can be higher).
  448. *
  449. * This method was developed by Playstation EDGE MLAA team, and used in
  450. * Killzone 3, by using the light accumulation buffer. More information here:
  451. * http://iryoku.com/aacourse/downloads/06-MLAA-on-PS3.pptx
  452. */
  453. #ifndef SMAA_PREDICATION
  454. #define SMAA_PREDICATION 0
  455. #endif
  456. /**
  457. * Threshold to be used in the additional predication buffer.
  458. *
  459. * Range: depends on the input, so you'll have to find the magic number that
  460. * works for you.
  461. */
  462. #ifndef SMAA_PREDICATION_THRESHOLD
  463. #define SMAA_PREDICATION_THRESHOLD 0.01
  464. #endif
  465. /**
  466. * How much to scale the global threshold used for luma or color edge
  467. * detection when using predication.
  468. *
  469. * Range: [1, 5]
  470. */
  471. #ifndef SMAA_PREDICATION_SCALE
  472. #define SMAA_PREDICATION_SCALE 2.0
  473. #endif
  474. /**
  475. * How much to locally decrease the threshold.
  476. *
  477. * Range: [0, 1]
  478. */
  479. #ifndef SMAA_PREDICATION_STRENGTH
  480. #define SMAA_PREDICATION_STRENGTH 0.4
  481. #endif
  482. /**
  483. * Temporal reprojection allows one to remove ghosting artifacts when using
  484. * temporal supersampling. We use the CryEngine 3 method which also introduces
  485. * velocity weighting. This feature is of extreme importance for totally
  486. * removing ghosting. More information here:
  487. * http://iryoku.com/aacourse/downloads/13-Anti-Aliasing-Methods-in-CryENGINE-3.pdf
  488. *
  489. * Note that you'll need to setup a velocity buffer for enabling reprojection.
  490. * For static geometry, saving the previous depth buffer is a viable
  491. * alternative.
  492. */
  493. #ifndef SMAA_REPROJECTION
  494. #define SMAA_REPROJECTION 0
  495. #endif
  496. /**
  497. * SMAA_REPROJECTION_WEIGHT_SCALE controls the velocity weighting. It allows one
  498. * to remove ghosting trails behind the moving object, which are not removed by
  499. * just using reprojection. Using low values will exhibit ghosting, while using
  500. * high values will disable temporal supersampling under motion.
  501. *
  502. * Behind the scenes, velocity weighting removes temporal supersampling when
  503. * the velocity of the subsamples differs (meaning they are different objects).
  504. *
  505. * Range: [0, 80]
  506. */
  507. #ifndef SMAA_REPROJECTION_WEIGHT_SCALE
  508. #define SMAA_REPROJECTION_WEIGHT_SCALE 30.0
  509. #endif
  510. /**
  511. * On some compilers, discard cannot be used in vertex shaders. Thus, they need
  512. * to be compiled separately.
  513. */
  514. #ifndef SMAA_INCLUDE_VS
  515. #define SMAA_INCLUDE_VS 1
  516. #endif
  517. #ifndef SMAA_INCLUDE_PS
  518. #define SMAA_INCLUDE_PS 1
  519. #endif
  520. //-----------------------------------------------------------------------------
  521. // Texture Access Defines
  522. #ifndef SMAA_AREATEX_SELECT
  523. #if defined(SMAA_HLSL_3)
  524. #define SMAA_AREATEX_SELECT(sample) sample.ra
  525. #else
  526. #define SMAA_AREATEX_SELECT(sample) sample.rg
  527. #endif
  528. #endif
  529. #ifndef SMAA_SEARCHTEX_SELECT
  530. #define SMAA_SEARCHTEX_SELECT(sample) sample.r
  531. #endif
  532. #ifndef SMAA_DECODE_VELOCITY
  533. #define SMAA_DECODE_VELOCITY(sample) sample.rg
  534. #endif
  535. //-----------------------------------------------------------------------------
  536. // Non-Configurable Defines
  537. #define SMAA_AREATEX_MAX_DISTANCE 16
  538. #define SMAA_AREATEX_MAX_DISTANCE_DIAG 20
  539. #define SMAA_AREATEX_PIXEL_SIZE (1.0 / float2(160.0, 560.0))
  540. #define SMAA_AREATEX_SUBTEX_SIZE (1.0 / 7.0)
  541. #define SMAA_SEARCHTEX_SIZE float2(66.0, 33.0)
  542. #define SMAA_SEARCHTEX_PACKED_SIZE float2(64.0, 16.0)
  543. #define SMAA_CORNER_ROUNDING_NORM (float(SMAA_CORNER_ROUNDING) / 100.0)
  544. //-----------------------------------------------------------------------------
  545. // Porting Functions
  546. #if defined(SMAA_HLSL_3)
  547. #define SMAATexture2D(tex) sampler2D tex
  548. #define SMAATexturePass2D(tex) tex
  549. #define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0))
  550. #define SMAASampleLevelZeroPoint(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0))
  551. #define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlod(tex, float4(coord + offset * SMAA_RT_METRICS.xy, 0.0, 0.0))
  552. #define SMAASample(tex, coord) tex2D(tex, coord)
  553. #define SMAASamplePoint(tex, coord) tex2D(tex, coord)
  554. #define SMAASampleOffset(tex, coord, offset) tex2D(tex, coord + offset * SMAA_RT_METRICS.xy)
  555. #define SMAA_FLATTEN [flatten]
  556. #define SMAA_BRANCH [branch]
  557. #endif
  558. #if defined(SMAA_HLSL_4) || defined(SMAA_HLSL_4_1)
  559. SamplerState LinearSampler { Filter = MIN_MAG_LINEAR_MIP_POINT; AddressU = Clamp; AddressV = Clamp; };
  560. SamplerState PointSampler { Filter = MIN_MAG_MIP_POINT; AddressU = Clamp; AddressV = Clamp; };
  561. #define SMAATexture2D(tex) Texture2D tex
  562. #define SMAATexturePass2D(tex) tex
  563. #define SMAASampleLevelZero(tex, coord) tex.SampleLevel(LinearSampler, coord, 0)
  564. #define SMAASampleLevelZeroPoint(tex, coord) tex.SampleLevel(PointSampler, coord, 0)
  565. #define SMAASampleLevelZeroOffset(tex, coord, offset) tex.SampleLevel(LinearSampler, coord, 0, offset)
  566. #define SMAASample(tex, coord) tex.Sample(LinearSampler, coord)
  567. #define SMAASamplePoint(tex, coord) tex.Sample(PointSampler, coord)
  568. #define SMAASampleOffset(tex, coord, offset) tex.Sample(LinearSampler, coord, offset)
  569. #define SMAA_FLATTEN [flatten]
  570. #define SMAA_BRANCH [branch]
  571. #define SMAATexture2DMS2(tex) Texture2DMS<float4, 2> tex
  572. #define SMAALoad(tex, pos, sample) tex.Load(pos, sample)
  573. #if defined(SMAA_HLSL_4_1)
  574. #define SMAAGather(tex, coord) tex.Gather(LinearSampler, coord, 0)
  575. #endif
  576. #endif
  577. #if defined(SMAA_GLSL_2_1) || defined(SMAA_GLSL_3) || defined(SMAA_GLSL_4)
  578. #define SMAATexture2D(tex) sampler2D tex
  579. #define SMAATexturePass2D(tex) tex
  580. #define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0)
  581. #define SMAASampleLevelZeroPoint(tex, coord) textureLod(tex, coord, 0.0)
  582. #define SMAASampleLevelZeroOffset(tex, coord, offset) textureLodOffset(tex, coord, 0.0, offset)
  583. #if defined(SMAA_GLSL_2_1)
  584. #define SMAASample(tex, coord) texture2D(tex, coord)
  585. #define SMAASamplePoint(tex, coord) texture2D(tex, coord)
  586. #define SMAASampleOffset(tex, coord, offset) texture2D(tex, coord + offset * SMAA_RT_METRICS.rg)
  587. #define round(x) floor(x + 0.5)
  588. #define textureLod(tex, coord, level) texture2D(tex, coord)
  589. #define textureLodOffset(tex, coord, level, offset) texture2D(tex, coord + offset * SMAA_RT_METRICS.rg)
  590. #else
  591. #define SMAASample(tex, coord) texture(tex, coord)
  592. #define SMAASamplePoint(tex, coord) texture(tex, coord)
  593. #define SMAASampleOffset(tex, coord, offset) texture(tex, coord, offset)
  594. #endif
  595. #define SMAA_FLATTEN
  596. #define SMAA_BRANCH
  597. #define lerp(a, b, t) mix(a, b, t)
  598. #define saturate(a) clamp(a, 0.0, 1.0)
  599. #if defined(SMAA_GLSL_4)
  600. #define mad(a, b, c) fma(a, b, c)
  601. #define SMAAGather(tex, coord) textureGather(tex, coord)
  602. #else
  603. #define mad(a, b, c) (a * b + c)
  604. #endif
  605. #define float2 vec2
  606. #define float3 vec3
  607. #define float4 vec4
  608. #define int2 ivec2
  609. #define int3 ivec3
  610. #define int4 ivec4
  611. #define bool2 bvec2
  612. #define bool3 bvec3
  613. #define bool4 bvec4
  614. #endif
  615. #if !defined(SMAA_HLSL_3) && !defined(SMAA_HLSL_4) && !defined(SMAA_HLSL_4_1) && !defined(SMAA_GLSL_2_1) && !defined(SMAA_GLSL_3) && !defined(SMAA_GLSL_4) && !defined(SMAA_CUSTOM_SL)
  616. #error you must define the shading language: SMAA_HLSL_*, SMAA_GLSL_* or SMAA_CUSTOM_SL
  617. #endif
  618. //-----------------------------------------------------------------------------
  619. // Misc functions
  620. /**
  621. * Gathers current pixel, and the top-left neighbors.
  622. */
  623. float3 SMAAGatherNeighbours(float2 texcoord,
  624. float4 offset[3],
  625. SMAATexture2D(tex)) {
  626. #ifdef SMAAGather
  627. return SMAAGather(tex, texcoord + SMAA_RT_METRICS.xy * float2(-0.5, -0.5)).grb;
  628. #else
  629. float P = SMAASamplePoint(tex, texcoord).r;
  630. float Pleft = SMAASamplePoint(tex, offset[0].xy).r;
  631. float Ptop = SMAASamplePoint(tex, offset[0].zw).r;
  632. return float3(P, Pleft, Ptop);
  633. #endif
  634. }
  635. /**
  636. * Adjusts the threshold by means of predication.
  637. */
  638. float2 SMAACalculatePredicatedThreshold(float2 texcoord,
  639. float4 offset[3],
  640. SMAATexture2D(predicationTex)) {
  641. float3 neighbours = SMAAGatherNeighbours(texcoord, offset, SMAATexturePass2D(predicationTex));
  642. float2 delta = abs(neighbours.xx - neighbours.yz);
  643. float2 edges = step(SMAA_PREDICATION_THRESHOLD, delta);
  644. return SMAA_PREDICATION_SCALE * SMAA_THRESHOLD * (1.0 - SMAA_PREDICATION_STRENGTH * edges);
  645. }
  646. /**
  647. * Conditional move:
  648. */
  649. void SMAAMovc(bool2 cond, inout float2 variable, float2 value) {
  650. SMAA_FLATTEN if (cond.x) variable.x = value.x;
  651. SMAA_FLATTEN if (cond.y) variable.y = value.y;
  652. }
  653. void SMAAMovc(bool4 cond, inout float4 variable, float4 value) {
  654. SMAAMovc(cond.xy, variable.xy, value.xy);
  655. SMAAMovc(cond.zw, variable.zw, value.zw);
  656. }
  657. #if SMAA_INCLUDE_VS
  658. //-----------------------------------------------------------------------------
  659. // Vertex Shaders
  660. /**
  661. * Edge Detection Vertex Shader
  662. */
  663. void SMAAEdgeDetectionVS(float2 texcoord,
  664. out float4 offset[3]) {
  665. offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-1.0, 0.0, 0.0, -1.0), texcoord.xyxy);
  666. offset[1] = mad(SMAA_RT_METRICS.xyxy, float4( 1.0, 0.0, 0.0, 1.0), texcoord.xyxy);
  667. offset[2] = mad(SMAA_RT_METRICS.xyxy, float4(-2.0, 0.0, 0.0, -2.0), texcoord.xyxy);
  668. }
  669. /**
  670. * Blend Weight Calculation Vertex Shader
  671. */
  672. void SMAABlendingWeightCalculationVS(float2 texcoord,
  673. out float2 pixcoord,
  674. out float4 offset[3]) {
  675. pixcoord = texcoord * SMAA_RT_METRICS.zw;
  676. // We will use these offsets for the searches later on (see @PSEUDO_GATHER4):
  677. offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-0.25, -0.125, 1.25, -0.125), texcoord.xyxy);
  678. offset[1] = mad(SMAA_RT_METRICS.xyxy, float4(-0.125, -0.25, -0.125, 1.25), texcoord.xyxy);
  679. // And these for the searches, they indicate the ends of the loops:
  680. offset[2] = mad(SMAA_RT_METRICS.xxyy,
  681. float4(-2.0, 2.0, -2.0, 2.0) * float(SMAA_MAX_SEARCH_STEPS),
  682. float4(offset[0].xz, offset[1].yw));
  683. }
  684. /**
  685. * Neighborhood Blending Vertex Shader
  686. */
  687. void SMAANeighborhoodBlendingVS(float2 texcoord,
  688. out float4 offset) {
  689. offset = mad(SMAA_RT_METRICS.xyxy, float4( 1.0, 0.0, 0.0, 1.0), texcoord.xyxy);
  690. }
  691. #endif // SMAA_INCLUDE_VS
  692. #if SMAA_INCLUDE_PS
  693. //-----------------------------------------------------------------------------
  694. // Edge Detection Pixel Shaders (First Pass)
  695. /**
  696. * Luma Edge Detection
  697. *
  698. * IMPORTANT NOTICE: luma edge detection requires gamma-corrected colors, and
  699. * thus 'colorTex' should be a non-sRGB texture.
  700. */
  701. float2 SMAALumaEdgeDetectionPS(float2 texcoord,
  702. float4 offset[3],
  703. SMAATexture2D(colorTex)
  704. #if SMAA_PREDICATION
  705. , SMAATexture2D(predicationTex)
  706. #endif
  707. ) {
  708. // Calculate the threshold:
  709. #if SMAA_PREDICATION
  710. float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, SMAATexturePass2D(predicationTex));
  711. #else
  712. float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD);
  713. #endif
  714. // Calculate lumas:
  715. float3 weights = float3(0.2126, 0.7152, 0.0722);
  716. float L = dot(SMAASamplePoint(colorTex, texcoord).rgb, weights);
  717. float Lleft = dot(SMAASamplePoint(colorTex, offset[0].xy).rgb, weights);
  718. float Ltop = dot(SMAASamplePoint(colorTex, offset[0].zw).rgb, weights);
  719. // We do the usual threshold:
  720. float4 delta;
  721. delta.xy = abs(L - float2(Lleft, Ltop));
  722. float2 edges = step(threshold, delta.xy);
  723. // Then discard if there is no edge:
  724. if (dot(edges, float2(1.0, 1.0)) == 0.0)
  725. discard;
  726. // Calculate right and bottom deltas:
  727. float Lright = dot(SMAASamplePoint(colorTex, offset[1].xy).rgb, weights);
  728. float Lbottom = dot(SMAASamplePoint(colorTex, offset[1].zw).rgb, weights);
  729. delta.zw = abs(L - float2(Lright, Lbottom));
  730. // Calculate the maximum delta in the direct neighborhood:
  731. float2 maxDelta = max(delta.xy, delta.zw);
  732. // Calculate left-left and top-top deltas:
  733. float Lleftleft = dot(SMAASamplePoint(colorTex, offset[2].xy).rgb, weights);
  734. float Ltoptop = dot(SMAASamplePoint(colorTex, offset[2].zw).rgb, weights);
  735. delta.zw = abs(float2(Lleft, Ltop) - float2(Lleftleft, Ltoptop));
  736. // Calculate the final maximum delta:
  737. maxDelta = max(maxDelta.xy, delta.zw);
  738. float finalDelta = max(maxDelta.x, maxDelta.y);
  739. // Local contrast adaptation:
  740. edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy);
  741. return edges;
  742. }
  743. /**
  744. * Color Edge Detection
  745. *
  746. * IMPORTANT NOTICE: color edge detection requires gamma-corrected colors, and
  747. * thus 'colorTex' should be a non-sRGB texture.
  748. */
  749. float2 SMAAColorEdgeDetectionPS(float2 texcoord,
  750. float4 offset[3],
  751. SMAATexture2D(colorTex)
  752. #if SMAA_PREDICATION
  753. , SMAATexture2D(predicationTex)
  754. #endif
  755. ) {
  756. // Calculate the threshold:
  757. #if SMAA_PREDICATION
  758. float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, predicationTex);
  759. #else
  760. float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD);
  761. #endif
  762. // Calculate color deltas:
  763. float4 delta;
  764. float3 C = SMAASamplePoint(colorTex, texcoord).rgb;
  765. float3 Cleft = SMAASamplePoint(colorTex, offset[0].xy).rgb;
  766. float3 t = abs(C - Cleft);
  767. delta.x = max(max(t.r, t.g), t.b);
  768. float3 Ctop = SMAASamplePoint(colorTex, offset[0].zw).rgb;
  769. t = abs(C - Ctop);
  770. delta.y = max(max(t.r, t.g), t.b);
  771. // We do the usual threshold:
  772. float2 edges = step(threshold, delta.xy);
  773. // Then discard if there is no edge:
  774. if (dot(edges, float2(1.0, 1.0)) == 0.0)
  775. discard;
  776. // Calculate right and bottom deltas:
  777. float3 Cright = SMAASamplePoint(colorTex, offset[1].xy).rgb;
  778. t = abs(C - Cright);
  779. delta.z = max(max(t.r, t.g), t.b);
  780. float3 Cbottom = SMAASamplePoint(colorTex, offset[1].zw).rgb;
  781. t = abs(C - Cbottom);
  782. delta.w = max(max(t.r, t.g), t.b);
  783. // Calculate the maximum delta in the direct neighborhood:
  784. float2 maxDelta = max(delta.xy, delta.zw);
  785. // Calculate left-left and top-top deltas:
  786. float3 Cleftleft = SMAASamplePoint(colorTex, offset[2].xy).rgb;
  787. t = abs(C - Cleftleft);
  788. delta.z = max(max(t.r, t.g), t.b);
  789. float3 Ctoptop = SMAASamplePoint(colorTex, offset[2].zw).rgb;
  790. t = abs(C - Ctoptop);
  791. delta.w = max(max(t.r, t.g), t.b);
  792. // Calculate the final maximum delta:
  793. maxDelta = max(maxDelta.xy, delta.zw);
  794. float finalDelta = max(maxDelta.x, maxDelta.y);
  795. // Local contrast adaptation:
  796. edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy);
  797. return edges;
  798. }
  799. )SHADER_SOURCE";
  800. extern const char smaa_base_shader_p3[] = R"SHADER_SOURCE(
  801. /**
  802. * Depth Edge Detection
  803. */
  804. float2 SMAADepthEdgeDetectionPS(float2 texcoord,
  805. float4 offset[3],
  806. SMAATexture2D(depthTex)) {
  807. float3 neighbours = SMAAGatherNeighbours(texcoord, offset, SMAATexturePass2D(depthTex));
  808. float2 delta = abs(neighbours.xx - float2(neighbours.y, neighbours.z));
  809. float2 edges = step(SMAA_DEPTH_THRESHOLD, delta);
  810. if (dot(edges, float2(1.0, 1.0)) == 0.0)
  811. discard;
  812. return edges;
  813. }
  814. //-----------------------------------------------------------------------------
  815. // Diagonal Search Functions
  816. #if !defined(SMAA_DISABLE_DIAG_DETECTION)
  817. /**
  818. * Allows one to decode two binary values from a bilinear-filtered access.
  819. */
  820. float2 SMAADecodeDiagBilinearAccess(float2 e) {
  821. // Bilinear access for fetching 'e' have a 0.25 offset, and we are
  822. // interested in the R and G edges:
  823. //
  824. // +---G---+-------+
  825. // | x o R x |
  826. // +-------+-------+
  827. //
  828. // Then, if one of these edge is enabled:
  829. // Red: (0.75 * X + 0.25 * 1) => 0.25 or 1.0
  830. // Green: (0.75 * 1 + 0.25 * X) => 0.75 or 1.0
  831. //
  832. // This function will unpack the values (mad + mul + round):
  833. // wolframalpha.com: round(x * abs(5 * x - 5 * 0.75)) plot 0 to 1
  834. e.r = e.r * abs(5.0 * e.r - 5.0 * 0.75);
  835. return round(e);
  836. }
  837. float4 SMAADecodeDiagBilinearAccess(float4 e) {
  838. e.rb = e.rb * abs(5.0 * e.rb - 5.0 * 0.75);
  839. return round(e);
  840. }
  841. /**
  842. * These functions allows one to perform diagonal pattern searches.
  843. */
  844. float2 SMAASearchDiag1(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, out float2 e) {
  845. float4 coord = float4(texcoord, -1.0, 1.0);
  846. float3 t = float3(SMAA_RT_METRICS.xy, 1.0);
  847. while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) &&
  848. coord.w > 0.9) {
  849. coord.xyz = mad(t, float3(dir, 1.0), coord.xyz);
  850. e = SMAASampleLevelZero(edgesTex, coord.xy).rg;
  851. coord.w = dot(e, float2(0.5, 0.5));
  852. }
  853. return coord.zw;
  854. }
  855. float2 SMAASearchDiag2(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, out float2 e) {
  856. float4 coord = float4(texcoord, -1.0, 1.0);
  857. coord.x += 0.25 * SMAA_RT_METRICS.x; // See @SearchDiag2Optimization
  858. float3 t = float3(SMAA_RT_METRICS.xy, 1.0);
  859. while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) &&
  860. coord.w > 0.9) {
  861. coord.xyz = mad(t, float3(dir, 1.0), coord.xyz);
  862. // @SearchDiag2Optimization
  863. // Fetch both edges at once using bilinear filtering:
  864. e = SMAASampleLevelZero(edgesTex, coord.xy).rg;
  865. e = SMAADecodeDiagBilinearAccess(e);
  866. // Non-optimized version:
  867. // e.g = SMAASampleLevelZero(edgesTex, coord.xy).g;
  868. // e.r = SMAASampleLevelZeroOffset(edgesTex, coord.xy, int2(1, 0)).r;
  869. coord.w = dot(e, float2(0.5, 0.5));
  870. }
  871. return coord.zw;
  872. }
  873. /**
  874. * Similar to SMAAArea, this calculates the area corresponding to a certain
  875. * diagonal distance and crossing edges 'e'.
  876. */
  877. float2 SMAAAreaDiag(SMAATexture2D(areaTex), float2 dist, float2 e, float offset) {
  878. float2 texcoord = mad(float2(SMAA_AREATEX_MAX_DISTANCE_DIAG, SMAA_AREATEX_MAX_DISTANCE_DIAG), e, dist);
  879. // We do a scale and bias for mapping to texel space:
  880. texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE);
  881. // Diagonal areas are on the second half of the texture:
  882. texcoord.x += 0.5;
  883. // Move to proper place, according to the subpixel offset:
  884. texcoord.y += SMAA_AREATEX_SUBTEX_SIZE * offset;
  885. // Do it!
  886. return SMAA_AREATEX_SELECT(SMAASampleLevelZero(areaTex, texcoord));
  887. }
  888. /**
  889. * This searches for diagonal patterns and returns the corresponding weights.
  890. */
  891. float2 SMAACalculateDiagWeights(SMAATexture2D(edgesTex), SMAATexture2D(areaTex), float2 texcoord, float2 e, float4 subsampleIndices) {
  892. float2 weights = float2(0.0, 0.0);
  893. // Search for the line ends:
  894. float4 d;
  895. float2 end;
  896. if (e.r > 0.0) {
  897. d.xz = SMAASearchDiag1(SMAATexturePass2D(edgesTex), texcoord, float2(-1.0, 1.0), end);
  898. d.x += float(end.y > 0.9);
  899. } else
  900. d.xz = float2(0.0, 0.0);
  901. d.yw = SMAASearchDiag1(SMAATexturePass2D(edgesTex), texcoord, float2(1.0, -1.0), end);
  902. SMAA_BRANCH
  903. if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3
  904. // Fetch the crossing edges:
  905. float4 coords = mad(float4(-d.x + 0.25, d.x, d.y, -d.y - 0.25), SMAA_RT_METRICS.xyxy, texcoord.xyxy);
  906. float4 c;
  907. c.xy = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).rg;
  908. c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, 0)).rg;
  909. c.yxwz = SMAADecodeDiagBilinearAccess(c.xyzw);
  910. // Non-optimized version:
  911. // float4 coords = mad(float4(-d.x, d.x, d.y, -d.y), SMAA_RT_METRICS.xyxy, texcoord.xyxy);
  912. // float4 c;
  913. // c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).g;
  914. // c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2( 0, 0)).r;
  915. // c.z = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, 0)).g;
  916. // c.w = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, -1)).r;
  917. // Merge crossing edges at each side into a single value:
  918. float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw);
  919. // Remove the crossing edge if we didn't found the end of the line:
  920. SMAAMovc(bool2(step(0.9, d.zw)), cc, float2(0.0, 0.0));
  921. // Fetch the areas for this line:
  922. weights += SMAAAreaDiag(SMAATexturePass2D(areaTex), d.xy, cc, subsampleIndices.z);
  923. }
  924. // Search for the line ends:
  925. d.xz = SMAASearchDiag2(SMAATexturePass2D(edgesTex), texcoord, float2(-1.0, -1.0), end);
  926. if (SMAASampleLevelZeroOffset(edgesTex, texcoord, int2(1, 0)).r > 0.0) {
  927. d.yw = SMAASearchDiag2(SMAATexturePass2D(edgesTex), texcoord, float2(1.0, 1.0), end);
  928. d.y += float(end.y > 0.9);
  929. } else
  930. d.yw = float2(0.0, 0.0);
  931. SMAA_BRANCH
  932. if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3
  933. // Fetch the crossing edges:
  934. float4 coords = mad(float4(-d.x, -d.x, d.y, d.y), SMAA_RT_METRICS.xyxy, texcoord.xyxy);
  935. float4 c;
  936. c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).g;
  937. c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2( 0, -1)).r;
  938. c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, 0)).gr;
  939. float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw);
  940. // Remove the crossing edge if we didn't found the end of the line:
  941. SMAAMovc(bool2(step(0.9, d.zw)), cc, float2(0.0, 0.0));
  942. // Fetch the areas for this line:
  943. weights += SMAAAreaDiag(SMAATexturePass2D(areaTex), d.xy, cc, subsampleIndices.w).gr;
  944. }
  945. return weights;
  946. }
  947. #endif
  948. //-----------------------------------------------------------------------------
  949. // Horizontal/Vertical Search Functions
  950. /**
  951. * This allows one to determine how much length should we add in the last step
  952. * of the searches. It takes the bilinearly interpolated edge (see
  953. * @PSEUDO_GATHER4), and adds 0, 1 or 2, depending on which edges and
  954. * crossing edges are active.
  955. */
  956. float SMAASearchLength(SMAATexture2D(searchTex), float2 e, float offset) {
  957. // The texture is flipped vertically, with left and right cases taking half
  958. // of the space horizontally:
  959. float2 scale = SMAA_SEARCHTEX_SIZE * float2(0.5, -1.0);
  960. float2 bias = SMAA_SEARCHTEX_SIZE * float2(offset, 1.0);
  961. // Scale and bias to access texel centers:
  962. scale += float2(-1.0, 1.0);
  963. bias += float2( 0.5, -0.5);
  964. // Convert from pixel coordinates to texcoords:
  965. // (We use SMAA_SEARCHTEX_PACKED_SIZE because the texture is cropped)
  966. scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;
  967. bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;
  968. // Lookup the search texture:
  969. return SMAA_SEARCHTEX_SELECT(SMAASampleLevelZero(searchTex, mad(scale, e, bias)));
  970. }
  971. /**
  972. * Horizontal/vertical search functions for the 2nd pass.
  973. */
  974. float SMAASearchXLeft(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) {
  975. /**
  976. * @PSEUDO_GATHER4
  977. * This texcoord has been offset by (-0.25, -0.125) in the vertex shader to
  978. * sample between edge, thus fetching four edges in a row.
  979. * Sampling with different offsets in each direction allows one to
  980. * disambiguate which edges are active from the four fetched ones.
  981. */
  982. float2 e = float2(0.0, 1.0);
  983. while (texcoord.x > end &&
  984. e.g > 0.8281 && // Is there some edge not activated?
  985. e.r == 0.0) { // Or is there a crossing edge that breaks the line?
  986. e = SMAASampleLevelZero(edgesTex, texcoord).rg;
  987. texcoord = mad(-float2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
  988. }
  989. float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.0), 3.25);
  990. return mad(SMAA_RT_METRICS.x, offset, texcoord.x);
  991. // Non-optimized version:
  992. // We correct the previous (-0.25, -0.125) offset we applied:
  993. // texcoord.x += 0.25 * SMAA_RT_METRICS.x;
  994. // The searches are bias by 1, so adjust the coords accordingly:
  995. // texcoord.x += SMAA_RT_METRICS.x;
  996. // Disambiguate the length added by the last step:
  997. // texcoord.x += 2.0 * SMAA_RT_METRICS.x; // Undo last step
  998. // texcoord.x -= SMAA_RT_METRICS.x * (255.0 / 127.0) * SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.0);
  999. // return mad(SMAA_RT_METRICS.x, offset, texcoord.x);
  1000. }
  1001. float SMAASearchXRight(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) {
  1002. float2 e = float2(0.0, 1.0);
  1003. while (texcoord.x < end &&
  1004. e.g > 0.8281 && // Is there some edge not activated?
  1005. e.r == 0.0) { // Or is there a crossing edge that breaks the line?
  1006. e = SMAASampleLevelZero(edgesTex, texcoord).rg;
  1007. texcoord = mad(float2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
  1008. }
  1009. float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.5), 3.25);
  1010. return mad(-SMAA_RT_METRICS.x, offset, texcoord.x);
  1011. }
  1012. float SMAASearchYUp(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) {
  1013. float2 e = float2(1.0, 0.0);
  1014. while (texcoord.y > end &&
  1015. e.r > 0.8281 && // Is there some edge not activated?
  1016. e.g == 0.0) { // Or is there a crossing edge that breaks the line?
  1017. e = SMAASampleLevelZero(edgesTex, texcoord).rg;
  1018. texcoord = mad(-float2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
  1019. }
  1020. float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e.gr, 0.0), 3.25);
  1021. return mad(SMAA_RT_METRICS.y, offset, texcoord.y);
  1022. }
  1023. float SMAASearchYDown(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end) {
  1024. float2 e = float2(1.0, 0.0);
  1025. while (texcoord.y < end &&
  1026. e.r > 0.8281 && // Is there some edge not activated?
  1027. e.g == 0.0) { // Or is there a crossing edge that breaks the line?
  1028. e = SMAASampleLevelZero(edgesTex, texcoord).rg;
  1029. texcoord = mad(float2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
  1030. }
  1031. float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e.gr, 0.5), 3.25);
  1032. return mad(-SMAA_RT_METRICS.y, offset, texcoord.y);
  1033. }
  1034. /**
  1035. * Ok, we have the distance and both crossing edges. So, what are the areas
  1036. * at each side of current edge?
  1037. */
  1038. float2 SMAAArea(SMAATexture2D(areaTex), float2 dist, float e1, float e2, float offset) {
  1039. // Rounding prevents precision errors of bilinear filtering:
  1040. float2 texcoord = mad(float2(SMAA_AREATEX_MAX_DISTANCE, SMAA_AREATEX_MAX_DISTANCE), round(4.0 * float2(e1, e2)), dist);
  1041. // We do a scale and bias for mapping to texel space:
  1042. texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE);
  1043. // Move to proper place, according to the subpixel offset:
  1044. texcoord.y = mad(SMAA_AREATEX_SUBTEX_SIZE, offset, texcoord.y);
  1045. // Do it!
  1046. return SMAA_AREATEX_SELECT(SMAASampleLevelZero(areaTex, texcoord));
  1047. }
  1048. //-----------------------------------------------------------------------------
  1049. // Corner Detection Functions
  1050. void SMAADetectHorizontalCornerPattern(SMAATexture2D(edgesTex), inout float2 weights, float4 texcoord, float2 d) {
  1051. #if !defined(SMAA_DISABLE_CORNER_DETECTION)
  1052. float2 leftRight = step(d.xy, d.yx);
  1053. float2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight;
  1054. rounding /= leftRight.x + leftRight.y; // Reduce blending for pixels in the center of a line.
  1055. float2 factor = float2(1.0, 1.0);
  1056. factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(0, 1)).r;
  1057. factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(1, 1)).r;
  1058. factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(0, -2)).r;
  1059. factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(1, -2)).r;
  1060. weights *= saturate(factor);
  1061. #endif
  1062. }
  1063. void SMAADetectVerticalCornerPattern(SMAATexture2D(edgesTex), inout float2 weights, float4 texcoord, float2 d) {
  1064. #if !defined(SMAA_DISABLE_CORNER_DETECTION)
  1065. float2 leftRight = step(d.xy, d.yx);
  1066. float2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight;
  1067. rounding /= leftRight.x + leftRight.y;
  1068. float2 factor = float2(1.0, 1.0);
  1069. factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2( 1, 0)).g;
  1070. factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2( 1, 1)).g;
  1071. factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(-2, 0)).g;
  1072. factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(-2, 1)).g;
  1073. weights *= saturate(factor);
  1074. #endif
  1075. }
  1076. //-----------------------------------------------------------------------------
  1077. // Blending Weight Calculation Pixel Shader (Second Pass)
  1078. float4 SMAABlendingWeightCalculationPS(float2 texcoord,
  1079. float2 pixcoord,
  1080. float4 offset[3],
  1081. SMAATexture2D(edgesTex),
  1082. SMAATexture2D(areaTex),
  1083. SMAATexture2D(searchTex),
  1084. float4 subsampleIndices) { // Just pass zero for SMAA 1x, see @SUBSAMPLE_INDICES.
  1085. float4 weights = float4(0.0, 0.0, 0.0, 0.0);
  1086. float2 e = SMAASample(edgesTex, texcoord).rg;
  1087. SMAA_BRANCH
  1088. if (e.g > 0.0) { // Edge at north
  1089. #if !defined(SMAA_DISABLE_DIAG_DETECTION)
  1090. // Diagonals have both north and west edges, so searching for them in
  1091. // one of the boundaries is enough.
  1092. weights.rg = SMAACalculateDiagWeights(SMAATexturePass2D(edgesTex), SMAATexturePass2D(areaTex), texcoord, e, subsampleIndices);
  1093. // We give priority to diagonals, so if we find a diagonal we skip
  1094. // horizontal/vertical processing.
  1095. SMAA_BRANCH
  1096. if (weights.r == -weights.g) { // weights.r + weights.g == 0.0
  1097. #endif
  1098. float2 d;
  1099. // Find the distance to the left:
  1100. float3 coords;
  1101. coords.x = SMAASearchXLeft(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].xy, offset[2].x);
  1102. coords.y = offset[1].y; // offset[1].y = texcoord.y - 0.25 * SMAA_RT_METRICS.y (@CROSSING_OFFSET)
  1103. d.x = coords.x;
  1104. // Now fetch the left crossing edges, two at a time using bilinear
  1105. // filtering. Sampling at -0.25 (see @CROSSING_OFFSET) enables to
  1106. // discern what value each edge has:
  1107. float e1 = SMAASampleLevelZero(edgesTex, coords.xy).r;
  1108. // Find the distance to the right:
  1109. coords.z = SMAASearchXRight(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].zw, offset[2].y);
  1110. d.y = coords.z;
  1111. // We want the distances to be in pixel units (doing this here allow one
  1112. // to better interleave arithmetic and memory accesses):
  1113. d = abs(round(mad(SMAA_RT_METRICS.zz, d, -pixcoord.xx)));
  1114. // SMAAArea below needs a sqrt, as the areas texture is compressed
  1115. // quadratically:
  1116. float2 sqrt_d = sqrt(d);
  1117. )SHADER_SOURCE";
  1118. extern const char smaa_base_shader_p4[] = R"SHADER_SOURCE(
  1119. // Fetch the right crossing edges:
  1120. float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.zy, int2(1, 0)).r;
  1121. // Ok, we know how this pattern looks like, now it is time for getting
  1122. // the actual area:
  1123. weights.rg = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.y);
  1124. // Fix corners:
  1125. coords.y = texcoord.y;
  1126. SMAADetectHorizontalCornerPattern(SMAATexturePass2D(edgesTex), weights.rg, coords.xyzy, d);
  1127. #if !defined(SMAA_DISABLE_DIAG_DETECTION)
  1128. } else
  1129. e.r = 0.0; // Skip vertical processing.
  1130. #endif
  1131. }
  1132. SMAA_BRANCH
  1133. if (e.r > 0.0) { // Edge at west
  1134. float2 d;
  1135. // Find the distance to the top:
  1136. float3 coords;
  1137. coords.y = SMAASearchYUp(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].xy, offset[2].z);
  1138. coords.x = offset[0].x; // offset[1].x = texcoord.x - 0.25 * SMAA_RT_METRICS.x;
  1139. d.x = coords.y;
  1140. // Fetch the top crossing edges:
  1141. float e1 = SMAASampleLevelZero(edgesTex, coords.xy).g;
  1142. // Find the distance to the bottom:
  1143. coords.z = SMAASearchYDown(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].zw, offset[2].w);
  1144. d.y = coords.z;
  1145. // We want the distances to be in pixel units:
  1146. d = abs(round(mad(SMAA_RT_METRICS.ww, d, -pixcoord.yy)));
  1147. // SMAAArea below needs a sqrt, as the areas texture is compressed
  1148. // quadratically:
  1149. float2 sqrt_d = sqrt(d);
  1150. // Fetch the bottom crossing edges:
  1151. float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.xz, int2(0, 1)).g;
  1152. // Get the area for this direction:
  1153. weights.ba = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.x);
  1154. // Fix corners:
  1155. coords.x = texcoord.x;
  1156. SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), weights.ba, coords.xyxz, d);
  1157. }
  1158. return weights;
  1159. }
  1160. //-----------------------------------------------------------------------------
  1161. // Neighborhood Blending Pixel Shader (Third Pass)
  1162. float4 SMAANeighborhoodBlendingPS(float2 texcoord,
  1163. float4 offset,
  1164. SMAATexture2D(colorTex),
  1165. SMAATexture2D(blendTex)
  1166. #if SMAA_REPROJECTION
  1167. , SMAATexture2D(velocityTex)
  1168. #endif
  1169. ) {
  1170. // Fetch the blending weights for current pixel:
  1171. float4 a;
  1172. a.x = SMAASample(blendTex, offset.xy).a; // Right
  1173. a.y = SMAASample(blendTex, offset.zw).g; // Top
  1174. a.wz = SMAASample(blendTex, texcoord).xz; // Bottom / Left
  1175. // Is there any blending weight with a value greater than 0.0?
  1176. SMAA_BRANCH
  1177. if (dot(a, float4(1.0, 1.0, 1.0, 1.0)) < 1e-5) {
  1178. float4 color = SMAASampleLevelZero(colorTex, texcoord);
  1179. #if SMAA_REPROJECTION
  1180. float2 velocity = SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, texcoord));
  1181. // Pack velocity into the alpha channel:
  1182. color.a = sqrt(5.0 * length(velocity));
  1183. #endif
  1184. return color;
  1185. } else {
  1186. bool h = max(a.x, a.z) > max(a.y, a.w); // max(horizontal) > max(vertical)
  1187. // Calculate the blending offsets:
  1188. float4 blendingOffset = float4(0.0, a.y, 0.0, a.w);
  1189. float2 blendingWeight = a.yw;
  1190. SMAAMovc(bool4(h, h, h, h), blendingOffset, float4(a.x, 0.0, a.z, 0.0));
  1191. SMAAMovc(bool2(h, h), blendingWeight, a.xz);
  1192. blendingWeight /= dot(blendingWeight, float2(1.0, 1.0));
  1193. // Calculate the texture coordinates:
  1194. float4 blendingCoord = mad(blendingOffset, float4(SMAA_RT_METRICS.xy, -SMAA_RT_METRICS.xy), texcoord.xyxy);
  1195. // We exploit bilinear filtering to mix current pixel with the chosen
  1196. // neighbor:
  1197. float4 color = blendingWeight.x * SMAASampleLevelZero(colorTex, blendingCoord.xy);
  1198. color += blendingWeight.y * SMAASampleLevelZero(colorTex, blendingCoord.zw);
  1199. #if SMAA_REPROJECTION
  1200. // Antialias velocity for proper reprojection in a later stage:
  1201. float2 velocity = blendingWeight.x * SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, blendingCoord.xy));
  1202. velocity += blendingWeight.y * SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, blendingCoord.zw));
  1203. // Pack velocity into the alpha channel:
  1204. color.a = sqrt(5.0 * length(velocity));
  1205. #endif
  1206. return color;
  1207. }
  1208. }
  1209. //-----------------------------------------------------------------------------
  1210. // Temporal Resolve Pixel Shader (Optional Pass)
  1211. float4 SMAAResolvePS(float2 texcoord,
  1212. SMAATexture2D(currentColorTex),
  1213. SMAATexture2D(previousColorTex)
  1214. #if SMAA_REPROJECTION
  1215. , SMAATexture2D(velocityTex)
  1216. #endif
  1217. ) {
  1218. #if SMAA_REPROJECTION
  1219. // Velocity is assumed to be calculated for motion blur, so we need to
  1220. // inverse it for reprojection:
  1221. float2 velocity = -SMAA_DECODE_VELOCITY(SMAASamplePoint(velocityTex, texcoord).rg);
  1222. // Fetch current pixel:
  1223. float4 current = SMAASamplePoint(currentColorTex, texcoord);
  1224. // Reproject current coordinates and fetch previous pixel:
  1225. float4 previous = SMAASamplePoint(previousColorTex, texcoord + velocity);
  1226. // Attenuate the previous pixel if the velocity is different:
  1227. float delta = abs(current.a * current.a - previous.a * previous.a) / 5.0;
  1228. float weight = 0.5 * saturate(1.0 - sqrt(delta) * SMAA_REPROJECTION_WEIGHT_SCALE);
  1229. // Blend the pixels according to the calculated weight:
  1230. return lerp(current, previous, weight);
  1231. #else
  1232. // Just blend the pixels:
  1233. float4 current = SMAASamplePoint(currentColorTex, texcoord);
  1234. float4 previous = SMAASamplePoint(previousColorTex, texcoord);
  1235. return lerp(current, previous, 0.5);
  1236. #endif
  1237. }
  1238. //-----------------------------------------------------------------------------
  1239. // Separate Multisamples Pixel Shader (Optional Pass)
  1240. #ifdef SMAALoad
  1241. void SMAASeparatePS(float4 position,
  1242. float2 texcoord,
  1243. out float4 target0,
  1244. out float4 target1,
  1245. SMAATexture2DMS2(colorTexMS)) {
  1246. int2 pos = int2(position.xy);
  1247. target0 = SMAALoad(colorTexMS, pos, 0);
  1248. target1 = SMAALoad(colorTexMS, pos, 1);
  1249. }
  1250. #endif
  1251. //-----------------------------------------------------------------------------
  1252. #endif // SMAA_INCLUDE_PS
  1253. )SHADER_SOURCE";
  1254. const char smaa_pass_1_vertex_shader[] = R"SHADER_SOURCE(
  1255. varying vec4 offset[3];
  1256. varying vec2 texcoord;
  1257. void main()
  1258. {
  1259. texcoord = gl_MultiTexCoord0.st;
  1260. SMAAEdgeDetectionVS( texcoord, offset);
  1261. gl_Position = ftransform();
  1262. }
  1263. )SHADER_SOURCE";
  1264. const char smaa_pass_1_fragment_shader_luma[] = R"SHADER_SOURCE(
  1265. varying vec2 texcoord;
  1266. varying vec4 offset[3];
  1267. uniform sampler2D colorTex;
  1268. void main()
  1269. {
  1270. gl_FragColor.xy = SMAALumaEdgeDetectionPS(texcoord, offset, colorTex).xy;
  1271. }
  1272. )SHADER_SOURCE";
  1273. const char smaa_pass_1_fragment_shader_color[] = R"SHADER_SOURCE(
  1274. varying vec2 texcoord;
  1275. varying vec4 offset[3];
  1276. uniform sampler2D colorTex;
  1277. void main()
  1278. {
  1279. gl_FragColor.xy = SMAAColorEdgeDetectionPS(texcoord, offset, colorTex).xy;
  1280. }
  1281. )SHADER_SOURCE";
  1282. const char smaa_pass_2_vertex_shader[] = R"SHADER_SOURCE(
  1283. varying vec4 offset[3];
  1284. varying vec2 texcoord;
  1285. varying vec2 pixcoord;
  1286. void main()
  1287. {
  1288. texcoord = gl_MultiTexCoord0.st;
  1289. SMAABlendingWeightCalculationVS( texcoord, pixcoord, offset );
  1290. gl_Position = ftransform();
  1291. }
  1292. )SHADER_SOURCE";
  1293. const char smaa_pass_2_fragment_shader[] = R"SHADER_SOURCE(
  1294. varying vec2 texcoord;
  1295. varying vec2 pixcoord;
  1296. varying vec4 offset[3];
  1297. uniform sampler2D edgesTex;
  1298. uniform sampler2D areaTex;
  1299. uniform sampler2D searchTex;
  1300. void main()
  1301. {
  1302. gl_FragColor = SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesTex, areaTex, searchTex, vec4(0.,0.,0.,0.));
  1303. }
  1304. )SHADER_SOURCE";
  1305. const char smaa_pass_3_vertex_shader[] = R"SHADER_SOURCE(
  1306. varying vec4 offset;
  1307. varying vec2 texcoord;
  1308. void main()
  1309. {
  1310. texcoord = gl_MultiTexCoord0.st;
  1311. SMAANeighborhoodBlendingVS( texcoord, offset );
  1312. gl_Position = ftransform();
  1313. }
  1314. )SHADER_SOURCE";
  1315. const char smaa_pass_3_fragment_shader[] = R"SHADER_SOURCE(
  1316. varying vec2 texcoord;
  1317. varying vec4 offset;
  1318. uniform sampler2D colorTex;
  1319. uniform sampler2D blendTex;
  1320. void main()
  1321. {
  1322. gl_FragColor = SMAANeighborhoodBlendingPS(texcoord, offset, colorTex, blendTex);
  1323. }
  1324. )SHADER_SOURCE";
  1325. }
  1326. }