FXAAShader.js 51 KB

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