FXAAShader.js 51 KB

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