FXAAShader.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. console.warn( "THREE.FXAAShader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author alteredq / http://alteredqualia.com/
  4. * @author davidedc / http://www.sketchpatch.net/
  5. *
  6. * NVIDIA FXAA by Timothy Lottes
  7. * http://timothylottes.blogspot.com/2011/06/fxaa3-source-released.html
  8. * - WebGL port by @supereggbert
  9. * http://www.glge.org/demos/fxaa/
  10. */
  11. THREE.FXAAShader = {
  12. uniforms: {
  13. "tDiffuse": { value: null },
  14. "resolution": { value: new THREE.Vector2( 1 / 1024, 1 / 512 ) }
  15. },
  16. vertexShader: [
  17. "varying vec2 vUv;",
  18. "void main() {",
  19. " vUv = uv;",
  20. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  21. "}"
  22. ].join( "\n" ),
  23. fragmentShader: [
  24. "precision highp float;",
  25. "",
  26. "uniform sampler2D tDiffuse;",
  27. "",
  28. "uniform vec2 resolution;",
  29. "",
  30. "varying vec2 vUv;",
  31. "",
  32. "// FXAA 3.11 implementation by NVIDIA, ported to WebGL by Agost Biro ([email protected])",
  33. "",
  34. "//----------------------------------------------------------------------------------",
  35. "// File: es3-kepler\FXAA\assets\shaders/FXAA_DefaultES.frag",
  36. "// SDK Version: v3.00",
  37. "// Email: [email protected]",
  38. "// Site: http://developer.nvidia.com/",
  39. "//",
  40. "// Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.",
  41. "//",
  42. "// Redistribution and use in source and binary forms, with or without",
  43. "// modification, are permitted provided that the following conditions",
  44. "// are met:",
  45. "// * Redistributions of source code must retain the above copyright",
  46. "// notice, this list of conditions and the following disclaimer.",
  47. "// * Redistributions in binary form must reproduce the above copyright",
  48. "// notice, this list of conditions and the following disclaimer in the",
  49. "// documentation and/or other materials provided with the distribution.",
  50. "// * Neither the name of NVIDIA CORPORATION nor the names of its",
  51. "// contributors may be used to endorse or promote products derived",
  52. "// from this software without specific prior written permission.",
  53. "//",
  54. "// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY",
  55. "// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE",
  56. "// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR",
  57. "// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR",
  58. "// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,",
  59. "// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,",
  60. "// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR",
  61. "// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY",
  62. "// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT",
  63. "// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE",
  64. "// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
  65. "//",
  66. "//----------------------------------------------------------------------------------",
  67. "",
  68. "#define FXAA_PC 1",
  69. "#define FXAA_GLSL_100 1",
  70. "#define FXAA_QUALITY_PRESET 12",
  71. "",
  72. "#define FXAA_GREEN_AS_LUMA 1",
  73. "",
  74. "/*--------------------------------------------------------------------------*/",
  75. "#ifndef FXAA_PC_CONSOLE",
  76. " //",
  77. " // The console algorithm for PC is included",
  78. " // for developers targeting really low spec machines.",
  79. " // Likely better to just run FXAA_PC, and use a really low preset.",
  80. " //",
  81. " #define FXAA_PC_CONSOLE 0",
  82. "#endif",
  83. "/*--------------------------------------------------------------------------*/",
  84. "#ifndef FXAA_GLSL_120",
  85. " #define FXAA_GLSL_120 0",
  86. "#endif",
  87. "/*--------------------------------------------------------------------------*/",
  88. "#ifndef FXAA_GLSL_130",
  89. " #define FXAA_GLSL_130 0",
  90. "#endif",
  91. "/*--------------------------------------------------------------------------*/",
  92. "#ifndef FXAA_HLSL_3",
  93. " #define FXAA_HLSL_3 0",
  94. "#endif",
  95. "/*--------------------------------------------------------------------------*/",
  96. "#ifndef FXAA_HLSL_4",
  97. " #define FXAA_HLSL_4 0",
  98. "#endif",
  99. "/*--------------------------------------------------------------------------*/",
  100. "#ifndef FXAA_HLSL_5",
  101. " #define FXAA_HLSL_5 0",
  102. "#endif",
  103. "/*==========================================================================*/",
  104. "#ifndef FXAA_GREEN_AS_LUMA",
  105. " //",
  106. " // For those using non-linear color,",
  107. " // and either not able to get luma in alpha, or not wanting to,",
  108. " // this enables FXAA to run using green as a proxy for luma.",
  109. " // So with this enabled, no need to pack luma in alpha.",
  110. " //",
  111. " // This will turn off AA on anything which lacks some amount of green.",
  112. " // Pure red and blue or combination of only R and B, will get no AA.",
  113. " //",
  114. " // Might want to lower the settings for both,",
  115. " // fxaaConsoleEdgeThresholdMin",
  116. " // fxaaQualityEdgeThresholdMin",
  117. " // In order to insure AA does not get turned off on colors",
  118. " // which contain a minor amount of green.",
  119. " //",
  120. " // 1 = On.",
  121. " // 0 = Off.",
  122. " //",
  123. " #define FXAA_GREEN_AS_LUMA 0",
  124. "#endif",
  125. "/*--------------------------------------------------------------------------*/",
  126. "#ifndef FXAA_EARLY_EXIT",
  127. " //",
  128. " // Controls algorithm's early exit path.",
  129. " // On PS3 turning this ON adds 2 cycles to the shader.",
  130. " // On 360 turning this OFF adds 10ths of a millisecond to the shader.",
  131. " // Turning this off on console will result in a more blurry image.",
  132. " // So this defaults to on.",
  133. " //",
  134. " // 1 = On.",
  135. " // 0 = Off.",
  136. " //",
  137. " #define FXAA_EARLY_EXIT 1",
  138. "#endif",
  139. "/*--------------------------------------------------------------------------*/",
  140. "#ifndef FXAA_DISCARD",
  141. " //",
  142. " // Only valid for PC OpenGL currently.",
  143. " // Probably will not work when FXAA_GREEN_AS_LUMA = 1.",
  144. " //",
  145. " // 1 = Use discard on pixels which don't need AA.",
  146. " // For APIs which enable concurrent TEX+ROP from same surface.",
  147. " // 0 = Return unchanged color on pixels which don't need AA.",
  148. " //",
  149. " #define FXAA_DISCARD 0",
  150. "#endif",
  151. "/*--------------------------------------------------------------------------*/",
  152. "#ifndef FXAA_FAST_PIXEL_OFFSET",
  153. " //",
  154. " // Used for GLSL 120 only.",
  155. " //",
  156. " // 1 = GL API supports fast pixel offsets",
  157. " // 0 = do not use fast pixel offsets",
  158. " //",
  159. " #ifdef GL_EXT_gpu_shader4",
  160. " #define FXAA_FAST_PIXEL_OFFSET 1",
  161. " #endif",
  162. " #ifdef GL_NV_gpu_shader5",
  163. " #define FXAA_FAST_PIXEL_OFFSET 1",
  164. " #endif",
  165. " #ifdef GL_ARB_gpu_shader5",
  166. " #define FXAA_FAST_PIXEL_OFFSET 1",
  167. " #endif",
  168. " #ifndef FXAA_FAST_PIXEL_OFFSET",
  169. " #define FXAA_FAST_PIXEL_OFFSET 0",
  170. " #endif",
  171. "#endif",
  172. "/*--------------------------------------------------------------------------*/",
  173. "#ifndef FXAA_GATHER4_ALPHA",
  174. " //",
  175. " // 1 = API supports gather4 on alpha channel.",
  176. " // 0 = API does not support gather4 on alpha channel.",
  177. " //",
  178. " #if (FXAA_HLSL_5 == 1)",
  179. " #define FXAA_GATHER4_ALPHA 1",
  180. " #endif",
  181. " #ifdef GL_ARB_gpu_shader5",
  182. " #define FXAA_GATHER4_ALPHA 1",
  183. " #endif",
  184. " #ifdef GL_NV_gpu_shader5",
  185. " #define FXAA_GATHER4_ALPHA 1",
  186. " #endif",
  187. " #ifndef FXAA_GATHER4_ALPHA",
  188. " #define FXAA_GATHER4_ALPHA 0",
  189. " #endif",
  190. "#endif",
  191. "",
  192. "",
  193. "/*============================================================================",
  194. " FXAA QUALITY - TUNING KNOBS",
  195. "------------------------------------------------------------------------------",
  196. "NOTE the other tuning knobs are now in the shader function inputs!",
  197. "============================================================================*/",
  198. "#ifndef FXAA_QUALITY_PRESET",
  199. " //",
  200. " // Choose the quality preset.",
  201. " // This needs to be compiled into the shader as it effects code.",
  202. " // Best option to include multiple presets is to",
  203. " // in each shader define the preset, then include this file.",
  204. " //",
  205. " // OPTIONS",
  206. " // -----------------------------------------------------------------------",
  207. " // 10 to 15 - default medium dither (10=fastest, 15=highest quality)",
  208. " // 20 to 29 - less dither, more expensive (20=fastest, 29=highest quality)",
  209. " // 39 - no dither, very expensive",
  210. " //",
  211. " // NOTES",
  212. " // -----------------------------------------------------------------------",
  213. " // 12 = slightly faster then FXAA 3.9 and higher edge quality (default)",
  214. " // 13 = about same speed as FXAA 3.9 and better than 12",
  215. " // 23 = closest to FXAA 3.9 visually and performance wise",
  216. " // _ = the lowest digit is directly related to performance",
  217. " // _ = the highest digit is directly related to style",
  218. " //",
  219. " #define FXAA_QUALITY_PRESET 12",
  220. "#endif",
  221. "",
  222. "",
  223. "/*============================================================================",
  224. "",
  225. " FXAA QUALITY - PRESETS",
  226. "",
  227. "============================================================================*/",
  228. "",
  229. "/*============================================================================",
  230. " FXAA QUALITY - MEDIUM DITHER PRESETS",
  231. "============================================================================*/",
  232. "#if (FXAA_QUALITY_PRESET == 10)",
  233. " #define FXAA_QUALITY_PS 3",
  234. " #define FXAA_QUALITY_P0 1.5",
  235. " #define FXAA_QUALITY_P1 3.0",
  236. " #define FXAA_QUALITY_P2 12.0",
  237. "#endif",
  238. "/*--------------------------------------------------------------------------*/",
  239. "#if (FXAA_QUALITY_PRESET == 11)",
  240. " #define FXAA_QUALITY_PS 4",
  241. " #define FXAA_QUALITY_P0 1.0",
  242. " #define FXAA_QUALITY_P1 1.5",
  243. " #define FXAA_QUALITY_P2 3.0",
  244. " #define FXAA_QUALITY_P3 12.0",
  245. "#endif",
  246. "/*--------------------------------------------------------------------------*/",
  247. "#if (FXAA_QUALITY_PRESET == 12)",
  248. " #define FXAA_QUALITY_PS 5",
  249. " #define FXAA_QUALITY_P0 1.0",
  250. " #define FXAA_QUALITY_P1 1.5",
  251. " #define FXAA_QUALITY_P2 2.0",
  252. " #define FXAA_QUALITY_P3 4.0",
  253. " #define FXAA_QUALITY_P4 12.0",
  254. "#endif",
  255. "/*--------------------------------------------------------------------------*/",
  256. "#if (FXAA_QUALITY_PRESET == 13)",
  257. " #define FXAA_QUALITY_PS 6",
  258. " #define FXAA_QUALITY_P0 1.0",
  259. " #define FXAA_QUALITY_P1 1.5",
  260. " #define FXAA_QUALITY_P2 2.0",
  261. " #define FXAA_QUALITY_P3 2.0",
  262. " #define FXAA_QUALITY_P4 4.0",
  263. " #define FXAA_QUALITY_P5 12.0",
  264. "#endif",
  265. "/*--------------------------------------------------------------------------*/",
  266. "#if (FXAA_QUALITY_PRESET == 14)",
  267. " #define FXAA_QUALITY_PS 7",
  268. " #define FXAA_QUALITY_P0 1.0",
  269. " #define FXAA_QUALITY_P1 1.5",
  270. " #define FXAA_QUALITY_P2 2.0",
  271. " #define FXAA_QUALITY_P3 2.0",
  272. " #define FXAA_QUALITY_P4 2.0",
  273. " #define FXAA_QUALITY_P5 4.0",
  274. " #define FXAA_QUALITY_P6 12.0",
  275. "#endif",
  276. "/*--------------------------------------------------------------------------*/",
  277. "#if (FXAA_QUALITY_PRESET == 15)",
  278. " #define FXAA_QUALITY_PS 8",
  279. " #define FXAA_QUALITY_P0 1.0",
  280. " #define FXAA_QUALITY_P1 1.5",
  281. " #define FXAA_QUALITY_P2 2.0",
  282. " #define FXAA_QUALITY_P3 2.0",
  283. " #define FXAA_QUALITY_P4 2.0",
  284. " #define FXAA_QUALITY_P5 2.0",
  285. " #define FXAA_QUALITY_P6 4.0",
  286. " #define FXAA_QUALITY_P7 12.0",
  287. "#endif",
  288. "",
  289. "/*============================================================================",
  290. " FXAA QUALITY - LOW DITHER PRESETS",
  291. "============================================================================*/",
  292. "#if (FXAA_QUALITY_PRESET == 20)",
  293. " #define FXAA_QUALITY_PS 3",
  294. " #define FXAA_QUALITY_P0 1.5",
  295. " #define FXAA_QUALITY_P1 2.0",
  296. " #define FXAA_QUALITY_P2 8.0",
  297. "#endif",
  298. "/*--------------------------------------------------------------------------*/",
  299. "#if (FXAA_QUALITY_PRESET == 21)",
  300. " #define FXAA_QUALITY_PS 4",
  301. " #define FXAA_QUALITY_P0 1.0",
  302. " #define FXAA_QUALITY_P1 1.5",
  303. " #define FXAA_QUALITY_P2 2.0",
  304. " #define FXAA_QUALITY_P3 8.0",
  305. "#endif",
  306. "/*--------------------------------------------------------------------------*/",
  307. "#if (FXAA_QUALITY_PRESET == 22)",
  308. " #define FXAA_QUALITY_PS 5",
  309. " #define FXAA_QUALITY_P0 1.0",
  310. " #define FXAA_QUALITY_P1 1.5",
  311. " #define FXAA_QUALITY_P2 2.0",
  312. " #define FXAA_QUALITY_P3 2.0",
  313. " #define FXAA_QUALITY_P4 8.0",
  314. "#endif",
  315. "/*--------------------------------------------------------------------------*/",
  316. "#if (FXAA_QUALITY_PRESET == 23)",
  317. " #define FXAA_QUALITY_PS 6",
  318. " #define FXAA_QUALITY_P0 1.0",
  319. " #define FXAA_QUALITY_P1 1.5",
  320. " #define FXAA_QUALITY_P2 2.0",
  321. " #define FXAA_QUALITY_P3 2.0",
  322. " #define FXAA_QUALITY_P4 2.0",
  323. " #define FXAA_QUALITY_P5 8.0",
  324. "#endif",
  325. "/*--------------------------------------------------------------------------*/",
  326. "#if (FXAA_QUALITY_PRESET == 24)",
  327. " #define FXAA_QUALITY_PS 7",
  328. " #define FXAA_QUALITY_P0 1.0",
  329. " #define FXAA_QUALITY_P1 1.5",
  330. " #define FXAA_QUALITY_P2 2.0",
  331. " #define FXAA_QUALITY_P3 2.0",
  332. " #define FXAA_QUALITY_P4 2.0",
  333. " #define FXAA_QUALITY_P5 3.0",
  334. " #define FXAA_QUALITY_P6 8.0",
  335. "#endif",
  336. "/*--------------------------------------------------------------------------*/",
  337. "#if (FXAA_QUALITY_PRESET == 25)",
  338. " #define FXAA_QUALITY_PS 8",
  339. " #define FXAA_QUALITY_P0 1.0",
  340. " #define FXAA_QUALITY_P1 1.5",
  341. " #define FXAA_QUALITY_P2 2.0",
  342. " #define FXAA_QUALITY_P3 2.0",
  343. " #define FXAA_QUALITY_P4 2.0",
  344. " #define FXAA_QUALITY_P5 2.0",
  345. " #define FXAA_QUALITY_P6 4.0",
  346. " #define FXAA_QUALITY_P7 8.0",
  347. "#endif",
  348. "/*--------------------------------------------------------------------------*/",
  349. "#if (FXAA_QUALITY_PRESET == 26)",
  350. " #define FXAA_QUALITY_PS 9",
  351. " #define FXAA_QUALITY_P0 1.0",
  352. " #define FXAA_QUALITY_P1 1.5",
  353. " #define FXAA_QUALITY_P2 2.0",
  354. " #define FXAA_QUALITY_P3 2.0",
  355. " #define FXAA_QUALITY_P4 2.0",
  356. " #define FXAA_QUALITY_P5 2.0",
  357. " #define FXAA_QUALITY_P6 2.0",
  358. " #define FXAA_QUALITY_P7 4.0",
  359. " #define FXAA_QUALITY_P8 8.0",
  360. "#endif",
  361. "/*--------------------------------------------------------------------------*/",
  362. "#if (FXAA_QUALITY_PRESET == 27)",
  363. " #define FXAA_QUALITY_PS 10",
  364. " #define FXAA_QUALITY_P0 1.0",
  365. " #define FXAA_QUALITY_P1 1.5",
  366. " #define FXAA_QUALITY_P2 2.0",
  367. " #define FXAA_QUALITY_P3 2.0",
  368. " #define FXAA_QUALITY_P4 2.0",
  369. " #define FXAA_QUALITY_P5 2.0",
  370. " #define FXAA_QUALITY_P6 2.0",
  371. " #define FXAA_QUALITY_P7 2.0",
  372. " #define FXAA_QUALITY_P8 4.0",
  373. " #define FXAA_QUALITY_P9 8.0",
  374. "#endif",
  375. "/*--------------------------------------------------------------------------*/",
  376. "#if (FXAA_QUALITY_PRESET == 28)",
  377. " #define FXAA_QUALITY_PS 11",
  378. " #define FXAA_QUALITY_P0 1.0",
  379. " #define FXAA_QUALITY_P1 1.5",
  380. " #define FXAA_QUALITY_P2 2.0",
  381. " #define FXAA_QUALITY_P3 2.0",
  382. " #define FXAA_QUALITY_P4 2.0",
  383. " #define FXAA_QUALITY_P5 2.0",
  384. " #define FXAA_QUALITY_P6 2.0",
  385. " #define FXAA_QUALITY_P7 2.0",
  386. " #define FXAA_QUALITY_P8 2.0",
  387. " #define FXAA_QUALITY_P9 4.0",
  388. " #define FXAA_QUALITY_P10 8.0",
  389. "#endif",
  390. "/*--------------------------------------------------------------------------*/",
  391. "#if (FXAA_QUALITY_PRESET == 29)",
  392. " #define FXAA_QUALITY_PS 12",
  393. " #define FXAA_QUALITY_P0 1.0",
  394. " #define FXAA_QUALITY_P1 1.5",
  395. " #define FXAA_QUALITY_P2 2.0",
  396. " #define FXAA_QUALITY_P3 2.0",
  397. " #define FXAA_QUALITY_P4 2.0",
  398. " #define FXAA_QUALITY_P5 2.0",
  399. " #define FXAA_QUALITY_P6 2.0",
  400. " #define FXAA_QUALITY_P7 2.0",
  401. " #define FXAA_QUALITY_P8 2.0",
  402. " #define FXAA_QUALITY_P9 2.0",
  403. " #define FXAA_QUALITY_P10 4.0",
  404. " #define FXAA_QUALITY_P11 8.0",
  405. "#endif",
  406. "",
  407. "/*============================================================================",
  408. " FXAA QUALITY - EXTREME QUALITY",
  409. "============================================================================*/",
  410. "#if (FXAA_QUALITY_PRESET == 39)",
  411. " #define FXAA_QUALITY_PS 12",
  412. " #define FXAA_QUALITY_P0 1.0",
  413. " #define FXAA_QUALITY_P1 1.0",
  414. " #define FXAA_QUALITY_P2 1.0",
  415. " #define FXAA_QUALITY_P3 1.0",
  416. " #define FXAA_QUALITY_P4 1.0",
  417. " #define FXAA_QUALITY_P5 1.5",
  418. " #define FXAA_QUALITY_P6 2.0",
  419. " #define FXAA_QUALITY_P7 2.0",
  420. " #define FXAA_QUALITY_P8 2.0",
  421. " #define FXAA_QUALITY_P9 2.0",
  422. " #define FXAA_QUALITY_P10 4.0",
  423. " #define FXAA_QUALITY_P11 8.0",
  424. "#endif",
  425. "",
  426. "",
  427. "",
  428. "/*============================================================================",
  429. "",
  430. " API PORTING",
  431. "",
  432. "============================================================================*/",
  433. "#if (FXAA_GLSL_100 == 1) || (FXAA_GLSL_120 == 1) || (FXAA_GLSL_130 == 1)",
  434. " #define FxaaBool bool",
  435. " #define FxaaDiscard discard",
  436. " #define FxaaFloat float",
  437. " #define FxaaFloat2 vec2",
  438. " #define FxaaFloat3 vec3",
  439. " #define FxaaFloat4 vec4",
  440. " #define FxaaHalf float",
  441. " #define FxaaHalf2 vec2",
  442. " #define FxaaHalf3 vec3",
  443. " #define FxaaHalf4 vec4",
  444. " #define FxaaInt2 ivec2",
  445. " #define FxaaSat(x) clamp(x, 0.0, 1.0)",
  446. " #define FxaaTex sampler2D",
  447. "#else",
  448. " #define FxaaBool bool",
  449. " #define FxaaDiscard clip(-1)",
  450. " #define FxaaFloat float",
  451. " #define FxaaFloat2 float2",
  452. " #define FxaaFloat3 float3",
  453. " #define FxaaFloat4 float4",
  454. " #define FxaaHalf half",
  455. " #define FxaaHalf2 half2",
  456. " #define FxaaHalf3 half3",
  457. " #define FxaaHalf4 half4",
  458. " #define FxaaSat(x) saturate(x)",
  459. "#endif",
  460. "/*--------------------------------------------------------------------------*/",
  461. "#if (FXAA_GLSL_100 == 1)",
  462. " #define FxaaTexTop(t, p) texture2D(t, p, 0.0)",
  463. " #define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r), 0.0)",
  464. "#endif",
  465. "/*--------------------------------------------------------------------------*/",
  466. "#if (FXAA_GLSL_120 == 1)",
  467. " // Requires,",
  468. " // #version 120",
  469. " // And at least,",
  470. " // #extension GL_EXT_gpu_shader4 : enable",
  471. " // (or set FXAA_FAST_PIXEL_OFFSET 1 to work like DX9)",
  472. " #define FxaaTexTop(t, p) texture2DLod(t, p, 0.0)",
  473. " #if (FXAA_FAST_PIXEL_OFFSET == 1)",
  474. " #define FxaaTexOff(t, p, o, r) texture2DLodOffset(t, p, 0.0, o)",
  475. " #else",
  476. " #define FxaaTexOff(t, p, o, r) texture2DLod(t, p + (o * r), 0.0)",
  477. " #endif",
  478. " #if (FXAA_GATHER4_ALPHA == 1)",
  479. " // use #extension GL_ARB_gpu_shader5 : enable",
  480. " #define FxaaTexAlpha4(t, p) textureGather(t, p, 3)",
  481. " #define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, p, o, 3)",
  482. " #define FxaaTexGreen4(t, p) textureGather(t, p, 1)",
  483. " #define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, p, o, 1)",
  484. " #endif",
  485. "#endif",
  486. "/*--------------------------------------------------------------------------*/",
  487. "#if (FXAA_GLSL_130 == 1)",
  488. " // Requires \"#version 130\" or better",
  489. " #define FxaaTexTop(t, p) textureLod(t, p, 0.0)",
  490. " #define FxaaTexOff(t, p, o, r) textureLodOffset(t, p, 0.0, o)",
  491. " #if (FXAA_GATHER4_ALPHA == 1)",
  492. " // use #extension GL_ARB_gpu_shader5 : enable",
  493. " #define FxaaTexAlpha4(t, p) textureGather(t, p, 3)",
  494. " #define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, p, o, 3)",
  495. " #define FxaaTexGreen4(t, p) textureGather(t, p, 1)",
  496. " #define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, p, o, 1)",
  497. " #endif",
  498. "#endif",
  499. "/*--------------------------------------------------------------------------*/",
  500. "#if (FXAA_HLSL_3 == 1)",
  501. " #define FxaaInt2 float2",
  502. " #define FxaaTex sampler2D",
  503. " #define FxaaTexTop(t, p) tex2Dlod(t, float4(p, 0.0, 0.0))",
  504. " #define FxaaTexOff(t, p, o, r) tex2Dlod(t, float4(p + (o * r), 0, 0))",
  505. "#endif",
  506. "/*--------------------------------------------------------------------------*/",
  507. "#if (FXAA_HLSL_4 == 1)",
  508. " #define FxaaInt2 int2",
  509. " struct FxaaTex { SamplerState smpl; Texture2D tex; };",
  510. " #define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, p, 0.0)",
  511. " #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, p, 0.0, o)",
  512. "#endif",
  513. "/*--------------------------------------------------------------------------*/",
  514. "#if (FXAA_HLSL_5 == 1)",
  515. " #define FxaaInt2 int2",
  516. " struct FxaaTex { SamplerState smpl; Texture2D tex; };",
  517. " #define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, p, 0.0)",
  518. " #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, p, 0.0, o)",
  519. " #define FxaaTexAlpha4(t, p) t.tex.GatherAlpha(t.smpl, p)",
  520. " #define FxaaTexOffAlpha4(t, p, o) t.tex.GatherAlpha(t.smpl, p, o)",
  521. " #define FxaaTexGreen4(t, p) t.tex.GatherGreen(t.smpl, p)",
  522. " #define FxaaTexOffGreen4(t, p, o) t.tex.GatherGreen(t.smpl, p, o)",
  523. "#endif",
  524. "",
  525. "",
  526. "/*============================================================================",
  527. " GREEN AS LUMA OPTION SUPPORT FUNCTION",
  528. "============================================================================*/",
  529. "#if (FXAA_GREEN_AS_LUMA == 0)",
  530. " FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.w; }",
  531. "#else",
  532. " FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.y; }",
  533. "#endif",
  534. "",
  535. "",
  536. "",
  537. "",
  538. "/*============================================================================",
  539. "",
  540. " FXAA3 QUALITY - PC",
  541. "",
  542. "============================================================================*/",
  543. "#if (FXAA_PC == 1)",
  544. "/*--------------------------------------------------------------------------*/",
  545. "FxaaFloat4 FxaaPixelShader(",
  546. " //",
  547. " // Use noperspective interpolation here (turn off perspective interpolation).",
  548. " // {xy} = center of pixel",
  549. " FxaaFloat2 pos,",
  550. " //",
  551. " // Used only for FXAA Console, and not used on the 360 version.",
  552. " // Use noperspective interpolation here (turn off perspective interpolation).",
  553. " // {xy_} = upper left of pixel",
  554. " // {_zw} = lower right of pixel",
  555. " FxaaFloat4 fxaaConsolePosPos,",
  556. " //",
  557. " // Input color texture.",
  558. " // {rgb_} = color in linear or perceptual color space",
  559. " // if (FXAA_GREEN_AS_LUMA == 0)",
  560. " // {__a} = luma in perceptual color space (not linear)",
  561. " FxaaTex tex,",
  562. " //",
  563. " // Only used on the optimized 360 version of FXAA Console.",
  564. " // For everything but 360, just use the same input here as for \"tex\".",
  565. " // For 360, same texture, just alias with a 2nd sampler.",
  566. " // This sampler needs to have an exponent bias of -1.",
  567. " FxaaTex fxaaConsole360TexExpBiasNegOne,",
  568. " //",
  569. " // Only used on the optimized 360 version of FXAA Console.",
  570. " // For everything but 360, just use the same input here as for \"tex\".",
  571. " // For 360, same texture, just alias with a 3nd sampler.",
  572. " // This sampler needs to have an exponent bias of -2.",
  573. " FxaaTex fxaaConsole360TexExpBiasNegTwo,",
  574. " //",
  575. " // Only used on FXAA Quality.",
  576. " // This must be from a constant/uniform.",
  577. " // {x_} = 1.0/screenWidthInPixels",
  578. " // {_y} = 1.0/screenHeightInPixels",
  579. " FxaaFloat2 fxaaQualityRcpFrame,",
  580. " //",
  581. " // Only used on FXAA Console.",
  582. " // This must be from a constant/uniform.",
  583. " // This effects sub-pixel AA quality and inversely sharpness.",
  584. " // Where N ranges between,",
  585. " // N = 0.50 (default)",
  586. " // N = 0.33 (sharper)",
  587. " // {x__} = -N/screenWidthInPixels",
  588. " // {_y_} = -N/screenHeightInPixels",
  589. " // {_z_} = N/screenWidthInPixels",
  590. " // {__w} = N/screenHeightInPixels",
  591. " FxaaFloat4 fxaaConsoleRcpFrameOpt,",
  592. " //",
  593. " // Only used on FXAA Console.",
  594. " // Not used on 360, but used on PS3 and PC.",
  595. " // This must be from a constant/uniform.",
  596. " // {x__} = -2.0/screenWidthInPixels",
  597. " // {_y_} = -2.0/screenHeightInPixels",
  598. " // {_z_} = 2.0/screenWidthInPixels",
  599. " // {__w} = 2.0/screenHeightInPixels",
  600. " FxaaFloat4 fxaaConsoleRcpFrameOpt2,",
  601. " //",
  602. " // Only used on FXAA Console.",
  603. " // Only used on 360 in place of fxaaConsoleRcpFrameOpt2.",
  604. " // This must be from a constant/uniform.",
  605. " // {x__} = 8.0/screenWidthInPixels",
  606. " // {_y_} = 8.0/screenHeightInPixels",
  607. " // {_z_} = -4.0/screenWidthInPixels",
  608. " // {__w} = -4.0/screenHeightInPixels",
  609. " FxaaFloat4 fxaaConsole360RcpFrameOpt2,",
  610. " //",
  611. " // Only used on FXAA Quality.",
  612. " // This used to be the FXAA_QUALITY_SUBPIX define.",
  613. " // It is here now to allow easier tuning.",
  614. " // Choose the amount of sub-pixel aliasing removal.",
  615. " // This can effect sharpness.",
  616. " // 1.00 - upper limit (softer)",
  617. " // 0.75 - default amount of filtering",
  618. " // 0.50 - lower limit (sharper, less sub-pixel aliasing removal)",
  619. " // 0.25 - almost off",
  620. " // 0.00 - completely off",
  621. " FxaaFloat fxaaQualitySubpix,",
  622. " //",
  623. " // Only used on FXAA Quality.",
  624. " // This used to be the FXAA_QUALITY_EDGE_THRESHOLD define.",
  625. " // It is here now to allow easier tuning.",
  626. " // The minimum amount of local contrast required to apply algorithm.",
  627. " // 0.333 - too little (faster)",
  628. " // 0.250 - low quality",
  629. " // 0.166 - default",
  630. " // 0.125 - high quality",
  631. " // 0.063 - overkill (slower)",
  632. " FxaaFloat fxaaQualityEdgeThreshold,",
  633. " //",
  634. " // Only used on FXAA Quality.",
  635. " // This used to be the FXAA_QUALITY_EDGE_THRESHOLD_MIN define.",
  636. " // It is here now to allow easier tuning.",
  637. " // Trims the algorithm from processing darks.",
  638. " // 0.0833 - upper limit (default, the start of visible unfiltered edges)",
  639. " // 0.0625 - high quality (faster)",
  640. " // 0.0312 - visible limit (slower)",
  641. " // Special notes when using FXAA_GREEN_AS_LUMA,",
  642. " // Likely want to set this to zero.",
  643. " // As colors that are mostly not-green",
  644. " // will appear very dark in the green channel!",
  645. " // Tune by looking at mostly non-green content,",
  646. " // then start at zero and increase until aliasing is a problem.",
  647. " FxaaFloat fxaaQualityEdgeThresholdMin,",
  648. " //",
  649. " // Only used on FXAA Console.",
  650. " // This used to be the FXAA_CONSOLE_EDGE_SHARPNESS define.",
  651. " // It is here now to allow easier tuning.",
  652. " // This does not effect PS3, as this needs to be compiled in.",
  653. " // Use FXAA_CONSOLE_PS3_EDGE_SHARPNESS for PS3.",
  654. " // Due to the PS3 being ALU bound,",
  655. " // there are only three safe values here: 2 and 4 and 8.",
  656. " // These options use the shaders ability to a free *|/ by 2|4|8.",
  657. " // For all other platforms can be a non-power of two.",
  658. " // 8.0 is sharper (default!!!)",
  659. " // 4.0 is softer",
  660. " // 2.0 is really soft (good only for vector graphics inputs)",
  661. " FxaaFloat fxaaConsoleEdgeSharpness,",
  662. " //",
  663. " // Only used on FXAA Console.",
  664. " // This used to be the FXAA_CONSOLE_EDGE_THRESHOLD define.",
  665. " // It is here now to allow easier tuning.",
  666. " // This does not effect PS3, as this needs to be compiled in.",
  667. " // Use FXAA_CONSOLE_PS3_EDGE_THRESHOLD for PS3.",
  668. " // Due to the PS3 being ALU bound,",
  669. " // there are only two safe values here: 1/4 and 1/8.",
  670. " // These options use the shaders ability to a free *|/ by 2|4|8.",
  671. " // The console setting has a different mapping than the quality setting.",
  672. " // Other platforms can use other values.",
  673. " // 0.125 leaves less aliasing, but is softer (default!!!)",
  674. " // 0.25 leaves more aliasing, and is sharper",
  675. " FxaaFloat fxaaConsoleEdgeThreshold,",
  676. " //",
  677. " // Only used on FXAA Console.",
  678. " // This used to be the FXAA_CONSOLE_EDGE_THRESHOLD_MIN define.",
  679. " // It is here now to allow easier tuning.",
  680. " // Trims the algorithm from processing darks.",
  681. " // The console setting has a different mapping than the quality setting.",
  682. " // This only applies when FXAA_EARLY_EXIT is 1.",
  683. " // This does not apply to PS3,",
  684. " // PS3 was simplified to avoid more shader instructions.",
  685. " // 0.06 - faster but more aliasing in darks",
  686. " // 0.05 - default",
  687. " // 0.04 - slower and less aliasing in darks",
  688. " // Special notes when using FXAA_GREEN_AS_LUMA,",
  689. " // Likely want to set this to zero.",
  690. " // As colors that are mostly not-green",
  691. " // will appear very dark in the green channel!",
  692. " // Tune by looking at mostly non-green content,",
  693. " // then start at zero and increase until aliasing is a problem.",
  694. " FxaaFloat fxaaConsoleEdgeThresholdMin,",
  695. " //",
  696. " // Extra constants for 360 FXAA Console only.",
  697. " // Use zeros or anything else for other platforms.",
  698. " // These must be in physical constant registers and NOT immediates.",
  699. " // Immediates will result in compiler un-optimizing.",
  700. " // {xyzw} = float4(1.0, -1.0, 0.25, -0.25)",
  701. " FxaaFloat4 fxaaConsole360ConstDir",
  702. ") {",
  703. "/*--------------------------------------------------------------------------*/",
  704. " FxaaFloat2 posM;",
  705. " posM.x = pos.x;",
  706. " posM.y = pos.y;",
  707. " #if (FXAA_GATHER4_ALPHA == 1)",
  708. " #if (FXAA_DISCARD == 0)",
  709. " FxaaFloat4 rgbyM = FxaaTexTop(tex, posM);",
  710. " #if (FXAA_GREEN_AS_LUMA == 0)",
  711. " #define lumaM rgbyM.w",
  712. " #else",
  713. " #define lumaM rgbyM.y",
  714. " #endif",
  715. " #endif",
  716. " #if (FXAA_GREEN_AS_LUMA == 0)",
  717. " FxaaFloat4 luma4A = FxaaTexAlpha4(tex, posM);",
  718. " FxaaFloat4 luma4B = FxaaTexOffAlpha4(tex, posM, FxaaInt2(-1, -1));",
  719. " #else",
  720. " FxaaFloat4 luma4A = FxaaTexGreen4(tex, posM);",
  721. " FxaaFloat4 luma4B = FxaaTexOffGreen4(tex, posM, FxaaInt2(-1, -1));",
  722. " #endif",
  723. " #if (FXAA_DISCARD == 1)",
  724. " #define lumaM luma4A.w",
  725. " #endif",
  726. " #define lumaE luma4A.z",
  727. " #define lumaS luma4A.x",
  728. " #define lumaSE luma4A.y",
  729. " #define lumaNW luma4B.w",
  730. " #define lumaN luma4B.z",
  731. " #define lumaW luma4B.x",
  732. " #else",
  733. " FxaaFloat4 rgbyM = FxaaTexTop(tex, posM);",
  734. " #if (FXAA_GREEN_AS_LUMA == 0)",
  735. " #define lumaM rgbyM.w",
  736. " #else",
  737. " #define lumaM rgbyM.y",
  738. " #endif",
  739. " #if (FXAA_GLSL_100 == 1)",
  740. " FxaaFloat lumaS = FxaaLuma(FxaaTexOff(tex, posM, FxaaFloat2( 0.0, 1.0), fxaaQualityRcpFrame.xy));",
  741. " FxaaFloat lumaE = FxaaLuma(FxaaTexOff(tex, posM, FxaaFloat2( 1.0, 0.0), fxaaQualityRcpFrame.xy));",
  742. " FxaaFloat lumaN = FxaaLuma(FxaaTexOff(tex, posM, FxaaFloat2( 0.0,-1.0), fxaaQualityRcpFrame.xy));",
  743. " FxaaFloat lumaW = FxaaLuma(FxaaTexOff(tex, posM, FxaaFloat2(-1.0, 0.0), fxaaQualityRcpFrame.xy));",
  744. " #else",
  745. " FxaaFloat lumaS = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0, 1), fxaaQualityRcpFrame.xy));",
  746. " FxaaFloat lumaE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 0), fxaaQualityRcpFrame.xy));",
  747. " FxaaFloat lumaN = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 0,-1), fxaaQualityRcpFrame.xy));",
  748. " FxaaFloat lumaW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 0), fxaaQualityRcpFrame.xy));",
  749. " #endif",
  750. " #endif",
  751. "/*--------------------------------------------------------------------------*/",
  752. " FxaaFloat maxSM = max(lumaS, lumaM);",
  753. " FxaaFloat minSM = min(lumaS, lumaM);",
  754. " FxaaFloat maxESM = max(lumaE, maxSM);",
  755. " FxaaFloat minESM = min(lumaE, minSM);",
  756. " FxaaFloat maxWN = max(lumaN, lumaW);",
  757. " FxaaFloat minWN = min(lumaN, lumaW);",
  758. " FxaaFloat rangeMax = max(maxWN, maxESM);",
  759. " FxaaFloat rangeMin = min(minWN, minESM);",
  760. " FxaaFloat rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;",
  761. " FxaaFloat range = rangeMax - rangeMin;",
  762. " FxaaFloat rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);",
  763. " FxaaBool earlyExit = range < rangeMaxClamped;",
  764. "/*--------------------------------------------------------------------------*/",
  765. " if(earlyExit)",
  766. " #if (FXAA_DISCARD == 1)",
  767. " FxaaDiscard;",
  768. " #else",
  769. " return rgbyM;",
  770. " #endif",
  771. "/*--------------------------------------------------------------------------*/",
  772. " #if (FXAA_GATHER4_ALPHA == 0)",
  773. " #if (FXAA_GLSL_100 == 1)",
  774. " FxaaFloat lumaNW = FxaaLuma(FxaaTexOff(tex, posM, FxaaFloat2(-1.0,-1.0), fxaaQualityRcpFrame.xy));",
  775. " FxaaFloat lumaSE = FxaaLuma(FxaaTexOff(tex, posM, FxaaFloat2( 1.0, 1.0), fxaaQualityRcpFrame.xy));",
  776. " FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaFloat2( 1.0,-1.0), fxaaQualityRcpFrame.xy));",
  777. " FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaFloat2(-1.0, 1.0), fxaaQualityRcpFrame.xy));",
  778. " #else",
  779. " FxaaFloat lumaNW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1,-1), fxaaQualityRcpFrame.xy));",
  780. " FxaaFloat lumaSE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1, 1), fxaaQualityRcpFrame.xy));",
  781. " FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2( 1,-1), fxaaQualityRcpFrame.xy));",
  782. " FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy));",
  783. " #endif",
  784. " #else",
  785. " FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(1, -1), fxaaQualityRcpFrame.xy));",
  786. " FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy));",
  787. " #endif",
  788. "/*--------------------------------------------------------------------------*/",
  789. " FxaaFloat lumaNS = lumaN + lumaS;",
  790. " FxaaFloat lumaWE = lumaW + lumaE;",
  791. " FxaaFloat subpixRcpRange = 1.0/range;",
  792. " FxaaFloat subpixNSWE = lumaNS + lumaWE;",
  793. " FxaaFloat edgeHorz1 = (-2.0 * lumaM) + lumaNS;",
  794. " FxaaFloat edgeVert1 = (-2.0 * lumaM) + lumaWE;",
  795. "/*--------------------------------------------------------------------------*/",
  796. " FxaaFloat lumaNESE = lumaNE + lumaSE;",
  797. " FxaaFloat lumaNWNE = lumaNW + lumaNE;",
  798. " FxaaFloat edgeHorz2 = (-2.0 * lumaE) + lumaNESE;",
  799. " FxaaFloat edgeVert2 = (-2.0 * lumaN) + lumaNWNE;",
  800. "/*--------------------------------------------------------------------------*/",
  801. " FxaaFloat lumaNWSW = lumaNW + lumaSW;",
  802. " FxaaFloat lumaSWSE = lumaSW + lumaSE;",
  803. " FxaaFloat edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);",
  804. " FxaaFloat edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);",
  805. " FxaaFloat edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;",
  806. " FxaaFloat edgeVert3 = (-2.0 * lumaS) + lumaSWSE;",
  807. " FxaaFloat edgeHorz = abs(edgeHorz3) + edgeHorz4;",
  808. " FxaaFloat edgeVert = abs(edgeVert3) + edgeVert4;",
  809. "/*--------------------------------------------------------------------------*/",
  810. " FxaaFloat subpixNWSWNESE = lumaNWSW + lumaNESE;",
  811. " FxaaFloat lengthSign = fxaaQualityRcpFrame.x;",
  812. " FxaaBool horzSpan = edgeHorz >= edgeVert;",
  813. " FxaaFloat subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;",
  814. "/*--------------------------------------------------------------------------*/",
  815. " if(!horzSpan) lumaN = lumaW;",
  816. " if(!horzSpan) lumaS = lumaE;",
  817. " if(horzSpan) lengthSign = fxaaQualityRcpFrame.y;",
  818. " FxaaFloat subpixB = (subpixA * (1.0/12.0)) - lumaM;",
  819. "/*--------------------------------------------------------------------------*/",
  820. " FxaaFloat gradientN = lumaN - lumaM;",
  821. " FxaaFloat gradientS = lumaS - lumaM;",
  822. " FxaaFloat lumaNN = lumaN + lumaM;",
  823. " FxaaFloat lumaSS = lumaS + lumaM;",
  824. " FxaaBool pairN = abs(gradientN) >= abs(gradientS);",
  825. " FxaaFloat gradient = max(abs(gradientN), abs(gradientS));",
  826. " if(pairN) lengthSign = -lengthSign;",
  827. " FxaaFloat subpixC = FxaaSat(abs(subpixB) * subpixRcpRange);",
  828. "/*--------------------------------------------------------------------------*/",
  829. " FxaaFloat2 posB;",
  830. " posB.x = posM.x;",
  831. " posB.y = posM.y;",
  832. " FxaaFloat2 offNP;",
  833. " offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;",
  834. " offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;",
  835. " if(!horzSpan) posB.x += lengthSign * 0.5;",
  836. " if( horzSpan) posB.y += lengthSign * 0.5;",
  837. "/*--------------------------------------------------------------------------*/",
  838. " FxaaFloat2 posN;",
  839. " posN.x = posB.x - offNP.x * FXAA_QUALITY_P0;",
  840. " posN.y = posB.y - offNP.y * FXAA_QUALITY_P0;",
  841. " FxaaFloat2 posP;",
  842. " posP.x = posB.x + offNP.x * FXAA_QUALITY_P0;",
  843. " posP.y = posB.y + offNP.y * FXAA_QUALITY_P0;",
  844. " FxaaFloat subpixD = ((-2.0)*subpixC) + 3.0;",
  845. " FxaaFloat lumaEndN = FxaaLuma(FxaaTexTop(tex, posN));",
  846. " FxaaFloat subpixE = subpixC * subpixC;",
  847. " FxaaFloat lumaEndP = FxaaLuma(FxaaTexTop(tex, posP));",
  848. "/*--------------------------------------------------------------------------*/",
  849. " if(!pairN) lumaNN = lumaSS;",
  850. " FxaaFloat gradientScaled = gradient * 1.0/4.0;",
  851. " FxaaFloat lumaMM = lumaM - lumaNN * 0.5;",
  852. " FxaaFloat subpixF = subpixD * subpixE;",
  853. " FxaaBool lumaMLTZero = lumaMM < 0.0;",
  854. "/*--------------------------------------------------------------------------*/",
  855. " lumaEndN -= lumaNN * 0.5;",
  856. " lumaEndP -= lumaNN * 0.5;",
  857. " FxaaBool doneN = abs(lumaEndN) >= gradientScaled;",
  858. " FxaaBool doneP = abs(lumaEndP) >= gradientScaled;",
  859. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P1;",
  860. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P1;",
  861. " FxaaBool doneNP = (!doneN) || (!doneP);",
  862. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P1;",
  863. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P1;",
  864. "/*--------------------------------------------------------------------------*/",
  865. " if(doneNP) {",
  866. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  867. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  868. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  869. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  870. " doneN = abs(lumaEndN) >= gradientScaled;",
  871. " doneP = abs(lumaEndP) >= gradientScaled;",
  872. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P2;",
  873. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P2;",
  874. " doneNP = (!doneN) || (!doneP);",
  875. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P2;",
  876. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P2;",
  877. "/*--------------------------------------------------------------------------*/",
  878. " #if (FXAA_QUALITY_PS > 3)",
  879. " if(doneNP) {",
  880. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  881. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  882. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  883. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  884. " doneN = abs(lumaEndN) >= gradientScaled;",
  885. " doneP = abs(lumaEndP) >= gradientScaled;",
  886. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P3;",
  887. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P3;",
  888. " doneNP = (!doneN) || (!doneP);",
  889. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P3;",
  890. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P3;",
  891. "/*--------------------------------------------------------------------------*/",
  892. " #if (FXAA_QUALITY_PS > 4)",
  893. " if(doneNP) {",
  894. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  895. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  896. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  897. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  898. " doneN = abs(lumaEndN) >= gradientScaled;",
  899. " doneP = abs(lumaEndP) >= gradientScaled;",
  900. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P4;",
  901. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P4;",
  902. " doneNP = (!doneN) || (!doneP);",
  903. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P4;",
  904. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P4;",
  905. "/*--------------------------------------------------------------------------*/",
  906. " #if (FXAA_QUALITY_PS > 5)",
  907. " if(doneNP) {",
  908. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  909. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  910. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  911. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  912. " doneN = abs(lumaEndN) >= gradientScaled;",
  913. " doneP = abs(lumaEndP) >= gradientScaled;",
  914. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P5;",
  915. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P5;",
  916. " doneNP = (!doneN) || (!doneP);",
  917. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P5;",
  918. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P5;",
  919. "/*--------------------------------------------------------------------------*/",
  920. " #if (FXAA_QUALITY_PS > 6)",
  921. " if(doneNP) {",
  922. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  923. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  924. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  925. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  926. " doneN = abs(lumaEndN) >= gradientScaled;",
  927. " doneP = abs(lumaEndP) >= gradientScaled;",
  928. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P6;",
  929. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P6;",
  930. " doneNP = (!doneN) || (!doneP);",
  931. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P6;",
  932. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P6;",
  933. "/*--------------------------------------------------------------------------*/",
  934. " #if (FXAA_QUALITY_PS > 7)",
  935. " if(doneNP) {",
  936. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  937. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  938. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  939. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  940. " doneN = abs(lumaEndN) >= gradientScaled;",
  941. " doneP = abs(lumaEndP) >= gradientScaled;",
  942. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P7;",
  943. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P7;",
  944. " doneNP = (!doneN) || (!doneP);",
  945. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P7;",
  946. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P7;",
  947. "/*--------------------------------------------------------------------------*/",
  948. " #if (FXAA_QUALITY_PS > 8)",
  949. " if(doneNP) {",
  950. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  951. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  952. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  953. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  954. " doneN = abs(lumaEndN) >= gradientScaled;",
  955. " doneP = abs(lumaEndP) >= gradientScaled;",
  956. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P8;",
  957. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P8;",
  958. " doneNP = (!doneN) || (!doneP);",
  959. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P8;",
  960. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P8;",
  961. "/*--------------------------------------------------------------------------*/",
  962. " #if (FXAA_QUALITY_PS > 9)",
  963. " if(doneNP) {",
  964. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  965. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  966. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  967. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  968. " doneN = abs(lumaEndN) >= gradientScaled;",
  969. " doneP = abs(lumaEndP) >= gradientScaled;",
  970. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P9;",
  971. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P9;",
  972. " doneNP = (!doneN) || (!doneP);",
  973. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P9;",
  974. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P9;",
  975. "/*--------------------------------------------------------------------------*/",
  976. " #if (FXAA_QUALITY_PS > 10)",
  977. " if(doneNP) {",
  978. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  979. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  980. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  981. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  982. " doneN = abs(lumaEndN) >= gradientScaled;",
  983. " doneP = abs(lumaEndP) >= gradientScaled;",
  984. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P10;",
  985. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P10;",
  986. " doneNP = (!doneN) || (!doneP);",
  987. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P10;",
  988. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P10;",
  989. "/*--------------------------------------------------------------------------*/",
  990. " #if (FXAA_QUALITY_PS > 11)",
  991. " if(doneNP) {",
  992. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  993. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  994. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  995. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  996. " doneN = abs(lumaEndN) >= gradientScaled;",
  997. " doneP = abs(lumaEndP) >= gradientScaled;",
  998. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P11;",
  999. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P11;",
  1000. " doneNP = (!doneN) || (!doneP);",
  1001. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P11;",
  1002. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P11;",
  1003. "/*--------------------------------------------------------------------------*/",
  1004. " #if (FXAA_QUALITY_PS > 12)",
  1005. " if(doneNP) {",
  1006. " if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));",
  1007. " if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));",
  1008. " if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;",
  1009. " if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;",
  1010. " doneN = abs(lumaEndN) >= gradientScaled;",
  1011. " doneP = abs(lumaEndP) >= gradientScaled;",
  1012. " if(!doneN) posN.x -= offNP.x * FXAA_QUALITY_P12;",
  1013. " if(!doneN) posN.y -= offNP.y * FXAA_QUALITY_P12;",
  1014. " doneNP = (!doneN) || (!doneP);",
  1015. " if(!doneP) posP.x += offNP.x * FXAA_QUALITY_P12;",
  1016. " if(!doneP) posP.y += offNP.y * FXAA_QUALITY_P12;",
  1017. "/*--------------------------------------------------------------------------*/",
  1018. " }",
  1019. " #endif",
  1020. "/*--------------------------------------------------------------------------*/",
  1021. " }",
  1022. " #endif",
  1023. "/*--------------------------------------------------------------------------*/",
  1024. " }",
  1025. " #endif",
  1026. "/*--------------------------------------------------------------------------*/",
  1027. " }",
  1028. " #endif",
  1029. "/*--------------------------------------------------------------------------*/",
  1030. " }",
  1031. " #endif",
  1032. "/*--------------------------------------------------------------------------*/",
  1033. " }",
  1034. " #endif",
  1035. "/*--------------------------------------------------------------------------*/",
  1036. " }",
  1037. " #endif",
  1038. "/*--------------------------------------------------------------------------*/",
  1039. " }",
  1040. " #endif",
  1041. "/*--------------------------------------------------------------------------*/",
  1042. " }",
  1043. " #endif",
  1044. "/*--------------------------------------------------------------------------*/",
  1045. " }",
  1046. " #endif",
  1047. "/*--------------------------------------------------------------------------*/",
  1048. " }",
  1049. "/*--------------------------------------------------------------------------*/",
  1050. " FxaaFloat dstN = posM.x - posN.x;",
  1051. " FxaaFloat dstP = posP.x - posM.x;",
  1052. " if(!horzSpan) dstN = posM.y - posN.y;",
  1053. " if(!horzSpan) dstP = posP.y - posM.y;",
  1054. "/*--------------------------------------------------------------------------*/",
  1055. " FxaaBool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;",
  1056. " FxaaFloat spanLength = (dstP + dstN);",
  1057. " FxaaBool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;",
  1058. " FxaaFloat spanLengthRcp = 1.0/spanLength;",
  1059. "/*--------------------------------------------------------------------------*/",
  1060. " FxaaBool directionN = dstN < dstP;",
  1061. " FxaaFloat dst = min(dstN, dstP);",
  1062. " FxaaBool goodSpan = directionN ? goodSpanN : goodSpanP;",
  1063. " FxaaFloat subpixG = subpixF * subpixF;",
  1064. " FxaaFloat pixelOffset = (dst * (-spanLengthRcp)) + 0.5;",
  1065. " FxaaFloat subpixH = subpixG * fxaaQualitySubpix;",
  1066. "/*--------------------------------------------------------------------------*/",
  1067. " FxaaFloat pixelOffsetGood = goodSpan ? pixelOffset : 0.0;",
  1068. " FxaaFloat pixelOffsetSubpix = max(pixelOffsetGood, subpixH);",
  1069. " if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;",
  1070. " if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;",
  1071. " #if (FXAA_DISCARD == 1)",
  1072. " return FxaaTexTop(tex, posM);",
  1073. " #else",
  1074. " return FxaaFloat4(FxaaTexTop(tex, posM).xyz, lumaM);",
  1075. " #endif",
  1076. "}",
  1077. "/*==========================================================================*/",
  1078. "#endif",
  1079. "",
  1080. "void main() {",
  1081. " gl_FragColor = FxaaPixelShader(",
  1082. " vUv,",
  1083. " vec4(0.0),",
  1084. " tDiffuse,",
  1085. " tDiffuse,",
  1086. " tDiffuse,",
  1087. " resolution,",
  1088. " vec4(0.0),",
  1089. " vec4(0.0),",
  1090. " vec4(0.0),",
  1091. " 0.75,",
  1092. " 0.166,",
  1093. " 0.0833,",
  1094. " 0.0,",
  1095. " 0.0,",
  1096. " 0.0,",
  1097. " vec4(0.0)",
  1098. " );",
  1099. "",
  1100. " // TODO avoid querying texture twice for same texel",
  1101. " gl_FragColor.a = texture2D(tDiffuse, vUv).a;",
  1102. "}"
  1103. ].join( "\n" )
  1104. };