FXAA3_11.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /**
  2. * @license
  3. * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * Neither the name of NVIDIA CORPORATION nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  25. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. //This file is automatically rebuilt by the Cesium build process.
  30. export default "/**\n\
  31. * @license\n\
  32. * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.\n\
  33. *\n\
  34. * Redistribution and use in source and binary forms, with or without\n\
  35. * modification, are permitted provided that the following conditions\n\
  36. * are met:\n\
  37. * * Redistributions of source code must retain the above copyright\n\
  38. * notice, this list of conditions and the following disclaimer.\n\
  39. * * Redistributions in binary form must reproduce the above copyright\n\
  40. * notice, this list of conditions and the following disclaimer in the\n\
  41. * documentation and/or other materials provided with the distribution.\n\
  42. * * Neither the name of NVIDIA CORPORATION nor the names of its\n\
  43. * contributors may be used to endorse or promote products derived\n\
  44. * from this software without specific prior written permission.\n\
  45. *\n\
  46. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY\n\
  47. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
  48. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n\
  49. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n\
  50. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n\
  51. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n\
  52. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n\
  53. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n\
  54. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
  55. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
  56. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\
  57. */\n\
  58. \n\
  59. // NVIDIA GameWorks Graphics Samples GitHub link: https://github.com/NVIDIAGameWorks/GraphicsSamples\n\
  60. // Original FXAA 3.11 shader link: https://github.com/NVIDIAGameWorks/GraphicsSamples/blob/master/samples/es3-kepler/FXAA/FXAA3_11.h\n\
  61. \n\
  62. // Steps used to integrate into Cesium:\n\
  63. // * The following defines are set:\n\
  64. // #define FXAA_PC 1\n\
  65. // #define FXAA_WEBGL_1 1\n\
  66. // #define FXAA_GREEN_AS_LUMA 1\n\
  67. // #define FXAA_EARLY_EXIT 1\n\
  68. // #define FXAA_GLSL_120 1\n\
  69. // * All other preprocessor directives besides the FXAA_QUALITY__P* directives were removed.\n\
  70. // * Double underscores are invalid for preprocessor directives so replace them with a single underscore. Replace\n\
  71. // /FXAA_QUALITY__P(.*)/g with /FXAA_QUALITY__P$1/.\n\
  72. // * There are no implicit conversions from ivec* to vec* so replace:\n\
  73. // #define FxaaInt2 ivec2\n\
  74. // with\n\
  75. // #define FxaaInt2 vec2\n\
  76. // * The texture2DLod function is only available in vertex shaders so replace:\n\
  77. // #define FxaaTexTop(t, p) texture2DLod(t, p, 0.0)\n\
  78. // #define FxaaTexOff(t, p, o, r) texture2DLod(t, p + (o * r), 0.0)\n\
  79. // with\n\
  80. // #define FxaaTexTop(t, p) texture2D(t, p)\n\
  81. // #define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r))\n\
  82. // * FXAA_QUALITY_PRESET is prepended in the javascript code. We may want to expose that setting in the future.\n\
  83. // * The following parameters to FxaaPixelShader are unused and can be removed:\n\
  84. // fxaaConsolePosPos\n\
  85. // fxaaConsoleRcpFrameOpt\n\
  86. // fxaaConsoleRcpFrameOpt2\n\
  87. // fxaaConsole360RcpFrameOpt2\n\
  88. // fxaaConsoleEdgeSharpness\n\
  89. // fxaaConsoleEdgeThreshold\n\
  90. // fxaaConsoleEdgeThresholdMi\n\
  91. // fxaaConsole360ConstDir\n\
  92. \n\
  93. //\n\
  94. // Choose the quality preset.\n\
  95. // This needs to be compiled into the shader as it effects code.\n\
  96. // Best option to include multiple presets is to\n\
  97. // in each shader define the preset, then include this file.\n\
  98. //\n\
  99. // OPTIONS\n\
  100. // -----------------------------------------------------------------------\n\
  101. // 10 to 15 - default medium dither (10=fastest, 15=highest quality)\n\
  102. // 20 to 29 - less dither, more expensive (20=fastest, 29=highest quality)\n\
  103. // 39 - no dither, very expensive\n\
  104. //\n\
  105. // NOTES\n\
  106. // -----------------------------------------------------------------------\n\
  107. // 12 = slightly faster then FXAA 3.9 and higher edge quality (default)\n\
  108. // 13 = about same speed as FXAA 3.9 and better than 12\n\
  109. // 23 = closest to FXAA 3.9 visually and performance wise\n\
  110. // _ = the lowest digit is directly related to performance\n\
  111. // _ = the highest digit is directly related to style\n\
  112. //\n\
  113. //#define FXAA_QUALITY_PRESET 12\n\
  114. \n\
  115. \n\
  116. #if (FXAA_QUALITY_PRESET == 10)\n\
  117. #define FXAA_QUALITY_PS 3\n\
  118. #define FXAA_QUALITY_P0 1.5\n\
  119. #define FXAA_QUALITY_P1 3.0\n\
  120. #define FXAA_QUALITY_P2 12.0\n\
  121. #endif\n\
  122. #if (FXAA_QUALITY_PRESET == 11)\n\
  123. #define FXAA_QUALITY_PS 4\n\
  124. #define FXAA_QUALITY_P0 1.0\n\
  125. #define FXAA_QUALITY_P1 1.5\n\
  126. #define FXAA_QUALITY_P2 3.0\n\
  127. #define FXAA_QUALITY_P3 12.0\n\
  128. #endif\n\
  129. #if (FXAA_QUALITY_PRESET == 12)\n\
  130. #define FXAA_QUALITY_PS 5\n\
  131. #define FXAA_QUALITY_P0 1.0\n\
  132. #define FXAA_QUALITY_P1 1.5\n\
  133. #define FXAA_QUALITY_P2 2.0\n\
  134. #define FXAA_QUALITY_P3 4.0\n\
  135. #define FXAA_QUALITY_P4 12.0\n\
  136. #endif\n\
  137. #if (FXAA_QUALITY_PRESET == 13)\n\
  138. #define FXAA_QUALITY_PS 6\n\
  139. #define FXAA_QUALITY_P0 1.0\n\
  140. #define FXAA_QUALITY_P1 1.5\n\
  141. #define FXAA_QUALITY_P2 2.0\n\
  142. #define FXAA_QUALITY_P3 2.0\n\
  143. #define FXAA_QUALITY_P4 4.0\n\
  144. #define FXAA_QUALITY_P5 12.0\n\
  145. #endif\n\
  146. #if (FXAA_QUALITY_PRESET == 14)\n\
  147. #define FXAA_QUALITY_PS 7\n\
  148. #define FXAA_QUALITY_P0 1.0\n\
  149. #define FXAA_QUALITY_P1 1.5\n\
  150. #define FXAA_QUALITY_P2 2.0\n\
  151. #define FXAA_QUALITY_P3 2.0\n\
  152. #define FXAA_QUALITY_P4 2.0\n\
  153. #define FXAA_QUALITY_P5 4.0\n\
  154. #define FXAA_QUALITY_P6 12.0\n\
  155. #endif\n\
  156. #if (FXAA_QUALITY_PRESET == 15)\n\
  157. #define FXAA_QUALITY_PS 8\n\
  158. #define FXAA_QUALITY_P0 1.0\n\
  159. #define FXAA_QUALITY_P1 1.5\n\
  160. #define FXAA_QUALITY_P2 2.0\n\
  161. #define FXAA_QUALITY_P3 2.0\n\
  162. #define FXAA_QUALITY_P4 2.0\n\
  163. #define FXAA_QUALITY_P5 2.0\n\
  164. #define FXAA_QUALITY_P6 4.0\n\
  165. #define FXAA_QUALITY_P7 12.0\n\
  166. #endif\n\
  167. #if (FXAA_QUALITY_PRESET == 20)\n\
  168. #define FXAA_QUALITY_PS 3\n\
  169. #define FXAA_QUALITY_P0 1.5\n\
  170. #define FXAA_QUALITY_P1 2.0\n\
  171. #define FXAA_QUALITY_P2 8.0\n\
  172. #endif\n\
  173. #if (FXAA_QUALITY_PRESET == 21)\n\
  174. #define FXAA_QUALITY_PS 4\n\
  175. #define FXAA_QUALITY_P0 1.0\n\
  176. #define FXAA_QUALITY_P1 1.5\n\
  177. #define FXAA_QUALITY_P2 2.0\n\
  178. #define FXAA_QUALITY_P3 8.0\n\
  179. #endif\n\
  180. #if (FXAA_QUALITY_PRESET == 22)\n\
  181. #define FXAA_QUALITY_PS 5\n\
  182. #define FXAA_QUALITY_P0 1.0\n\
  183. #define FXAA_QUALITY_P1 1.5\n\
  184. #define FXAA_QUALITY_P2 2.0\n\
  185. #define FXAA_QUALITY_P3 2.0\n\
  186. #define FXAA_QUALITY_P4 8.0\n\
  187. #endif\n\
  188. #if (FXAA_QUALITY_PRESET == 23)\n\
  189. #define FXAA_QUALITY_PS 6\n\
  190. #define FXAA_QUALITY_P0 1.0\n\
  191. #define FXAA_QUALITY_P1 1.5\n\
  192. #define FXAA_QUALITY_P2 2.0\n\
  193. #define FXAA_QUALITY_P3 2.0\n\
  194. #define FXAA_QUALITY_P4 2.0\n\
  195. #define FXAA_QUALITY_P5 8.0\n\
  196. #endif\n\
  197. #if (FXAA_QUALITY_PRESET == 24)\n\
  198. #define FXAA_QUALITY_PS 7\n\
  199. #define FXAA_QUALITY_P0 1.0\n\
  200. #define FXAA_QUALITY_P1 1.5\n\
  201. #define FXAA_QUALITY_P2 2.0\n\
  202. #define FXAA_QUALITY_P3 2.0\n\
  203. #define FXAA_QUALITY_P4 2.0\n\
  204. #define FXAA_QUALITY_P5 3.0\n\
  205. #define FXAA_QUALITY_P6 8.0\n\
  206. #endif\n\
  207. #if (FXAA_QUALITY_PRESET == 25)\n\
  208. #define FXAA_QUALITY_PS 8\n\
  209. #define FXAA_QUALITY_P0 1.0\n\
  210. #define FXAA_QUALITY_P1 1.5\n\
  211. #define FXAA_QUALITY_P2 2.0\n\
  212. #define FXAA_QUALITY_P3 2.0\n\
  213. #define FXAA_QUALITY_P4 2.0\n\
  214. #define FXAA_QUALITY_P5 2.0\n\
  215. #define FXAA_QUALITY_P6 4.0\n\
  216. #define FXAA_QUALITY_P7 8.0\n\
  217. #endif\n\
  218. #if (FXAA_QUALITY_PRESET == 26)\n\
  219. #define FXAA_QUALITY_PS 9\n\
  220. #define FXAA_QUALITY_P0 1.0\n\
  221. #define FXAA_QUALITY_P1 1.5\n\
  222. #define FXAA_QUALITY_P2 2.0\n\
  223. #define FXAA_QUALITY_P3 2.0\n\
  224. #define FXAA_QUALITY_P4 2.0\n\
  225. #define FXAA_QUALITY_P5 2.0\n\
  226. #define FXAA_QUALITY_P6 2.0\n\
  227. #define FXAA_QUALITY_P7 4.0\n\
  228. #define FXAA_QUALITY_P8 8.0\n\
  229. #endif\n\
  230. #if (FXAA_QUALITY_PRESET == 27)\n\
  231. #define FXAA_QUALITY_PS 10\n\
  232. #define FXAA_QUALITY_P0 1.0\n\
  233. #define FXAA_QUALITY_P1 1.5\n\
  234. #define FXAA_QUALITY_P2 2.0\n\
  235. #define FXAA_QUALITY_P3 2.0\n\
  236. #define FXAA_QUALITY_P4 2.0\n\
  237. #define FXAA_QUALITY_P5 2.0\n\
  238. #define FXAA_QUALITY_P6 2.0\n\
  239. #define FXAA_QUALITY_P7 2.0\n\
  240. #define FXAA_QUALITY_P8 4.0\n\
  241. #define FXAA_QUALITY_P9 8.0\n\
  242. #endif\n\
  243. #if (FXAA_QUALITY_PRESET == 28)\n\
  244. #define FXAA_QUALITY_PS 11\n\
  245. #define FXAA_QUALITY_P0 1.0\n\
  246. #define FXAA_QUALITY_P1 1.5\n\
  247. #define FXAA_QUALITY_P2 2.0\n\
  248. #define FXAA_QUALITY_P3 2.0\n\
  249. #define FXAA_QUALITY_P4 2.0\n\
  250. #define FXAA_QUALITY_P5 2.0\n\
  251. #define FXAA_QUALITY_P6 2.0\n\
  252. #define FXAA_QUALITY_P7 2.0\n\
  253. #define FXAA_QUALITY_P8 2.0\n\
  254. #define FXAA_QUALITY_P9 4.0\n\
  255. #define FXAA_QUALITY_P10 8.0\n\
  256. #endif\n\
  257. #if (FXAA_QUALITY_PRESET == 29)\n\
  258. #define FXAA_QUALITY_PS 12\n\
  259. #define FXAA_QUALITY_P0 1.0\n\
  260. #define FXAA_QUALITY_P1 1.5\n\
  261. #define FXAA_QUALITY_P2 2.0\n\
  262. #define FXAA_QUALITY_P3 2.0\n\
  263. #define FXAA_QUALITY_P4 2.0\n\
  264. #define FXAA_QUALITY_P5 2.0\n\
  265. #define FXAA_QUALITY_P6 2.0\n\
  266. #define FXAA_QUALITY_P7 2.0\n\
  267. #define FXAA_QUALITY_P8 2.0\n\
  268. #define FXAA_QUALITY_P9 2.0\n\
  269. #define FXAA_QUALITY_P10 4.0\n\
  270. #define FXAA_QUALITY_P11 8.0\n\
  271. #endif\n\
  272. #if (FXAA_QUALITY_PRESET == 39)\n\
  273. #define FXAA_QUALITY_PS 12\n\
  274. #define FXAA_QUALITY_P0 1.0\n\
  275. #define FXAA_QUALITY_P1 1.0\n\
  276. #define FXAA_QUALITY_P2 1.0\n\
  277. #define FXAA_QUALITY_P3 1.0\n\
  278. #define FXAA_QUALITY_P4 1.0\n\
  279. #define FXAA_QUALITY_P5 1.5\n\
  280. #define FXAA_QUALITY_P6 2.0\n\
  281. #define FXAA_QUALITY_P7 2.0\n\
  282. #define FXAA_QUALITY_P8 2.0\n\
  283. #define FXAA_QUALITY_P9 2.0\n\
  284. #define FXAA_QUALITY_P10 4.0\n\
  285. #define FXAA_QUALITY_P11 8.0\n\
  286. #endif\n\
  287. \n\
  288. #define FxaaBool bool\n\
  289. #define FxaaFloat float\n\
  290. #define FxaaFloat2 vec2\n\
  291. #define FxaaFloat3 vec3\n\
  292. #define FxaaFloat4 vec4\n\
  293. #define FxaaHalf float\n\
  294. #define FxaaHalf2 vec2\n\
  295. #define FxaaHalf3 vec3\n\
  296. #define FxaaHalf4 vec4\n\
  297. #define FxaaInt2 vec2\n\
  298. #define FxaaTex sampler2D\n\
  299. \n\
  300. #define FxaaSat(x) clamp(x, 0.0, 1.0)\n\
  301. #define FxaaTexTop(t, p) texture2D(t, p)\n\
  302. #define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r))\n\
  303. \n\
  304. FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.y; }\n\
  305. \n\
  306. FxaaFloat4 FxaaPixelShader(\n\
  307. //\n\
  308. // Use noperspective interpolation here (turn off perspective interpolation).\n\
  309. // {xy} = center of pixel\n\
  310. FxaaFloat2 pos,\n\
  311. //\n\
  312. // Input color texture.\n\
  313. // {rgb_} = color in linear or perceptual color space\n\
  314. // if (FXAA_GREEN_AS_LUMA == 0)\n\
  315. // {___a} = luma in perceptual color space (not linear)\n\
  316. FxaaTex tex,\n\
  317. //\n\
  318. // Only used on FXAA Quality.\n\
  319. // This must be from a constant/uniform.\n\
  320. // {x_} = 1.0/screenWidthInPixels\n\
  321. // {_y} = 1.0/screenHeightInPixels\n\
  322. FxaaFloat2 fxaaQualityRcpFrame,\n\
  323. //\n\
  324. // Only used on FXAA Quality.\n\
  325. // This used to be the FXAA_QUALITY_SUBPIX define.\n\
  326. // It is here now to allow easier tuning.\n\
  327. // Choose the amount of sub-pixel aliasing removal.\n\
  328. // This can effect sharpness.\n\
  329. // 1.00 - upper limit (softer)\n\
  330. // 0.75 - default amount of filtering\n\
  331. // 0.50 - lower limit (sharper, less sub-pixel aliasing removal)\n\
  332. // 0.25 - almost off\n\
  333. // 0.00 - completely off\n\
  334. FxaaFloat fxaaQualitySubpix,\n\
  335. //\n\
  336. // Only used on FXAA Quality.\n\
  337. // This used to be the FXAA_QUALITY_EDGE_THRESHOLD define.\n\
  338. // It is here now to allow easier tuning.\n\
  339. // The minimum amount of local contrast required to apply algorithm.\n\
  340. // 0.333 - too little (faster)\n\
  341. // 0.250 - low quality\n\
  342. // 0.166 - default\n\
  343. // 0.125 - high quality\n\
  344. // 0.063 - overkill (slower)\n\
  345. FxaaFloat fxaaQualityEdgeThreshold,\n\
  346. //\n\
  347. // Only used on FXAA Quality.\n\
  348. // This used to be the FXAA_QUALITY_EDGE_THRESHOLD_MIN define.\n\
  349. // It is here now to allow easier tuning.\n\
  350. // Trims the algorithm from processing darks.\n\
  351. // 0.0833 - upper limit (default, the start of visible unfiltered edges)\n\
  352. // 0.0625 - high quality (faster)\n\
  353. // 0.0312 - visible limit (slower)\n\
  354. // Special notes when using FXAA_GREEN_AS_LUMA,\n\
  355. // Likely want to set this to zero.\n\
  356. // As colors that are mostly not-green\n\
  357. // will appear very dark in the green channel!\n\
  358. // Tune by looking at mostly non-green content,\n\
  359. // then start at zero and increase until aliasing is a problem.\n\
  360. FxaaFloat fxaaQualityEdgeThresholdMin\n\
  361. ) {\n\
  362. /*--------------------------------------------------------------------------*/\n\
  363. FxaaFloat2 posM;\n\
  364. posM.x = pos.x;\n\
  365. posM.y = pos.y;\n\
  366. FxaaFloat4 rgbyM = FxaaTexTop(tex, posM);\n\
  367. #define lumaM rgbyM.y\n\
  368. FxaaFloat lumaS = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0, 1), fxaaQualityRcpFrame.xy));\n\
  369. FxaaFloat lumaE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 0), fxaaQualityRcpFrame.xy));\n\
  370. FxaaFloat lumaN = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0,-1), fxaaQualityRcpFrame.xy));\n\
  371. FxaaFloat lumaW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 0), fxaaQualityRcpFrame.xy));\n\
  372. /*--------------------------------------------------------------------------*/\n\
  373. FxaaFloat maxSM = max(lumaS, lumaM);\n\
  374. FxaaFloat minSM = min(lumaS, lumaM);\n\
  375. FxaaFloat maxESM = max(lumaE, maxSM);\n\
  376. FxaaFloat minESM = min(lumaE, minSM);\n\
  377. FxaaFloat maxWN = max(lumaN, lumaW);\n\
  378. FxaaFloat minWN = min(lumaN, lumaW);\n\
  379. FxaaFloat rangeMax = max(maxWN, maxESM);\n\
  380. FxaaFloat rangeMin = min(minWN, minESM);\n\
  381. FxaaFloat rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;\n\
  382. FxaaFloat range = rangeMax - rangeMin;\n\
  383. FxaaFloat rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);\n\
  384. FxaaBool earlyExit = range < rangeMaxClamped;\n\
  385. /*--------------------------------------------------------------------------*/\n\
  386. if(earlyExit)\n\
  387. return rgbyM;\n\
  388. /*--------------------------------------------------------------------------*/\n\
  389. FxaaFloat lumaNW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1,-1), fxaaQualityRcpFrame.xy));\n\
  390. FxaaFloat lumaSE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 1), fxaaQualityRcpFrame.xy));\n\
  391. FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1,-1), fxaaQualityRcpFrame.xy));\n\
  392. FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy));\n\
  393. /*--------------------------------------------------------------------------*/\n\
  394. FxaaFloat lumaNS = lumaN + lumaS;\n\
  395. FxaaFloat lumaWE = lumaW + lumaE;\n\
  396. FxaaFloat subpixRcpRange = 1.0/range;\n\
  397. FxaaFloat subpixNSWE = lumaNS + lumaWE;\n\
  398. FxaaFloat edgeHorz1 = (-2.0 * lumaM) + lumaNS;\n\
  399. FxaaFloat edgeVert1 = (-2.0 * lumaM) + lumaWE;\n\
  400. /*--------------------------------------------------------------------------*/\n\
  401. FxaaFloat lumaNESE = lumaNE + lumaSE;\n\
  402. FxaaFloat lumaNWNE = lumaNW + lumaNE;\n\
  403. FxaaFloat edgeHorz2 = (-2.0 * lumaE) + lumaNESE;\n\
  404. FxaaFloat edgeVert2 = (-2.0 * lumaN) + lumaNWNE;\n\
  405. /*--------------------------------------------------------------------------*/\n\
  406. FxaaFloat lumaNWSW = lumaNW + lumaSW;\n\
  407. FxaaFloat lumaSWSE = lumaSW + lumaSE;\n\
  408. FxaaFloat edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);\n\
  409. FxaaFloat edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);\n\
  410. FxaaFloat edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;\n\
  411. FxaaFloat edgeVert3 = (-2.0 * lumaS) + lumaSWSE;\n\
  412. FxaaFloat edgeHorz = abs(edgeHorz3) + edgeHorz4;\n\
  413. FxaaFloat edgeVert = abs(edgeVert3) + edgeVert4;\n\
  414. /*--------------------------------------------------------------------------*/\n\
  415. FxaaFloat subpixNWSWNESE = lumaNWSW + lumaNESE;\n\
  416. FxaaFloat lengthSign = fxaaQualityRcpFrame.x;\n\
  417. FxaaBool horzSpan = edgeHorz >= edgeVert;\n\
  418. FxaaFloat subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;\n\
  419. /*--------------------------------------------------------------------------*/\n\
  420. if(!horzSpan) lumaN = lumaW;\n\
  421. if(!horzSpan) lumaS = lumaE;\n\
  422. if(horzSpan) lengthSign = fxaaQualityRcpFrame.y;\n\
  423. FxaaFloat subpixB = (subpixA * (1.0/12.0)) - lumaM;\n\
  424. /*--------------------------------------------------------------------------*/\n\
  425. FxaaFloat gradientN = lumaN - lumaM;\n\
  426. FxaaFloat gradientS = lumaS - lumaM;\n\
  427. FxaaFloat lumaNN = lumaN + lumaM;\n\
  428. FxaaFloat lumaSS = lumaS + lumaM;\n\
  429. FxaaBool pairN = abs(gradientN) >= abs(gradientS);\n\
  430. FxaaFloat gradient = max(abs(gradientN), abs(gradientS));\n\
  431. if(pairN) lengthSign = -lengthSign;\n\
  432. FxaaFloat subpixC = FxaaSat(abs(subpixB) * subpixRcpRange);\n\
  433. /*--------------------------------------------------------------------------*/\n\
  434. FxaaFloat2 posB;\n\
  435. posB.x = posM.x;\n\
  436. posB.y = posM.y;\n\
  437. FxaaFloat2 offNP;\n\
  438. offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;\n\
  439. offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;\n\
  440. if(!horzSpan) posB.x += lengthSign * 0.5;\n\
  441. if( horzSpan) posB.y += lengthSign * 0.5;\n\
  442. /*--------------------------------------------------------------------------*/\n\
  443. FxaaFloat2 posN;\n\
  444. posN.x = posB.x - offNP.x * FXAA_QUALITY_P0;\n\
  445. posN.y = posB.y - offNP.y * FXAA_QUALITY_P0;\n\
  446. FxaaFloat2 posP;\n\
  447. posP.x = posB.x + offNP.x * FXAA_QUALITY_P0;\n\
  448. posP.y = posB.y + offNP.y * FXAA_QUALITY_P0;\n\
  449. FxaaFloat subpixD = ((-2.0)*subpixC) + 3.0;\n\
  450. FxaaFloat lumaEndN = FxaaLuma(FxaaTexTop(tex, posN));\n\
  451. FxaaFloat subpixE = subpixC * subpixC;\n\
  452. FxaaFloat lumaEndP = FxaaLuma(FxaaTexTop(tex, posP));\n\
  453. /*--------------------------------------------------------------------------*/\n\
  454. if(!pairN) lumaNN = lumaSS;\n\
  455. FxaaFloat gradientScaled = gradient * 1.0/4.0;\n\
  456. FxaaFloat lumaMM = lumaM - lumaNN * 0.5;\n\
  457. FxaaFloat subpixF = subpixD * subpixE;\n\
  458. FxaaBool lumaMLTZero = lumaMM < 0.0;\n\
  459. /*--------------------------------------------------------------------------*/\n\
  460. lumaEndN -= lumaNN * 0.5;\n\
  461. lumaEndP -= lumaNN * 0.5;\n\
  462. FxaaBool doneN = abs(lumaEndN) >= gradientScaled;\n\
  463. FxaaBool doneP = abs(lumaEndP) >= gradientScaled;\n\
  464. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P1;\n\
  465. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P1;\n\
  466. FxaaBool doneNP = (!doneN) || (!doneP);\n\
  467. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P1;\n\
  468. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P1;\n\
  469. /*--------------------------------------------------------------------------*/\n\
  470. if(doneNP) {\n\
  471. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  472. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  473. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  474. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  475. doneN = abs(lumaEndN) >= gradientScaled;\n\
  476. doneP = abs(lumaEndP) >= gradientScaled;\n\
  477. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P2;\n\
  478. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P2;\n\
  479. doneNP = (!doneN) || (!doneP);\n\
  480. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P2;\n\
  481. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P2;\n\
  482. /*--------------------------------------------------------------------------*/\n\
  483. #if (FXAA_QUALITY_PS > 3)\n\
  484. if(doneNP) {\n\
  485. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  486. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  487. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  488. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  489. doneN = abs(lumaEndN) >= gradientScaled;\n\
  490. doneP = abs(lumaEndP) >= gradientScaled;\n\
  491. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P3;\n\
  492. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P3;\n\
  493. doneNP = (!doneN) || (!doneP);\n\
  494. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P3;\n\
  495. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P3;\n\
  496. /*--------------------------------------------------------------------------*/\n\
  497. #if (FXAA_QUALITY_PS > 4)\n\
  498. if(doneNP) {\n\
  499. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  500. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  501. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  502. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  503. doneN = abs(lumaEndN) >= gradientScaled;\n\
  504. doneP = abs(lumaEndP) >= gradientScaled;\n\
  505. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P4;\n\
  506. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P4;\n\
  507. doneNP = (!doneN) || (!doneP);\n\
  508. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P4;\n\
  509. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P4;\n\
  510. /*--------------------------------------------------------------------------*/\n\
  511. #if (FXAA_QUALITY_PS > 5)\n\
  512. if(doneNP) {\n\
  513. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  514. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  515. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  516. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  517. doneN = abs(lumaEndN) >= gradientScaled;\n\
  518. doneP = abs(lumaEndP) >= gradientScaled;\n\
  519. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P5;\n\
  520. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P5;\n\
  521. doneNP = (!doneN) || (!doneP);\n\
  522. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P5;\n\
  523. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P5;\n\
  524. /*--------------------------------------------------------------------------*/\n\
  525. #if (FXAA_QUALITY_PS > 6)\n\
  526. if(doneNP) {\n\
  527. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  528. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  529. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  530. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  531. doneN = abs(lumaEndN) >= gradientScaled;\n\
  532. doneP = abs(lumaEndP) >= gradientScaled;\n\
  533. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P6;\n\
  534. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P6;\n\
  535. doneNP = (!doneN) || (!doneP);\n\
  536. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P6;\n\
  537. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P6;\n\
  538. /*--------------------------------------------------------------------------*/\n\
  539. #if (FXAA_QUALITY_PS > 7)\n\
  540. if(doneNP) {\n\
  541. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  542. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  543. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  544. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  545. doneN = abs(lumaEndN) >= gradientScaled;\n\
  546. doneP = abs(lumaEndP) >= gradientScaled;\n\
  547. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P7;\n\
  548. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P7;\n\
  549. doneNP = (!doneN) || (!doneP);\n\
  550. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P7;\n\
  551. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P7;\n\
  552. /*--------------------------------------------------------------------------*/\n\
  553. #if (FXAA_QUALITY_PS > 8)\n\
  554. if(doneNP) {\n\
  555. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  556. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  557. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  558. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  559. doneN = abs(lumaEndN) >= gradientScaled;\n\
  560. doneP = abs(lumaEndP) >= gradientScaled;\n\
  561. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P8;\n\
  562. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P8;\n\
  563. doneNP = (!doneN) || (!doneP);\n\
  564. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P8;\n\
  565. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P8;\n\
  566. /*--------------------------------------------------------------------------*/\n\
  567. #if (FXAA_QUALITY_PS > 9)\n\
  568. if(doneNP) {\n\
  569. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  570. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  571. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  572. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  573. doneN = abs(lumaEndN) >= gradientScaled;\n\
  574. doneP = abs(lumaEndP) >= gradientScaled;\n\
  575. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P9;\n\
  576. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P9;\n\
  577. doneNP = (!doneN) || (!doneP);\n\
  578. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P9;\n\
  579. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P9;\n\
  580. /*--------------------------------------------------------------------------*/\n\
  581. #if (FXAA_QUALITY_PS > 10)\n\
  582. if(doneNP) {\n\
  583. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  584. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  585. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  586. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  587. doneN = abs(lumaEndN) >= gradientScaled;\n\
  588. doneP = abs(lumaEndP) >= gradientScaled;\n\
  589. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P10;\n\
  590. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P10;\n\
  591. doneNP = (!doneN) || (!doneP);\n\
  592. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P10;\n\
  593. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P10;\n\
  594. /*--------------------------------------------------------------------------*/\n\
  595. #if (FXAA_QUALITY_PS > 11)\n\
  596. if(doneNP) {\n\
  597. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  598. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  599. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  600. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  601. doneN = abs(lumaEndN) >= gradientScaled;\n\
  602. doneP = abs(lumaEndP) >= gradientScaled;\n\
  603. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P11;\n\
  604. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P11;\n\
  605. doneNP = (!doneN) || (!doneP);\n\
  606. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P11;\n\
  607. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P11;\n\
  608. /*--------------------------------------------------------------------------*/\n\
  609. #if (FXAA_QUALITY_PS > 12)\n\
  610. if(doneNP) {\n\
  611. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  612. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  613. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  614. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  615. doneN = abs(lumaEndN) >= gradientScaled;\n\
  616. doneP = abs(lumaEndP) >= gradientScaled;\n\
  617. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P12;\n\
  618. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P12;\n\
  619. doneNP = (!doneN) || (!doneP);\n\
  620. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P12;\n\
  621. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P12;\n\
  622. /*--------------------------------------------------------------------------*/\n\
  623. }\n\
  624. #endif\n\
  625. /*--------------------------------------------------------------------------*/\n\
  626. }\n\
  627. #endif\n\
  628. /*--------------------------------------------------------------------------*/\n\
  629. }\n\
  630. #endif\n\
  631. /*--------------------------------------------------------------------------*/\n\
  632. }\n\
  633. #endif\n\
  634. /*--------------------------------------------------------------------------*/\n\
  635. }\n\
  636. #endif\n\
  637. /*--------------------------------------------------------------------------*/\n\
  638. }\n\
  639. #endif\n\
  640. /*--------------------------------------------------------------------------*/\n\
  641. }\n\
  642. #endif\n\
  643. /*--------------------------------------------------------------------------*/\n\
  644. }\n\
  645. #endif\n\
  646. /*--------------------------------------------------------------------------*/\n\
  647. }\n\
  648. #endif\n\
  649. /*--------------------------------------------------------------------------*/\n\
  650. }\n\
  651. #endif\n\
  652. /*--------------------------------------------------------------------------*/\n\
  653. }\n\
  654. /*--------------------------------------------------------------------------*/\n\
  655. FxaaFloat dstN = posM.x - posN.x;\n\
  656. FxaaFloat dstP = posP.x - posM.x;\n\
  657. if(!horzSpan) dstN = posM.y - posN.y;\n\
  658. if(!horzSpan) dstP = posP.y - posM.y;\n\
  659. /*--------------------------------------------------------------------------*/\n\
  660. FxaaBool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;\n\
  661. FxaaFloat spanLength = (dstP + dstN);\n\
  662. FxaaBool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;\n\
  663. FxaaFloat spanLengthRcp = 1.0/spanLength;\n\
  664. /*--------------------------------------------------------------------------*/\n\
  665. FxaaBool directionN = dstN < dstP;\n\
  666. FxaaFloat dst = min(dstN, dstP);\n\
  667. FxaaBool goodSpan = directionN ? goodSpanN : goodSpanP;\n\
  668. FxaaFloat subpixG = subpixF * subpixF;\n\
  669. FxaaFloat pixelOffset = (dst * (-spanLengthRcp)) + 0.5;\n\
  670. FxaaFloat subpixH = subpixG * fxaaQualitySubpix;\n\
  671. /*--------------------------------------------------------------------------*/\n\
  672. FxaaFloat pixelOffsetGood = goodSpan ? pixelOffset : 0.0;\n\
  673. FxaaFloat pixelOffsetSubpix = max(pixelOffsetGood, subpixH);\n\
  674. if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;\n\
  675. if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;\n\
  676. return FxaaFloat4(FxaaTexTop(tex, posM).xyz, lumaM);\n\
  677. }\n\
  678. ";