FXAA3_11.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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 "#if (FXAA_QUALITY_PRESET == 10)\n\
  31. #define FXAA_QUALITY_PS 3\n\
  32. #define FXAA_QUALITY_P0 1.5\n\
  33. #define FXAA_QUALITY_P1 3.0\n\
  34. #define FXAA_QUALITY_P2 12.0\n\
  35. #endif\n\
  36. #if (FXAA_QUALITY_PRESET == 11)\n\
  37. #define FXAA_QUALITY_PS 4\n\
  38. #define FXAA_QUALITY_P0 1.0\n\
  39. #define FXAA_QUALITY_P1 1.5\n\
  40. #define FXAA_QUALITY_P2 3.0\n\
  41. #define FXAA_QUALITY_P3 12.0\n\
  42. #endif\n\
  43. #if (FXAA_QUALITY_PRESET == 12)\n\
  44. #define FXAA_QUALITY_PS 5\n\
  45. #define FXAA_QUALITY_P0 1.0\n\
  46. #define FXAA_QUALITY_P1 1.5\n\
  47. #define FXAA_QUALITY_P2 2.0\n\
  48. #define FXAA_QUALITY_P3 4.0\n\
  49. #define FXAA_QUALITY_P4 12.0\n\
  50. #endif\n\
  51. #if (FXAA_QUALITY_PRESET == 13)\n\
  52. #define FXAA_QUALITY_PS 6\n\
  53. #define FXAA_QUALITY_P0 1.0\n\
  54. #define FXAA_QUALITY_P1 1.5\n\
  55. #define FXAA_QUALITY_P2 2.0\n\
  56. #define FXAA_QUALITY_P3 2.0\n\
  57. #define FXAA_QUALITY_P4 4.0\n\
  58. #define FXAA_QUALITY_P5 12.0\n\
  59. #endif\n\
  60. #if (FXAA_QUALITY_PRESET == 14)\n\
  61. #define FXAA_QUALITY_PS 7\n\
  62. #define FXAA_QUALITY_P0 1.0\n\
  63. #define FXAA_QUALITY_P1 1.5\n\
  64. #define FXAA_QUALITY_P2 2.0\n\
  65. #define FXAA_QUALITY_P3 2.0\n\
  66. #define FXAA_QUALITY_P4 2.0\n\
  67. #define FXAA_QUALITY_P5 4.0\n\
  68. #define FXAA_QUALITY_P6 12.0\n\
  69. #endif\n\
  70. #if (FXAA_QUALITY_PRESET == 15)\n\
  71. #define FXAA_QUALITY_PS 8\n\
  72. #define FXAA_QUALITY_P0 1.0\n\
  73. #define FXAA_QUALITY_P1 1.5\n\
  74. #define FXAA_QUALITY_P2 2.0\n\
  75. #define FXAA_QUALITY_P3 2.0\n\
  76. #define FXAA_QUALITY_P4 2.0\n\
  77. #define FXAA_QUALITY_P5 2.0\n\
  78. #define FXAA_QUALITY_P6 4.0\n\
  79. #define FXAA_QUALITY_P7 12.0\n\
  80. #endif\n\
  81. #if (FXAA_QUALITY_PRESET == 20)\n\
  82. #define FXAA_QUALITY_PS 3\n\
  83. #define FXAA_QUALITY_P0 1.5\n\
  84. #define FXAA_QUALITY_P1 2.0\n\
  85. #define FXAA_QUALITY_P2 8.0\n\
  86. #endif\n\
  87. #if (FXAA_QUALITY_PRESET == 21)\n\
  88. #define FXAA_QUALITY_PS 4\n\
  89. #define FXAA_QUALITY_P0 1.0\n\
  90. #define FXAA_QUALITY_P1 1.5\n\
  91. #define FXAA_QUALITY_P2 2.0\n\
  92. #define FXAA_QUALITY_P3 8.0\n\
  93. #endif\n\
  94. #if (FXAA_QUALITY_PRESET == 22)\n\
  95. #define FXAA_QUALITY_PS 5\n\
  96. #define FXAA_QUALITY_P0 1.0\n\
  97. #define FXAA_QUALITY_P1 1.5\n\
  98. #define FXAA_QUALITY_P2 2.0\n\
  99. #define FXAA_QUALITY_P3 2.0\n\
  100. #define FXAA_QUALITY_P4 8.0\n\
  101. #endif\n\
  102. #if (FXAA_QUALITY_PRESET == 23)\n\
  103. #define FXAA_QUALITY_PS 6\n\
  104. #define FXAA_QUALITY_P0 1.0\n\
  105. #define FXAA_QUALITY_P1 1.5\n\
  106. #define FXAA_QUALITY_P2 2.0\n\
  107. #define FXAA_QUALITY_P3 2.0\n\
  108. #define FXAA_QUALITY_P4 2.0\n\
  109. #define FXAA_QUALITY_P5 8.0\n\
  110. #endif\n\
  111. #if (FXAA_QUALITY_PRESET == 24)\n\
  112. #define FXAA_QUALITY_PS 7\n\
  113. #define FXAA_QUALITY_P0 1.0\n\
  114. #define FXAA_QUALITY_P1 1.5\n\
  115. #define FXAA_QUALITY_P2 2.0\n\
  116. #define FXAA_QUALITY_P3 2.0\n\
  117. #define FXAA_QUALITY_P4 2.0\n\
  118. #define FXAA_QUALITY_P5 3.0\n\
  119. #define FXAA_QUALITY_P6 8.0\n\
  120. #endif\n\
  121. #if (FXAA_QUALITY_PRESET == 25)\n\
  122. #define FXAA_QUALITY_PS 8\n\
  123. #define FXAA_QUALITY_P0 1.0\n\
  124. #define FXAA_QUALITY_P1 1.5\n\
  125. #define FXAA_QUALITY_P2 2.0\n\
  126. #define FXAA_QUALITY_P3 2.0\n\
  127. #define FXAA_QUALITY_P4 2.0\n\
  128. #define FXAA_QUALITY_P5 2.0\n\
  129. #define FXAA_QUALITY_P6 4.0\n\
  130. #define FXAA_QUALITY_P7 8.0\n\
  131. #endif\n\
  132. #if (FXAA_QUALITY_PRESET == 26)\n\
  133. #define FXAA_QUALITY_PS 9\n\
  134. #define FXAA_QUALITY_P0 1.0\n\
  135. #define FXAA_QUALITY_P1 1.5\n\
  136. #define FXAA_QUALITY_P2 2.0\n\
  137. #define FXAA_QUALITY_P3 2.0\n\
  138. #define FXAA_QUALITY_P4 2.0\n\
  139. #define FXAA_QUALITY_P5 2.0\n\
  140. #define FXAA_QUALITY_P6 2.0\n\
  141. #define FXAA_QUALITY_P7 4.0\n\
  142. #define FXAA_QUALITY_P8 8.0\n\
  143. #endif\n\
  144. #if (FXAA_QUALITY_PRESET == 27)\n\
  145. #define FXAA_QUALITY_PS 10\n\
  146. #define FXAA_QUALITY_P0 1.0\n\
  147. #define FXAA_QUALITY_P1 1.5\n\
  148. #define FXAA_QUALITY_P2 2.0\n\
  149. #define FXAA_QUALITY_P3 2.0\n\
  150. #define FXAA_QUALITY_P4 2.0\n\
  151. #define FXAA_QUALITY_P5 2.0\n\
  152. #define FXAA_QUALITY_P6 2.0\n\
  153. #define FXAA_QUALITY_P7 2.0\n\
  154. #define FXAA_QUALITY_P8 4.0\n\
  155. #define FXAA_QUALITY_P9 8.0\n\
  156. #endif\n\
  157. #if (FXAA_QUALITY_PRESET == 28)\n\
  158. #define FXAA_QUALITY_PS 11\n\
  159. #define FXAA_QUALITY_P0 1.0\n\
  160. #define FXAA_QUALITY_P1 1.5\n\
  161. #define FXAA_QUALITY_P2 2.0\n\
  162. #define FXAA_QUALITY_P3 2.0\n\
  163. #define FXAA_QUALITY_P4 2.0\n\
  164. #define FXAA_QUALITY_P5 2.0\n\
  165. #define FXAA_QUALITY_P6 2.0\n\
  166. #define FXAA_QUALITY_P7 2.0\n\
  167. #define FXAA_QUALITY_P8 2.0\n\
  168. #define FXAA_QUALITY_P9 4.0\n\
  169. #define FXAA_QUALITY_P10 8.0\n\
  170. #endif\n\
  171. #if (FXAA_QUALITY_PRESET == 29)\n\
  172. #define FXAA_QUALITY_PS 12\n\
  173. #define FXAA_QUALITY_P0 1.0\n\
  174. #define FXAA_QUALITY_P1 1.5\n\
  175. #define FXAA_QUALITY_P2 2.0\n\
  176. #define FXAA_QUALITY_P3 2.0\n\
  177. #define FXAA_QUALITY_P4 2.0\n\
  178. #define FXAA_QUALITY_P5 2.0\n\
  179. #define FXAA_QUALITY_P6 2.0\n\
  180. #define FXAA_QUALITY_P7 2.0\n\
  181. #define FXAA_QUALITY_P8 2.0\n\
  182. #define FXAA_QUALITY_P9 2.0\n\
  183. #define FXAA_QUALITY_P10 4.0\n\
  184. #define FXAA_QUALITY_P11 8.0\n\
  185. #endif\n\
  186. #if (FXAA_QUALITY_PRESET == 39)\n\
  187. #define FXAA_QUALITY_PS 12\n\
  188. #define FXAA_QUALITY_P0 1.0\n\
  189. #define FXAA_QUALITY_P1 1.0\n\
  190. #define FXAA_QUALITY_P2 1.0\n\
  191. #define FXAA_QUALITY_P3 1.0\n\
  192. #define FXAA_QUALITY_P4 1.0\n\
  193. #define FXAA_QUALITY_P5 1.5\n\
  194. #define FXAA_QUALITY_P6 2.0\n\
  195. #define FXAA_QUALITY_P7 2.0\n\
  196. #define FXAA_QUALITY_P8 2.0\n\
  197. #define FXAA_QUALITY_P9 2.0\n\
  198. #define FXAA_QUALITY_P10 4.0\n\
  199. #define FXAA_QUALITY_P11 8.0\n\
  200. #endif\n\
  201. #define FxaaBool bool\n\
  202. #define FxaaFloat float\n\
  203. #define FxaaFloat2 vec2\n\
  204. #define FxaaFloat3 vec3\n\
  205. #define FxaaFloat4 vec4\n\
  206. #define FxaaHalf float\n\
  207. #define FxaaHalf2 vec2\n\
  208. #define FxaaHalf3 vec3\n\
  209. #define FxaaHalf4 vec4\n\
  210. #define FxaaInt2 vec2\n\
  211. #define FxaaTex sampler2D\n\
  212. #define FxaaSat(x) clamp(x, 0.0, 1.0)\n\
  213. #define FxaaTexTop(t, p) texture2D(t, p)\n\
  214. #define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r))\n\
  215. FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.y; }\n\
  216. FxaaFloat4 FxaaPixelShader(\n\
  217. FxaaFloat2 pos,\n\
  218. FxaaTex tex,\n\
  219. FxaaFloat2 fxaaQualityRcpFrame,\n\
  220. FxaaFloat fxaaQualitySubpix,\n\
  221. FxaaFloat fxaaQualityEdgeThreshold,\n\
  222. FxaaFloat fxaaQualityEdgeThresholdMin\n\
  223. ) {\n\
  224. FxaaFloat2 posM;\n\
  225. posM.x = pos.x;\n\
  226. posM.y = pos.y;\n\
  227. FxaaFloat4 rgbyM = FxaaTexTop(tex, posM);\n\
  228. #define lumaM rgbyM.y\n\
  229. FxaaFloat lumaS = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0, 1), fxaaQualityRcpFrame.xy));\n\
  230. FxaaFloat lumaE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 0), fxaaQualityRcpFrame.xy));\n\
  231. FxaaFloat lumaN = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0,-1), fxaaQualityRcpFrame.xy));\n\
  232. FxaaFloat lumaW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 0), fxaaQualityRcpFrame.xy));\n\
  233. FxaaFloat maxSM = max(lumaS, lumaM);\n\
  234. FxaaFloat minSM = min(lumaS, lumaM);\n\
  235. FxaaFloat maxESM = max(lumaE, maxSM);\n\
  236. FxaaFloat minESM = min(lumaE, minSM);\n\
  237. FxaaFloat maxWN = max(lumaN, lumaW);\n\
  238. FxaaFloat minWN = min(lumaN, lumaW);\n\
  239. FxaaFloat rangeMax = max(maxWN, maxESM);\n\
  240. FxaaFloat rangeMin = min(minWN, minESM);\n\
  241. FxaaFloat rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;\n\
  242. FxaaFloat range = rangeMax - rangeMin;\n\
  243. FxaaFloat rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);\n\
  244. FxaaBool earlyExit = range < rangeMaxClamped;\n\
  245. if(earlyExit)\n\
  246. return rgbyM;\n\
  247. FxaaFloat lumaNW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1,-1), fxaaQualityRcpFrame.xy));\n\
  248. FxaaFloat lumaSE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 1), fxaaQualityRcpFrame.xy));\n\
  249. FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1,-1), fxaaQualityRcpFrame.xy));\n\
  250. FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy));\n\
  251. FxaaFloat lumaNS = lumaN + lumaS;\n\
  252. FxaaFloat lumaWE = lumaW + lumaE;\n\
  253. FxaaFloat subpixRcpRange = 1.0/range;\n\
  254. FxaaFloat subpixNSWE = lumaNS + lumaWE;\n\
  255. FxaaFloat edgeHorz1 = (-2.0 * lumaM) + lumaNS;\n\
  256. FxaaFloat edgeVert1 = (-2.0 * lumaM) + lumaWE;\n\
  257. FxaaFloat lumaNESE = lumaNE + lumaSE;\n\
  258. FxaaFloat lumaNWNE = lumaNW + lumaNE;\n\
  259. FxaaFloat edgeHorz2 = (-2.0 * lumaE) + lumaNESE;\n\
  260. FxaaFloat edgeVert2 = (-2.0 * lumaN) + lumaNWNE;\n\
  261. FxaaFloat lumaNWSW = lumaNW + lumaSW;\n\
  262. FxaaFloat lumaSWSE = lumaSW + lumaSE;\n\
  263. FxaaFloat edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);\n\
  264. FxaaFloat edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);\n\
  265. FxaaFloat edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;\n\
  266. FxaaFloat edgeVert3 = (-2.0 * lumaS) + lumaSWSE;\n\
  267. FxaaFloat edgeHorz = abs(edgeHorz3) + edgeHorz4;\n\
  268. FxaaFloat edgeVert = abs(edgeVert3) + edgeVert4;\n\
  269. FxaaFloat subpixNWSWNESE = lumaNWSW + lumaNESE;\n\
  270. FxaaFloat lengthSign = fxaaQualityRcpFrame.x;\n\
  271. FxaaBool horzSpan = edgeHorz >= edgeVert;\n\
  272. FxaaFloat subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;\n\
  273. if(!horzSpan) lumaN = lumaW;\n\
  274. if(!horzSpan) lumaS = lumaE;\n\
  275. if(horzSpan) lengthSign = fxaaQualityRcpFrame.y;\n\
  276. FxaaFloat subpixB = (subpixA * (1.0/12.0)) - lumaM;\n\
  277. FxaaFloat gradientN = lumaN - lumaM;\n\
  278. FxaaFloat gradientS = lumaS - lumaM;\n\
  279. FxaaFloat lumaNN = lumaN + lumaM;\n\
  280. FxaaFloat lumaSS = lumaS + lumaM;\n\
  281. FxaaBool pairN = abs(gradientN) >= abs(gradientS);\n\
  282. FxaaFloat gradient = max(abs(gradientN), abs(gradientS));\n\
  283. if(pairN) lengthSign = -lengthSign;\n\
  284. FxaaFloat subpixC = FxaaSat(abs(subpixB) * subpixRcpRange);\n\
  285. FxaaFloat2 posB;\n\
  286. posB.x = posM.x;\n\
  287. posB.y = posM.y;\n\
  288. FxaaFloat2 offNP;\n\
  289. offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;\n\
  290. offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;\n\
  291. if(!horzSpan) posB.x += lengthSign * 0.5;\n\
  292. if( horzSpan) posB.y += lengthSign * 0.5;\n\
  293. FxaaFloat2 posN;\n\
  294. posN.x = posB.x - offNP.x * FXAA_QUALITY_P0;\n\
  295. posN.y = posB.y - offNP.y * FXAA_QUALITY_P0;\n\
  296. FxaaFloat2 posP;\n\
  297. posP.x = posB.x + offNP.x * FXAA_QUALITY_P0;\n\
  298. posP.y = posB.y + offNP.y * FXAA_QUALITY_P0;\n\
  299. FxaaFloat subpixD = ((-2.0)*subpixC) + 3.0;\n\
  300. FxaaFloat lumaEndN = FxaaLuma(FxaaTexTop(tex, posN));\n\
  301. FxaaFloat subpixE = subpixC * subpixC;\n\
  302. FxaaFloat lumaEndP = FxaaLuma(FxaaTexTop(tex, posP));\n\
  303. if(!pairN) lumaNN = lumaSS;\n\
  304. FxaaFloat gradientScaled = gradient * 1.0/4.0;\n\
  305. FxaaFloat lumaMM = lumaM - lumaNN * 0.5;\n\
  306. FxaaFloat subpixF = subpixD * subpixE;\n\
  307. FxaaBool lumaMLTZero = lumaMM < 0.0;\n\
  308. lumaEndN -= lumaNN * 0.5;\n\
  309. lumaEndP -= lumaNN * 0.5;\n\
  310. FxaaBool doneN = abs(lumaEndN) >= gradientScaled;\n\
  311. FxaaBool doneP = abs(lumaEndP) >= gradientScaled;\n\
  312. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P1;\n\
  313. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P1;\n\
  314. FxaaBool doneNP = (!doneN) || (!doneP);\n\
  315. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P1;\n\
  316. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P1;\n\
  317. if(doneNP) {\n\
  318. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  319. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  320. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  321. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  322. doneN = abs(lumaEndN) >= gradientScaled;\n\
  323. doneP = abs(lumaEndP) >= gradientScaled;\n\
  324. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P2;\n\
  325. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P2;\n\
  326. doneNP = (!doneN) || (!doneP);\n\
  327. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P2;\n\
  328. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P2;\n\
  329. #if (FXAA_QUALITY_PS > 3)\n\
  330. if(doneNP) {\n\
  331. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  332. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  333. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  334. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  335. doneN = abs(lumaEndN) >= gradientScaled;\n\
  336. doneP = abs(lumaEndP) >= gradientScaled;\n\
  337. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P3;\n\
  338. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P3;\n\
  339. doneNP = (!doneN) || (!doneP);\n\
  340. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P3;\n\
  341. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P3;\n\
  342. #if (FXAA_QUALITY_PS > 4)\n\
  343. if(doneNP) {\n\
  344. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  345. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  346. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  347. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  348. doneN = abs(lumaEndN) >= gradientScaled;\n\
  349. doneP = abs(lumaEndP) >= gradientScaled;\n\
  350. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P4;\n\
  351. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P4;\n\
  352. doneNP = (!doneN) || (!doneP);\n\
  353. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P4;\n\
  354. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P4;\n\
  355. #if (FXAA_QUALITY_PS > 5)\n\
  356. if(doneNP) {\n\
  357. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  358. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  359. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  360. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  361. doneN = abs(lumaEndN) >= gradientScaled;\n\
  362. doneP = abs(lumaEndP) >= gradientScaled;\n\
  363. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P5;\n\
  364. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P5;\n\
  365. doneNP = (!doneN) || (!doneP);\n\
  366. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P5;\n\
  367. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P5;\n\
  368. #if (FXAA_QUALITY_PS > 6)\n\
  369. if(doneNP) {\n\
  370. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  371. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  372. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  373. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  374. doneN = abs(lumaEndN) >= gradientScaled;\n\
  375. doneP = abs(lumaEndP) >= gradientScaled;\n\
  376. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P6;\n\
  377. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P6;\n\
  378. doneNP = (!doneN) || (!doneP);\n\
  379. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P6;\n\
  380. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P6;\n\
  381. #if (FXAA_QUALITY_PS > 7)\n\
  382. if(doneNP) {\n\
  383. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  384. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  385. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  386. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  387. doneN = abs(lumaEndN) >= gradientScaled;\n\
  388. doneP = abs(lumaEndP) >= gradientScaled;\n\
  389. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P7;\n\
  390. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P7;\n\
  391. doneNP = (!doneN) || (!doneP);\n\
  392. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P7;\n\
  393. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P7;\n\
  394. #if (FXAA_QUALITY_PS > 8)\n\
  395. if(doneNP) {\n\
  396. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  397. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  398. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  399. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  400. doneN = abs(lumaEndN) >= gradientScaled;\n\
  401. doneP = abs(lumaEndP) >= gradientScaled;\n\
  402. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P8;\n\
  403. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P8;\n\
  404. doneNP = (!doneN) || (!doneP);\n\
  405. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P8;\n\
  406. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P8;\n\
  407. #if (FXAA_QUALITY_PS > 9)\n\
  408. if(doneNP) {\n\
  409. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  410. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  411. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  412. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  413. doneN = abs(lumaEndN) >= gradientScaled;\n\
  414. doneP = abs(lumaEndP) >= gradientScaled;\n\
  415. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P9;\n\
  416. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P9;\n\
  417. doneNP = (!doneN) || (!doneP);\n\
  418. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P9;\n\
  419. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P9;\n\
  420. #if (FXAA_QUALITY_PS > 10)\n\
  421. if(doneNP) {\n\
  422. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  423. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  424. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  425. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  426. doneN = abs(lumaEndN) >= gradientScaled;\n\
  427. doneP = abs(lumaEndP) >= gradientScaled;\n\
  428. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P10;\n\
  429. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P10;\n\
  430. doneNP = (!doneN) || (!doneP);\n\
  431. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P10;\n\
  432. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P10;\n\
  433. #if (FXAA_QUALITY_PS > 11)\n\
  434. if(doneNP) {\n\
  435. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  436. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  437. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  438. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  439. doneN = abs(lumaEndN) >= gradientScaled;\n\
  440. doneP = abs(lumaEndP) >= gradientScaled;\n\
  441. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P11;\n\
  442. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P11;\n\
  443. doneNP = (!doneN) || (!doneP);\n\
  444. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P11;\n\
  445. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P11;\n\
  446. #if (FXAA_QUALITY_PS > 12)\n\
  447. if(doneNP) {\n\
  448. if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));\n\
  449. if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));\n\
  450. if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n\
  451. if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n\
  452. doneN = abs(lumaEndN) >= gradientScaled;\n\
  453. doneP = abs(lumaEndP) >= gradientScaled;\n\
  454. if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P12;\n\
  455. if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P12;\n\
  456. doneNP = (!doneN) || (!doneP);\n\
  457. if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P12;\n\
  458. if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P12;\n\
  459. }\n\
  460. #endif\n\
  461. }\n\
  462. #endif\n\
  463. }\n\
  464. #endif\n\
  465. }\n\
  466. #endif\n\
  467. }\n\
  468. #endif\n\
  469. }\n\
  470. #endif\n\
  471. }\n\
  472. #endif\n\
  473. }\n\
  474. #endif\n\
  475. }\n\
  476. #endif\n\
  477. }\n\
  478. #endif\n\
  479. }\n\
  480. FxaaFloat dstN = posM.x - posN.x;\n\
  481. FxaaFloat dstP = posP.x - posM.x;\n\
  482. if(!horzSpan) dstN = posM.y - posN.y;\n\
  483. if(!horzSpan) dstP = posP.y - posM.y;\n\
  484. FxaaBool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;\n\
  485. FxaaFloat spanLength = (dstP + dstN);\n\
  486. FxaaBool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;\n\
  487. FxaaFloat spanLengthRcp = 1.0/spanLength;\n\
  488. FxaaBool directionN = dstN < dstP;\n\
  489. FxaaFloat dst = min(dstN, dstP);\n\
  490. FxaaBool goodSpan = directionN ? goodSpanN : goodSpanP;\n\
  491. FxaaFloat subpixG = subpixF * subpixF;\n\
  492. FxaaFloat pixelOffset = (dst * (-spanLengthRcp)) + 0.5;\n\
  493. FxaaFloat subpixH = subpixG * fxaaQualitySubpix;\n\
  494. FxaaFloat pixelOffsetGood = goodSpan ? pixelOffset : 0.0;\n\
  495. FxaaFloat pixelOffsetSubpix = max(pixelOffsetGood, subpixH);\n\
  496. if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;\n\
  497. if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;\n\
  498. return FxaaFloat4(FxaaTexTop(tex, posM).xyz, lumaM);\n\
  499. }\n\
  500. ";