FastApproximateAntialiasing.hlsl 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075
  1. #ifndef __FXAA3_INC__
  2. #define __FXAA3_INC__
  3. #include "../xRLib.hlsl"
  4. /*============================================================================
  5. NVIDIA FXAA 3.11 by TIMOTHY LOTTES
  6. ------------------------------------------------------------------------------
  7. COPYRIGHT (C) 2010, 2011 NVIDIA CORPORATION. ALL RIGHTS RESERVED.
  8. ------------------------------------------------------------------------------
  9. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
  10. *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
  11. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  12. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA
  13. OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR
  14. CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR
  15. LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION,
  16. OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE
  17. THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  18. DAMAGES.
  19. ------------------------------------------------------------------------------
  20. INTEGRATION CHECKLIST
  21. ------------------------------------------------------------------------------
  22. (1.)
  23. In the shader source, setup defines for the desired configuration.
  24. When providing multiple shaders (for different presets),
  25. simply setup the defines differently in multiple files.
  26. Example,
  27. #define FXAA_PC 1
  28. #define FXAA_HLSL_5 1
  29. #define FXAA_QUALITY__PRESET 12
  30. Or,
  31. #define FXAA_360 1
  32. Or,
  33. #define FXAA_PS3 1
  34. Etc.
  35. (2.)
  36. Then include this file,
  37. #include "Fxaa3_11.h"
  38. (3.)
  39. Then call the FXAA pixel shader from within your desired shader.
  40. Look at the FXAA Quality FxaaPixelShader() for docs on inputs.
  41. As for FXAA 3.11 all inputs for all shaders are the same
  42. to enable easy porting between platforms.
  43. return FxaaPixelShader(...);
  44. (4.)
  45. Insure pass prior to FXAA outputs RGBL (see next section).
  46. Or use,
  47. #define FXAA_GREEN_AS_LUMA 1
  48. (5.)
  49. Setup engine to provide the following constants
  50. which are used in the FxaaPixelShader() inputs,
  51. FxaaFloat2 fxaaQualityRcpFrame,
  52. FxaaFloat4 fxaaConsoleRcpFrameOpt,
  53. FxaaFloat4 fxaaConsoleRcpFrameOpt2,
  54. FxaaFloat4 fxaaConsole360RcpFrameOpt2,
  55. FxaaFloat fxaaQualitySubpix,
  56. FxaaFloat fxaaQualityEdgeThreshold,
  57. FxaaFloat fxaaQualityEdgeThresholdMin,
  58. FxaaFloat fxaaConsoleEdgeSharpness,
  59. FxaaFloat fxaaConsoleEdgeThreshold,
  60. FxaaFloat fxaaConsoleEdgeThresholdMin,
  61. FxaaFloat4 fxaaConsole360ConstDir
  62. Look at the FXAA Quality FxaaPixelShader() for docs on inputs.
  63. (6.)
  64. Have FXAA vertex shader run as a full screen triangle,
  65. and output "pos" and "fxaaConsolePosPos"
  66. such that inputs in the pixel shader provide,
  67. // {xy} = center of pixel
  68. FxaaFloat2 pos,
  69. // {xy__} = upper left of pixel
  70. // {__zw} = lower right of pixel
  71. FxaaFloat4 fxaaConsolePosPos,
  72. (7.)
  73. Insure the texture sampler(s) used by FXAA are set to bilinear filtering.
  74. ------------------------------------------------------------------------------
  75. INTEGRATION - RGBL AND COLORSPACE
  76. ------------------------------------------------------------------------------
  77. FXAA3 requires RGBL as input unless the following is set,
  78. #define FXAA_GREEN_AS_LUMA 1
  79. In which case the engine uses green in place of luma,
  80. and requires RGB input is in a non-linear colorspace.
  81. RGB should be LDR (low dynamic range).
  82. Specifically do FXAA after tonemapping.
  83. RGB data as returned by a texture fetch can be non-linear,
  84. or linear when FXAA_GREEN_AS_LUMA is not set.
  85. Note an "sRGB format" texture counts as linear,
  86. because the result of a texture fetch is linear data.
  87. Regular "RGBA8" textures in the sRGB colorspace are non-linear.
  88. If FXAA_GREEN_AS_LUMA is not set,
  89. luma must be stored in the alpha channel prior to running FXAA.
  90. This luma should be in a perceptual space (could be gamma 2.0).
  91. Example pass before FXAA where output is gamma 2.0 encoded,
  92. color.rgb = ToneMap(color.rgb); // linear color output
  93. color.rgb = sqrt(color.rgb); // gamma 2.0 color output
  94. return color;
  95. To use FXAA,
  96. color.rgb = ToneMap(color.rgb); // linear color output
  97. color.rgb = sqrt(color.rgb); // gamma 2.0 color output
  98. color.a = dot(color.rgb, FxaaFloat3(0.299, 0.587, 0.114)); // compute luma
  99. return color;
  100. Another example where output is linear encoded,
  101. say for instance writing to an sRGB formated render target,
  102. where the render target does the conversion back to sRGB after blending,
  103. color.rgb = ToneMap(color.rgb); // linear color output
  104. return color;
  105. To use FXAA,
  106. color.rgb = ToneMap(color.rgb); // linear color output
  107. color.a = sqrt(dot(color.rgb, FxaaFloat3(0.299, 0.587, 0.114))); // compute luma
  108. return color;
  109. Getting luma correct is required for the algorithm to work correctly.
  110. ------------------------------------------------------------------------------
  111. BEING LINEARLY CORRECT?
  112. ------------------------------------------------------------------------------
  113. Applying FXAA to a framebuffer with linear RGB color will look worse.
  114. This is very counter intuitive, but happends to be true in this case.
  115. The reason is because dithering artifacts will be more visiable
  116. in a linear colorspace.
  117. ------------------------------------------------------------------------------
  118. COMPLEX INTEGRATION
  119. ------------------------------------------------------------------------------
  120. Q. What if the engine is blending into RGB before wanting to run FXAA?
  121. A. In the last opaque pass prior to FXAA,
  122. have the pass write out luma into alpha.
  123. Then blend into RGB only.
  124. FXAA should be able to run ok
  125. assuming the blending pass did not any add aliasing.
  126. This should be the common case for particles and common blending passes.
  127. A. Or use FXAA_GREEN_AS_LUMA.
  128. ============================================================================*/
  129. /*============================================================================
  130. INTEGRATION KNOBS
  131. ============================================================================*/
  132. //
  133. // FXAA_PS3 and FXAA_360 choose the console algorithm (FXAA3 CONSOLE).
  134. // FXAA_360_OPT is a prototype for the new optimized 360 version.
  135. //
  136. // 1 = Use API.
  137. // 0 = Don't use API.
  138. //
  139. /*--------------------------------------------------------------------------*/
  140. #ifndef FXAA_PS3
  141. #define FXAA_PS3 0
  142. #endif
  143. /*--------------------------------------------------------------------------*/
  144. #ifndef FXAA_360
  145. #define FXAA_360 0
  146. #endif
  147. /*--------------------------------------------------------------------------*/
  148. #ifndef FXAA_360_OPT
  149. #define FXAA_360_OPT 0
  150. #endif
  151. /*==========================================================================*/
  152. #ifndef FXAA_PC
  153. //
  154. // FXAA Quality
  155. // The high quality PC algorithm.
  156. //
  157. #define FXAA_PC 0
  158. #endif
  159. /*--------------------------------------------------------------------------*/
  160. #ifndef FXAA_PC_CONSOLE
  161. //
  162. // The console algorithm for PC is included
  163. // for developers targeting really low spec machines.
  164. // Likely better to just run FXAA_PC, and use a really low preset.
  165. //
  166. #define FXAA_PC_CONSOLE 0
  167. #endif
  168. /*--------------------------------------------------------------------------*/
  169. #ifndef FXAA_GLSL_120
  170. #define FXAA_GLSL_120 0
  171. #endif
  172. /*--------------------------------------------------------------------------*/
  173. #ifndef FXAA_GLSL_130
  174. #define FXAA_GLSL_130 0
  175. #endif
  176. /*--------------------------------------------------------------------------*/
  177. #ifndef FXAA_HLSL_3
  178. #define FXAA_HLSL_3 0
  179. #endif
  180. /*--------------------------------------------------------------------------*/
  181. #ifndef FXAA_HLSL_4
  182. #define FXAA_HLSL_4 0
  183. #endif
  184. /*--------------------------------------------------------------------------*/
  185. #ifndef FXAA_HLSL_5
  186. #define FXAA_HLSL_5 0
  187. #endif
  188. /*==========================================================================*/
  189. #ifndef FXAA_GREEN_AS_LUMA
  190. //
  191. // For those using non-linear color,
  192. // and either not able to get luma in alpha, or not wanting to,
  193. // this enables FXAA to run using green as a proxy for luma.
  194. // So with this enabled, no need to pack luma in alpha.
  195. //
  196. // This will turn off AA on anything which lacks some amount of green.
  197. // Pure red and blue or combination of only R and B, will get no AA.
  198. //
  199. // Might want to lower the settings for both,
  200. // fxaaConsoleEdgeThresholdMin
  201. // fxaaQualityEdgeThresholdMin
  202. // In order to insure AA does not get turned off on colors
  203. // which contain a minor amount of green.
  204. //
  205. // 1 = On.
  206. // 0 = Off.
  207. //
  208. #define FXAA_GREEN_AS_LUMA 0
  209. #endif
  210. /*--------------------------------------------------------------------------*/
  211. #ifndef FXAA_EARLY_EXIT
  212. //
  213. // Controls algorithm's early exit path.
  214. // On PS3 turning this ON adds 2 cycles to the shader.
  215. // On 360 turning this OFF adds 10ths of a millisecond to the shader.
  216. // Turning this off on console will result in a more blurry image.
  217. // So this defaults to on.
  218. //
  219. // 1 = On.
  220. // 0 = Off.
  221. //
  222. #define FXAA_EARLY_EXIT 1
  223. #endif
  224. /*--------------------------------------------------------------------------*/
  225. #ifndef FXAA_DISCARD
  226. //
  227. // Only valid for PC OpenGL currently.
  228. // Probably will not work when FXAA_GREEN_AS_LUMA = 1.
  229. //
  230. // 1 = Use discard on pixels which don't need AA.
  231. // For APIs which enable concurrent TEX+ROP from same surface.
  232. // 0 = Return unchanged color on pixels which don't need AA.
  233. //
  234. #define FXAA_DISCARD 0
  235. #endif
  236. /*--------------------------------------------------------------------------*/
  237. #ifndef FXAA_FAST_PIXEL_OFFSET
  238. //
  239. // Used for GLSL 120 only.
  240. //
  241. // 1 = GL API supports fast pixel offsets
  242. // 0 = do not use fast pixel offsets
  243. //
  244. #ifdef GL_EXT_gpu_shader4
  245. #define FXAA_FAST_PIXEL_OFFSET 1
  246. #endif
  247. #ifdef GL_NV_gpu_shader5
  248. #define FXAA_FAST_PIXEL_OFFSET 1
  249. #endif
  250. #ifdef GL_ARB_gpu_shader5
  251. #define FXAA_FAST_PIXEL_OFFSET 1
  252. #endif
  253. #ifndef FXAA_FAST_PIXEL_OFFSET
  254. #define FXAA_FAST_PIXEL_OFFSET 0
  255. #endif
  256. #endif
  257. /*--------------------------------------------------------------------------*/
  258. #ifndef FXAA_GATHER4_ALPHA
  259. //
  260. // 1 = API supports gather4 on alpha channel.
  261. // 0 = API does not support gather4 on alpha channel.
  262. //
  263. #if (FXAA_HLSL_5 == 1)
  264. #define FXAA_GATHER4_ALPHA 1
  265. #endif
  266. #ifdef GL_ARB_gpu_shader5
  267. #define FXAA_GATHER4_ALPHA 1
  268. #endif
  269. #ifdef GL_NV_gpu_shader5
  270. #define FXAA_GATHER4_ALPHA 1
  271. #endif
  272. #ifndef FXAA_GATHER4_ALPHA
  273. #define FXAA_GATHER4_ALPHA 0
  274. #endif
  275. #endif
  276. /*============================================================================
  277. FXAA CONSOLE PS3 - TUNING KNOBS
  278. ============================================================================*/
  279. #ifndef FXAA_CONSOLE__PS3_EDGE_SHARPNESS
  280. //
  281. // Consoles the sharpness of edges on PS3 only.
  282. // Non-PS3 tuning is done with shader input.
  283. //
  284. // Due to the PS3 being ALU bound,
  285. // there are only two safe values here: 4 and 8.
  286. // These options use the shaders ability to a free *|/ by 2|4|8.
  287. //
  288. // 8.0 is sharper
  289. // 4.0 is softer
  290. // 2.0 is really soft (good for vector graphics inputs)
  291. //
  292. #if 1
  293. #define FXAA_CONSOLE__PS3_EDGE_SHARPNESS 8.0
  294. #endif
  295. #if 0
  296. #define FXAA_CONSOLE__PS3_EDGE_SHARPNESS 4.0
  297. #endif
  298. #if 0
  299. #define FXAA_CONSOLE__PS3_EDGE_SHARPNESS 2.0
  300. #endif
  301. #endif
  302. /*--------------------------------------------------------------------------*/
  303. #ifndef FXAA_CONSOLE__PS3_EDGE_THRESHOLD
  304. //
  305. // Only effects PS3.
  306. // Non-PS3 tuning is done with shader input.
  307. //
  308. // The minimum amount of local contrast required to apply algorithm.
  309. // The console setting has a different mapping than the quality setting.
  310. //
  311. // This only applies when FXAA_EARLY_EXIT is 1.
  312. //
  313. // Due to the PS3 being ALU bound,
  314. // there are only two safe values here: 0.25 and 0.125.
  315. // These options use the shaders ability to a free *|/ by 2|4|8.
  316. //
  317. // 0.125 leaves less aliasing, but is softer
  318. // 0.25 leaves more aliasing, and is sharper
  319. //
  320. #if 1
  321. #define FXAA_CONSOLE__PS3_EDGE_THRESHOLD 0.125
  322. #else
  323. #define FXAA_CONSOLE__PS3_EDGE_THRESHOLD 0.25
  324. #endif
  325. #endif
  326. /*============================================================================
  327. FXAA QUALITY - TUNING KNOBS
  328. ------------------------------------------------------------------------------
  329. NOTE the other tuning knobs are now in the shader function inputs!
  330. ============================================================================*/
  331. #ifndef FXAA_QUALITY__PRESET
  332. //
  333. // Choose the quality preset.
  334. // This needs to be compiled into the shader as it effects code.
  335. // Best option to include multiple presets is to
  336. // in each shader define the preset, then include this file.
  337. //
  338. // OPTIONS
  339. // -----------------------------------------------------------------------
  340. // 10 to 15 - default medium dither (10=fastest, 15=highest quality)
  341. // 20 to 29 - less dither, more expensive (20=fastest, 29=highest quality)
  342. // 39 - no dither, very expensive
  343. //
  344. // NOTES
  345. // -----------------------------------------------------------------------
  346. // 12 = slightly faster then FXAA 3.9 and higher edge quality (default)
  347. // 13 = about same speed as FXAA 3.9 and better than 12
  348. // 23 = closest to FXAA 3.9 visually and performance wise
  349. // _ = the lowest digit is directly related to performance
  350. // _ = the highest digit is directly related to style
  351. //
  352. #define FXAA_QUALITY__PRESET 12
  353. #endif
  354. /*============================================================================
  355. FXAA QUALITY - PRESETS
  356. ============================================================================*/
  357. /*============================================================================
  358. FXAA QUALITY - MEDIUM DITHER PRESETS
  359. ============================================================================*/
  360. #if (FXAA_QUALITY__PRESET == 10)
  361. #define FXAA_QUALITY__PS 3
  362. #define FXAA_QUALITY__P0 1.5
  363. #define FXAA_QUALITY__P1 3.0
  364. #define FXAA_QUALITY__P2 12.0
  365. #endif
  366. /*--------------------------------------------------------------------------*/
  367. #if (FXAA_QUALITY__PRESET == 11)
  368. #define FXAA_QUALITY__PS 4
  369. #define FXAA_QUALITY__P0 1.0
  370. #define FXAA_QUALITY__P1 1.5
  371. #define FXAA_QUALITY__P2 3.0
  372. #define FXAA_QUALITY__P3 12.0
  373. #endif
  374. /*--------------------------------------------------------------------------*/
  375. #if (FXAA_QUALITY__PRESET == 12)
  376. #define FXAA_QUALITY__PS 5
  377. #define FXAA_QUALITY__P0 1.0
  378. #define FXAA_QUALITY__P1 1.5
  379. #define FXAA_QUALITY__P2 2.0
  380. #define FXAA_QUALITY__P3 4.0
  381. #define FXAA_QUALITY__P4 12.0
  382. #endif
  383. /*--------------------------------------------------------------------------*/
  384. #if (FXAA_QUALITY__PRESET == 13)
  385. #define FXAA_QUALITY__PS 6
  386. #define FXAA_QUALITY__P0 1.0
  387. #define FXAA_QUALITY__P1 1.5
  388. #define FXAA_QUALITY__P2 2.0
  389. #define FXAA_QUALITY__P3 2.0
  390. #define FXAA_QUALITY__P4 4.0
  391. #define FXAA_QUALITY__P5 12.0
  392. #endif
  393. /*--------------------------------------------------------------------------*/
  394. #if (FXAA_QUALITY__PRESET == 14)
  395. #define FXAA_QUALITY__PS 7
  396. #define FXAA_QUALITY__P0 1.0
  397. #define FXAA_QUALITY__P1 1.5
  398. #define FXAA_QUALITY__P2 2.0
  399. #define FXAA_QUALITY__P3 2.0
  400. #define FXAA_QUALITY__P4 2.0
  401. #define FXAA_QUALITY__P5 4.0
  402. #define FXAA_QUALITY__P6 12.0
  403. #endif
  404. /*--------------------------------------------------------------------------*/
  405. #if (FXAA_QUALITY__PRESET == 15)
  406. #define FXAA_QUALITY__PS 8
  407. #define FXAA_QUALITY__P0 1.0
  408. #define FXAA_QUALITY__P1 1.5
  409. #define FXAA_QUALITY__P2 2.0
  410. #define FXAA_QUALITY__P3 2.0
  411. #define FXAA_QUALITY__P4 2.0
  412. #define FXAA_QUALITY__P5 2.0
  413. #define FXAA_QUALITY__P6 4.0
  414. #define FXAA_QUALITY__P7 12.0
  415. #endif
  416. /*============================================================================
  417. FXAA QUALITY - LOW DITHER PRESETS
  418. ============================================================================*/
  419. #if (FXAA_QUALITY__PRESET == 20)
  420. #define FXAA_QUALITY__PS 3
  421. #define FXAA_QUALITY__P0 1.5
  422. #define FXAA_QUALITY__P1 2.0
  423. #define FXAA_QUALITY__P2 8.0
  424. #endif
  425. /*--------------------------------------------------------------------------*/
  426. #if (FXAA_QUALITY__PRESET == 21)
  427. #define FXAA_QUALITY__PS 4
  428. #define FXAA_QUALITY__P0 1.0
  429. #define FXAA_QUALITY__P1 1.5
  430. #define FXAA_QUALITY__P2 2.0
  431. #define FXAA_QUALITY__P3 8.0
  432. #endif
  433. /*--------------------------------------------------------------------------*/
  434. #if (FXAA_QUALITY__PRESET == 22)
  435. #define FXAA_QUALITY__PS 5
  436. #define FXAA_QUALITY__P0 1.0
  437. #define FXAA_QUALITY__P1 1.5
  438. #define FXAA_QUALITY__P2 2.0
  439. #define FXAA_QUALITY__P3 2.0
  440. #define FXAA_QUALITY__P4 8.0
  441. #endif
  442. /*--------------------------------------------------------------------------*/
  443. #if (FXAA_QUALITY__PRESET == 23)
  444. #define FXAA_QUALITY__PS 6
  445. #define FXAA_QUALITY__P0 1.0
  446. #define FXAA_QUALITY__P1 1.5
  447. #define FXAA_QUALITY__P2 2.0
  448. #define FXAA_QUALITY__P3 2.0
  449. #define FXAA_QUALITY__P4 2.0
  450. #define FXAA_QUALITY__P5 8.0
  451. #endif
  452. /*--------------------------------------------------------------------------*/
  453. #if (FXAA_QUALITY__PRESET == 24)
  454. #define FXAA_QUALITY__PS 7
  455. #define FXAA_QUALITY__P0 1.0
  456. #define FXAA_QUALITY__P1 1.5
  457. #define FXAA_QUALITY__P2 2.0
  458. #define FXAA_QUALITY__P3 2.0
  459. #define FXAA_QUALITY__P4 2.0
  460. #define FXAA_QUALITY__P5 3.0
  461. #define FXAA_QUALITY__P6 8.0
  462. #endif
  463. /*--------------------------------------------------------------------------*/
  464. #if (FXAA_QUALITY__PRESET == 25)
  465. #define FXAA_QUALITY__PS 8
  466. #define FXAA_QUALITY__P0 1.0
  467. #define FXAA_QUALITY__P1 1.5
  468. #define FXAA_QUALITY__P2 2.0
  469. #define FXAA_QUALITY__P3 2.0
  470. #define FXAA_QUALITY__P4 2.0
  471. #define FXAA_QUALITY__P5 2.0
  472. #define FXAA_QUALITY__P6 4.0
  473. #define FXAA_QUALITY__P7 8.0
  474. #endif
  475. /*--------------------------------------------------------------------------*/
  476. #if (FXAA_QUALITY__PRESET == 26)
  477. #define FXAA_QUALITY__PS 9
  478. #define FXAA_QUALITY__P0 1.0
  479. #define FXAA_QUALITY__P1 1.5
  480. #define FXAA_QUALITY__P2 2.0
  481. #define FXAA_QUALITY__P3 2.0
  482. #define FXAA_QUALITY__P4 2.0
  483. #define FXAA_QUALITY__P5 2.0
  484. #define FXAA_QUALITY__P6 2.0
  485. #define FXAA_QUALITY__P7 4.0
  486. #define FXAA_QUALITY__P8 8.0
  487. #endif
  488. /*--------------------------------------------------------------------------*/
  489. #if (FXAA_QUALITY__PRESET == 27)
  490. #define FXAA_QUALITY__PS 10
  491. #define FXAA_QUALITY__P0 1.0
  492. #define FXAA_QUALITY__P1 1.5
  493. #define FXAA_QUALITY__P2 2.0
  494. #define FXAA_QUALITY__P3 2.0
  495. #define FXAA_QUALITY__P4 2.0
  496. #define FXAA_QUALITY__P5 2.0
  497. #define FXAA_QUALITY__P6 2.0
  498. #define FXAA_QUALITY__P7 2.0
  499. #define FXAA_QUALITY__P8 4.0
  500. #define FXAA_QUALITY__P9 8.0
  501. #endif
  502. /*--------------------------------------------------------------------------*/
  503. #if (FXAA_QUALITY__PRESET == 28)
  504. #define FXAA_QUALITY__PS 11
  505. #define FXAA_QUALITY__P0 1.0
  506. #define FXAA_QUALITY__P1 1.5
  507. #define FXAA_QUALITY__P2 2.0
  508. #define FXAA_QUALITY__P3 2.0
  509. #define FXAA_QUALITY__P4 2.0
  510. #define FXAA_QUALITY__P5 2.0
  511. #define FXAA_QUALITY__P6 2.0
  512. #define FXAA_QUALITY__P7 2.0
  513. #define FXAA_QUALITY__P8 2.0
  514. #define FXAA_QUALITY__P9 4.0
  515. #define FXAA_QUALITY__P10 8.0
  516. #endif
  517. /*--------------------------------------------------------------------------*/
  518. #if (FXAA_QUALITY__PRESET == 29)
  519. #define FXAA_QUALITY__PS 12
  520. #define FXAA_QUALITY__P0 1.0
  521. #define FXAA_QUALITY__P1 1.5
  522. #define FXAA_QUALITY__P2 2.0
  523. #define FXAA_QUALITY__P3 2.0
  524. #define FXAA_QUALITY__P4 2.0
  525. #define FXAA_QUALITY__P5 2.0
  526. #define FXAA_QUALITY__P6 2.0
  527. #define FXAA_QUALITY__P7 2.0
  528. #define FXAA_QUALITY__P8 2.0
  529. #define FXAA_QUALITY__P9 2.0
  530. #define FXAA_QUALITY__P10 4.0
  531. #define FXAA_QUALITY__P11 8.0
  532. #endif
  533. /*============================================================================
  534. FXAA QUALITY - EXTREME QUALITY
  535. ============================================================================*/
  536. #if (FXAA_QUALITY__PRESET == 39)
  537. #define FXAA_QUALITY__PS 12
  538. #define FXAA_QUALITY__P0 1.0
  539. #define FXAA_QUALITY__P1 1.0
  540. #define FXAA_QUALITY__P2 1.0
  541. #define FXAA_QUALITY__P3 1.0
  542. #define FXAA_QUALITY__P4 1.0
  543. #define FXAA_QUALITY__P5 1.5
  544. #define FXAA_QUALITY__P6 2.0
  545. #define FXAA_QUALITY__P7 2.0
  546. #define FXAA_QUALITY__P8 2.0
  547. #define FXAA_QUALITY__P9 2.0
  548. #define FXAA_QUALITY__P10 4.0
  549. #define FXAA_QUALITY__P11 8.0
  550. #endif
  551. /*============================================================================
  552. API PORTING
  553. ============================================================================*/
  554. #if (FXAA_GLSL_120 == 1) || (FXAA_GLSL_130 == 1)
  555. #define FxaaBool bool
  556. #define FxaaDiscard discard
  557. #define FxaaFloat float
  558. #define FxaaFloat2 vec2
  559. #define FxaaFloat3 vec3
  560. #define FxaaFloat4 vec4
  561. #define FxaaHalf float
  562. #define FxaaHalf2 vec2
  563. #define FxaaHalf3 vec3
  564. #define FxaaHalf4 vec4
  565. #define FxaaInt2 ivec2
  566. #define FxaaSat(x) clamp(x, 0.0, 1.0)
  567. #define FxaaTex sampler2D
  568. #else
  569. #define FxaaBool bool
  570. #define FxaaDiscard clip(-1)
  571. #define FxaaFloat float
  572. #define FxaaFloat2 float2
  573. #define FxaaFloat3 float3
  574. #define FxaaFloat4 float4
  575. #define FxaaHalf half
  576. #define FxaaHalf2 half2
  577. #define FxaaHalf3 half3
  578. #define FxaaHalf4 half4
  579. #define FxaaSat(x) saturate(x)
  580. #endif
  581. /*--------------------------------------------------------------------------*/
  582. #if (FXAA_GLSL_120 == 1)
  583. // Requires,
  584. // #version 120
  585. // And at least,
  586. // #extension GL_EXT_gpu_shader4 : enable
  587. // (or set FXAA_FAST_PIXEL_OFFSET 1 to work like DX9)
  588. #define FxaaTexTop(t, p) texture2DLod(t, UnityStereoTransformScreenSpaceTex(p), 0.0)
  589. #if (FXAA_FAST_PIXEL_OFFSET == 1)
  590. #define FxaaTexOff(t, p, o, r) texture2DLodOffset(t, UnityStereoTransformScreenSpaceTex(p), 0.0, o)
  591. #else
  592. #define FxaaTexOff(t, p, o, r) texture2DLod(t, UnityStereoTransformScreenSpaceTex(p + (o * r)), 0.0)
  593. #endif
  594. #if (FXAA_GATHER4_ALPHA == 1)
  595. // use #extension GL_ARB_gpu_shader5 : enable
  596. #define FxaaTexAlpha4(t, p) textureGather(t, UnityStereoTransformScreenSpaceTex(p), 3)
  597. #define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, UnityStereoTransformScreenSpaceTex(p), o, 3)
  598. #define FxaaTexGreen4(t, p) textureGather(t, UnityStereoTransformScreenSpaceTex(p), 1)
  599. #define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, UnityStereoTransformScreenSpaceTex(p), o, 1)
  600. #endif
  601. #endif
  602. /*--------------------------------------------------------------------------*/
  603. #if (FXAA_GLSL_130 == 1)
  604. // Requires "#version 130" or better
  605. #define FxaaTexTop(t, p) textureLod(t, UnityStereoTransformScreenSpaceTex(p), 0.0)
  606. #define FxaaTexOff(t, p, o, r) textureLodOffset(t, UnityStereoTransformScreenSpaceTex(p), 0.0, o)
  607. #if (FXAA_GATHER4_ALPHA == 1)
  608. // use #extension GL_ARB_gpu_shader5 : enable
  609. #define FxaaTexAlpha4(t, p) textureGather(t, UnityStereoTransformScreenSpaceTex(p), 3)
  610. #define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, UnityStereoTransformScreenSpaceTex(p), o, 3)
  611. #define FxaaTexGreen4(t, p) textureGather(t, UnityStereoTransformScreenSpaceTex(p), 1)
  612. #define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, UnityStereoTransformScreenSpaceTex(p), o, 1)
  613. #endif
  614. #endif
  615. /*--------------------------------------------------------------------------*/
  616. #if (FXAA_HLSL_3 == 1) || (FXAA_360 == 1) || (FXAA_PS3 == 1)
  617. #define FxaaInt2 float2
  618. #define FxaaTex sampler2D
  619. #define FxaaTexTop(t, p) tex2Dlod(t, float4(UnityStereoTransformScreenSpaceTex(p), 0.0, 0.0))
  620. #define FxaaTexOff(t, p, o, r) tex2Dlod(t, float4(UnityStereoTransformScreenSpaceTex(p + (o * r)), 0, 0))
  621. #endif
  622. /*--------------------------------------------------------------------------*/
  623. #if (FXAA_HLSL_4 == 1)
  624. #define FxaaInt2 int2
  625. struct FxaaTex { SamplerState smpl; Texture2D tex; };
  626. #define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, UnityStereoTransformScreenSpaceTex(p), 0.0)
  627. #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, UnityStereoTransformScreenSpaceTex(p), 0.0, o)
  628. #endif
  629. /*--------------------------------------------------------------------------*/
  630. #if (FXAA_HLSL_5 == 1)
  631. #define FxaaInt2 int2
  632. struct FxaaTex { SamplerState smpl; Texture2D tex; };
  633. #define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, UnityStereoTransformScreenSpaceTex(p), 0.0)
  634. #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, UnityStereoTransformScreenSpaceTex(p), 0.0, o)
  635. #define FxaaTexAlpha4(t, p) t.tex.GatherAlpha(t.smpl, UnityStereoTransformScreenSpaceTex(p))
  636. #define FxaaTexOffAlpha4(t, p, o) t.tex.GatherAlpha(t.smpl, UnityStereoTransformScreenSpaceTex(p), o)
  637. #define FxaaTexGreen4(t, p) t.tex.GatherGreen(t.smpl, UnityStereoTransformScreenSpaceTex(p))
  638. #define FxaaTexOffGreen4(t, p, o) t.tex.GatherGreen(t.smpl, UnityStereoTransformScreenSpaceTex(p), o)
  639. #endif
  640. /*============================================================================
  641. GREEN AS LUMA OPTION SUPPORT FUNCTION
  642. ============================================================================*/
  643. #if (FXAA_GREEN_AS_LUMA == 0)
  644. FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.w; }
  645. #else
  646. FxaaFloat FxaaLuma(FxaaFloat4 rgba) { return rgba.y; }
  647. #endif
  648. /*============================================================================
  649. FXAA3 QUALITY - PC
  650. ============================================================================*/
  651. #if (FXAA_PC == 1)
  652. /*--------------------------------------------------------------------------*/
  653. FxaaFloat4 FxaaPixelShader(
  654. //
  655. // Use noperspective interpolation here (turn off perspective interpolation).
  656. // {xy} = center of pixel
  657. FxaaFloat2 pos,
  658. //
  659. // Used only for FXAA Console, and not used on the 360 version.
  660. // Use noperspective interpolation here (turn off perspective interpolation).
  661. // {xy__} = upper left of pixel
  662. // {__zw} = lower right of pixel
  663. FxaaFloat4 fxaaConsolePosPos,
  664. //
  665. // Input color texture.
  666. // {rgb_} = color in linear or perceptual color space
  667. // if (FXAA_GREEN_AS_LUMA == 0)
  668. // {___a} = luma in perceptual color space (not linear)
  669. FxaaTex tex,
  670. //
  671. // Only used on the optimized 360 version of FXAA Console.
  672. // For everything but 360, just use the same input here as for "tex".
  673. // For 360, same texture, just alias with a 2nd sampler.
  674. // This sampler needs to have an exponent bias of -1.
  675. FxaaTex fxaaConsole360TexExpBiasNegOne,
  676. //
  677. // Only used on the optimized 360 version of FXAA Console.
  678. // For everything but 360, just use the same input here as for "tex".
  679. // For 360, same texture, just alias with a 3nd sampler.
  680. // This sampler needs to have an exponent bias of -2.
  681. FxaaTex fxaaConsole360TexExpBiasNegTwo,
  682. //
  683. // Only used on FXAA Quality.
  684. // This must be from a constant/uniform.
  685. // {x_} = 1.0/screenWidthInPixels
  686. // {_y} = 1.0/screenHeightInPixels
  687. FxaaFloat2 fxaaQualityRcpFrame,
  688. //
  689. // Only used on FXAA Console.
  690. // This must be from a constant/uniform.
  691. // This effects sub-pixel AA quality and inversely sharpness.
  692. // Where N ranges between,
  693. // N = 0.50 (default)
  694. // N = 0.33 (sharper)
  695. // {x___} = -N/screenWidthInPixels
  696. // {_y__} = -N/screenHeightInPixels
  697. // {__z_} = N/screenWidthInPixels
  698. // {___w} = N/screenHeightInPixels
  699. FxaaFloat4 fxaaConsoleRcpFrameOpt,
  700. //
  701. // Only used on FXAA Console.
  702. // Not used on 360, but used on PS3 and PC.
  703. // This must be from a constant/uniform.
  704. // {x___} = -2.0/screenWidthInPixels
  705. // {_y__} = -2.0/screenHeightInPixels
  706. // {__z_} = 2.0/screenWidthInPixels
  707. // {___w} = 2.0/screenHeightInPixels
  708. FxaaFloat4 fxaaConsoleRcpFrameOpt2,
  709. //
  710. // Only used on FXAA Console.
  711. // Only used on 360 in place of fxaaConsoleRcpFrameOpt2.
  712. // This must be from a constant/uniform.
  713. // {x___} = 8.0/screenWidthInPixels
  714. // {_y__} = 8.0/screenHeightInPixels
  715. // {__z_} = -4.0/screenWidthInPixels
  716. // {___w} = -4.0/screenHeightInPixels
  717. FxaaFloat4 fxaaConsole360RcpFrameOpt2,
  718. //
  719. // Only used on FXAA Quality.
  720. // This used to be the FXAA_QUALITY__SUBPIX define.
  721. // It is here now to allow easier tuning.
  722. // Choose the amount of sub-pixel aliasing removal.
  723. // This can effect sharpness.
  724. // 1.00 - upper limit (softer)
  725. // 0.75 - default amount of filtering
  726. // 0.50 - lower limit (sharper, less sub-pixel aliasing removal)
  727. // 0.25 - almost off
  728. // 0.00 - completely off
  729. FxaaFloat fxaaQualitySubpix,
  730. //
  731. // Only used on FXAA Quality.
  732. // This used to be the FXAA_QUALITY__EDGE_THRESHOLD define.
  733. // It is here now to allow easier tuning.
  734. // The minimum amount of local contrast required to apply algorithm.
  735. // 0.333 - too little (faster)
  736. // 0.250 - low quality
  737. // 0.166 - default
  738. // 0.125 - high quality
  739. // 0.063 - overkill (slower)
  740. FxaaFloat fxaaQualityEdgeThreshold,
  741. //
  742. // Only used on FXAA Quality.
  743. // This used to be the FXAA_QUALITY__EDGE_THRESHOLD_MIN define.
  744. // It is here now to allow easier tuning.
  745. // Trims the algorithm from processing darks.
  746. // 0.0833 - upper limit (default, the start of visible unfiltered edges)
  747. // 0.0625 - high quality (faster)
  748. // 0.0312 - visible limit (slower)
  749. // Special notes when using FXAA_GREEN_AS_LUMA,
  750. // Likely want to set this to zero.
  751. // As colors that are mostly not-green
  752. // will appear very dark in the green channel!
  753. // Tune by looking at mostly non-green content,
  754. // then start at zero and increase until aliasing is a problem.
  755. FxaaFloat fxaaQualityEdgeThresholdMin,
  756. //
  757. // Only used on FXAA Console.
  758. // This used to be the FXAA_CONSOLE__EDGE_SHARPNESS define.
  759. // It is here now to allow easier tuning.
  760. // This does not effect PS3, as this needs to be compiled in.
  761. // Use FXAA_CONSOLE__PS3_EDGE_SHARPNESS for PS3.
  762. // Due to the PS3 being ALU bound,
  763. // there are only three safe values here: 2 and 4 and 8.
  764. // These options use the shaders ability to a free *|/ by 2|4|8.
  765. // For all other platforms can be a non-power of two.
  766. // 8.0 is sharper (default!!!)
  767. // 4.0 is softer
  768. // 2.0 is really soft (good only for vector graphics inputs)
  769. FxaaFloat fxaaConsoleEdgeSharpness,
  770. //
  771. // Only used on FXAA Console.
  772. // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD define.
  773. // It is here now to allow easier tuning.
  774. // This does not effect PS3, as this needs to be compiled in.
  775. // Use FXAA_CONSOLE__PS3_EDGE_THRESHOLD for PS3.
  776. // Due to the PS3 being ALU bound,
  777. // there are only two safe values here: 1/4 and 1/8.
  778. // These options use the shaders ability to a free *|/ by 2|4|8.
  779. // The console setting has a different mapping than the quality setting.
  780. // Other platforms can use other values.
  781. // 0.125 leaves less aliasing, but is softer (default!!!)
  782. // 0.25 leaves more aliasing, and is sharper
  783. FxaaFloat fxaaConsoleEdgeThreshold,
  784. //
  785. // Only used on FXAA Console.
  786. // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD_MIN define.
  787. // It is here now to allow easier tuning.
  788. // Trims the algorithm from processing darks.
  789. // The console setting has a different mapping than the quality setting.
  790. // This only applies when FXAA_EARLY_EXIT is 1.
  791. // This does not apply to PS3,
  792. // PS3 was simplified to avoid more shader instructions.
  793. // 0.06 - faster but more aliasing in darks
  794. // 0.05 - default
  795. // 0.04 - slower and less aliasing in darks
  796. // Special notes when using FXAA_GREEN_AS_LUMA,
  797. // Likely want to set this to zero.
  798. // As colors that are mostly not-green
  799. // will appear very dark in the green channel!
  800. // Tune by looking at mostly non-green content,
  801. // then start at zero and increase until aliasing is a problem.
  802. FxaaFloat fxaaConsoleEdgeThresholdMin,
  803. //
  804. // Extra constants for 360 FXAA Console only.
  805. // Use zeros or anything else for other platforms.
  806. // These must be in physical constant registers and NOT immedates.
  807. // Immedates will result in compiler un-optimizing.
  808. // {xyzw} = float4(1.0, -1.0, 0.25, -0.25)
  809. FxaaFloat4 fxaaConsole360ConstDir
  810. ) {
  811. /*--------------------------------------------------------------------------*/
  812. FxaaFloat2 posM;
  813. posM.x = pos.x;
  814. posM.y = pos.y;
  815. #if (FXAA_GATHER4_ALPHA == 1)
  816. #if (FXAA_DISCARD == 0)
  817. FxaaFloat4 rgbyM = FxaaTexTop(tex, posM);
  818. #if (FXAA_GREEN_AS_LUMA == 0)
  819. #define lumaM rgbyM.w
  820. #else
  821. #define lumaM rgbyM.y
  822. #endif
  823. #endif
  824. #if (FXAA_GREEN_AS_LUMA == 0)
  825. FxaaFloat4 luma4A = FxaaTexAlpha4(tex, posM);
  826. FxaaFloat4 luma4B = FxaaTexOffAlpha4(tex, posM, FxaaInt2(-1, -1));
  827. #else
  828. FxaaFloat4 luma4A = FxaaTexGreen4(tex, posM);
  829. FxaaFloat4 luma4B = FxaaTexOffGreen4(tex, posM, FxaaInt2(-1, -1));
  830. #endif
  831. #if (FXAA_DISCARD == 1)
  832. #define lumaM luma4A.w
  833. #endif
  834. #define lumaE luma4A.z
  835. #define lumaS luma4A.x
  836. #define lumaSE luma4A.y
  837. #define lumaNW luma4B.w
  838. #define lumaN luma4B.z
  839. #define lumaW luma4B.x
  840. #else
  841. FxaaFloat4 rgbyM = FxaaTexTop(tex, posM);
  842. #if (FXAA_GREEN_AS_LUMA == 0)
  843. #define lumaM rgbyM.w
  844. #else
  845. #define lumaM rgbyM.y
  846. #endif
  847. FxaaFloat lumaS = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(0, 1), fxaaQualityRcpFrame.xy));
  848. FxaaFloat lumaE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(1, 0), fxaaQualityRcpFrame.xy));
  849. FxaaFloat lumaN = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(0, -1), fxaaQualityRcpFrame.xy));
  850. FxaaFloat lumaW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 0), fxaaQualityRcpFrame.xy));
  851. #endif
  852. /*--------------------------------------------------------------------------*/
  853. FxaaFloat maxSM = max(lumaS, lumaM);
  854. FxaaFloat minSM = min(lumaS, lumaM);
  855. FxaaFloat maxESM = max(lumaE, maxSM);
  856. FxaaFloat minESM = min(lumaE, minSM);
  857. FxaaFloat maxWN = max(lumaN, lumaW);
  858. FxaaFloat minWN = min(lumaN, lumaW);
  859. FxaaFloat rangeMax = max(maxWN, maxESM);
  860. FxaaFloat rangeMin = min(minWN, minESM);
  861. FxaaFloat rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;
  862. FxaaFloat range = rangeMax - rangeMin;
  863. FxaaFloat rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);
  864. FxaaBool earlyExit = range < rangeMaxClamped;
  865. /*--------------------------------------------------------------------------*/
  866. if (earlyExit)
  867. #if (FXAA_DISCARD == 1)
  868. FxaaDiscard;
  869. #else
  870. return rgbyM;
  871. #endif
  872. /*--------------------------------------------------------------------------*/
  873. #if (FXAA_GATHER4_ALPHA == 0)
  874. FxaaFloat lumaNW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, -1), fxaaQualityRcpFrame.xy));
  875. FxaaFloat lumaSE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(1, 1), fxaaQualityRcpFrame.xy));
  876. FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(1, -1), fxaaQualityRcpFrame.xy));
  877. FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy));
  878. #else
  879. FxaaFloat lumaNE = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(1, -1), fxaaQualityRcpFrame.xy));
  880. FxaaFloat lumaSW = FxaaLuma(FxaaTexOff(tex, posM, FxaaInt2(-1, 1), fxaaQualityRcpFrame.xy));
  881. #endif
  882. /*--------------------------------------------------------------------------*/
  883. FxaaFloat lumaNS = lumaN + lumaS;
  884. FxaaFloat lumaWE = lumaW + lumaE;
  885. FxaaFloat subpixRcpRange = 1.0 / range;
  886. FxaaFloat subpixNSWE = lumaNS + lumaWE;
  887. FxaaFloat edgeHorz1 = (-2.0 * lumaM) + lumaNS;
  888. FxaaFloat edgeVert1 = (-2.0 * lumaM) + lumaWE;
  889. /*--------------------------------------------------------------------------*/
  890. FxaaFloat lumaNESE = lumaNE + lumaSE;
  891. FxaaFloat lumaNWNE = lumaNW + lumaNE;
  892. FxaaFloat edgeHorz2 = (-2.0 * lumaE) + lumaNESE;
  893. FxaaFloat edgeVert2 = (-2.0 * lumaN) + lumaNWNE;
  894. /*--------------------------------------------------------------------------*/
  895. FxaaFloat lumaNWSW = lumaNW + lumaSW;
  896. FxaaFloat lumaSWSE = lumaSW + lumaSE;
  897. FxaaFloat edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);
  898. FxaaFloat edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);
  899. FxaaFloat edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;
  900. FxaaFloat edgeVert3 = (-2.0 * lumaS) + lumaSWSE;
  901. FxaaFloat edgeHorz = abs(edgeHorz3) + edgeHorz4;
  902. FxaaFloat edgeVert = abs(edgeVert3) + edgeVert4;
  903. /*--------------------------------------------------------------------------*/
  904. FxaaFloat subpixNWSWNESE = lumaNWSW + lumaNESE;
  905. FxaaFloat lengthSign = fxaaQualityRcpFrame.x;
  906. FxaaBool horzSpan = edgeHorz >= edgeVert;
  907. FxaaFloat subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;
  908. /*--------------------------------------------------------------------------*/
  909. if (!horzSpan) lumaN = lumaW;
  910. if (!horzSpan) lumaS = lumaE;
  911. if (horzSpan) lengthSign = fxaaQualityRcpFrame.y;
  912. FxaaFloat subpixB = (subpixA * (1.0 / 12.0)) - lumaM;
  913. /*--------------------------------------------------------------------------*/
  914. FxaaFloat gradientN = lumaN - lumaM;
  915. FxaaFloat gradientS = lumaS - lumaM;
  916. FxaaFloat lumaNN = lumaN + lumaM;
  917. FxaaFloat lumaSS = lumaS + lumaM;
  918. FxaaBool pairN = abs(gradientN) >= abs(gradientS);
  919. FxaaFloat gradient = max(abs(gradientN), abs(gradientS));
  920. if (pairN) lengthSign = -lengthSign;
  921. FxaaFloat subpixC = FxaaSat(abs(subpixB) * subpixRcpRange);
  922. /*--------------------------------------------------------------------------*/
  923. FxaaFloat2 posB;
  924. posB.x = posM.x;
  925. posB.y = posM.y;
  926. FxaaFloat2 offNP;
  927. offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;
  928. offNP.y = (horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;
  929. if (!horzSpan) posB.x += lengthSign * 0.5;
  930. if (horzSpan) posB.y += lengthSign * 0.5;
  931. /*--------------------------------------------------------------------------*/
  932. FxaaFloat2 posN;
  933. posN.x = posB.x - offNP.x * FXAA_QUALITY__P0;
  934. posN.y = posB.y - offNP.y * FXAA_QUALITY__P0;
  935. FxaaFloat2 posP;
  936. posP.x = posB.x + offNP.x * FXAA_QUALITY__P0;
  937. posP.y = posB.y + offNP.y * FXAA_QUALITY__P0;
  938. FxaaFloat subpixD = ((-2.0)*subpixC) + 3.0;
  939. FxaaFloat lumaEndN = FxaaLuma(FxaaTexTop(tex, posN));
  940. FxaaFloat subpixE = subpixC * subpixC;
  941. FxaaFloat lumaEndP = FxaaLuma(FxaaTexTop(tex, posP));
  942. /*--------------------------------------------------------------------------*/
  943. if (!pairN) lumaNN = lumaSS;
  944. FxaaFloat gradientScaled = gradient * 1.0 / 4.0;
  945. FxaaFloat lumaMM = lumaM - lumaNN * 0.5;
  946. FxaaFloat subpixF = subpixD * subpixE;
  947. FxaaBool lumaMLTZero = lumaMM < 0.0;
  948. /*--------------------------------------------------------------------------*/
  949. lumaEndN -= lumaNN * 0.5;
  950. lumaEndP -= lumaNN * 0.5;
  951. FxaaBool doneN = abs(lumaEndN) >= gradientScaled;
  952. FxaaBool doneP = abs(lumaEndP) >= gradientScaled;
  953. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P1;
  954. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P1;
  955. FxaaBool doneNP = (!doneN) || (!doneP);
  956. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P1;
  957. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P1;
  958. /*--------------------------------------------------------------------------*/
  959. if (doneNP)
  960. {
  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__P2;
  968. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P2;
  969. doneNP = (!doneN) || (!doneP);
  970. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P2;
  971. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P2;
  972. /*--------------------------------------------------------------------------*/
  973. #if (FXAA_QUALITY__PS > 3)
  974. if (doneNP)
  975. {
  976. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  977. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  978. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  979. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  980. doneN = abs(lumaEndN) >= gradientScaled;
  981. doneP = abs(lumaEndP) >= gradientScaled;
  982. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P3;
  983. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P3;
  984. doneNP = (!doneN) || (!doneP);
  985. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P3;
  986. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P3;
  987. /*--------------------------------------------------------------------------*/
  988. #if (FXAA_QUALITY__PS > 4)
  989. if (doneNP)
  990. {
  991. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  992. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  993. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  994. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  995. doneN = abs(lumaEndN) >= gradientScaled;
  996. doneP = abs(lumaEndP) >= gradientScaled;
  997. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P4;
  998. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P4;
  999. doneNP = (!doneN) || (!doneP);
  1000. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P4;
  1001. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P4;
  1002. /*--------------------------------------------------------------------------*/
  1003. #if (FXAA_QUALITY__PS > 5)
  1004. if (doneNP)
  1005. {
  1006. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  1007. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  1008. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  1009. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  1010. doneN = abs(lumaEndN) >= gradientScaled;
  1011. doneP = abs(lumaEndP) >= gradientScaled;
  1012. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P5;
  1013. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P5;
  1014. doneNP = (!doneN) || (!doneP);
  1015. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P5;
  1016. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P5;
  1017. /*--------------------------------------------------------------------------*/
  1018. #if (FXAA_QUALITY__PS > 6)
  1019. if (doneNP)
  1020. {
  1021. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  1022. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  1023. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  1024. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  1025. doneN = abs(lumaEndN) >= gradientScaled;
  1026. doneP = abs(lumaEndP) >= gradientScaled;
  1027. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P6;
  1028. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P6;
  1029. doneNP = (!doneN) || (!doneP);
  1030. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P6;
  1031. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P6;
  1032. /*--------------------------------------------------------------------------*/
  1033. #if (FXAA_QUALITY__PS > 7)
  1034. if (doneNP)
  1035. {
  1036. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  1037. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  1038. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  1039. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  1040. doneN = abs(lumaEndN) >= gradientScaled;
  1041. doneP = abs(lumaEndP) >= gradientScaled;
  1042. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P7;
  1043. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P7;
  1044. doneNP = (!doneN) || (!doneP);
  1045. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P7;
  1046. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P7;
  1047. /*--------------------------------------------------------------------------*/
  1048. #if (FXAA_QUALITY__PS > 8)
  1049. if (doneNP)
  1050. {
  1051. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  1052. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  1053. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  1054. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  1055. doneN = abs(lumaEndN) >= gradientScaled;
  1056. doneP = abs(lumaEndP) >= gradientScaled;
  1057. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P8;
  1058. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P8;
  1059. doneNP = (!doneN) || (!doneP);
  1060. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P8;
  1061. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P8;
  1062. /*--------------------------------------------------------------------------*/
  1063. #if (FXAA_QUALITY__PS > 9)
  1064. if (doneNP)
  1065. {
  1066. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  1067. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  1068. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  1069. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  1070. doneN = abs(lumaEndN) >= gradientScaled;
  1071. doneP = abs(lumaEndP) >= gradientScaled;
  1072. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P9;
  1073. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P9;
  1074. doneNP = (!doneN) || (!doneP);
  1075. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P9;
  1076. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P9;
  1077. /*--------------------------------------------------------------------------*/
  1078. #if (FXAA_QUALITY__PS > 10)
  1079. if (doneNP)
  1080. {
  1081. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  1082. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  1083. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  1084. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  1085. doneN = abs(lumaEndN) >= gradientScaled;
  1086. doneP = abs(lumaEndP) >= gradientScaled;
  1087. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P10;
  1088. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P10;
  1089. doneNP = (!doneN) || (!doneP);
  1090. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P10;
  1091. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P10;
  1092. /*--------------------------------------------------------------------------*/
  1093. #if (FXAA_QUALITY__PS > 11)
  1094. if (doneNP)
  1095. {
  1096. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  1097. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  1098. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  1099. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  1100. doneN = abs(lumaEndN) >= gradientScaled;
  1101. doneP = abs(lumaEndP) >= gradientScaled;
  1102. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P11;
  1103. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P11;
  1104. doneNP = (!doneN) || (!doneP);
  1105. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P11;
  1106. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P11;
  1107. /*--------------------------------------------------------------------------*/
  1108. #if (FXAA_QUALITY__PS > 12)
  1109. if (doneNP)
  1110. {
  1111. if (!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
  1112. if (!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
  1113. if (!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
  1114. if (!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
  1115. doneN = abs(lumaEndN) >= gradientScaled;
  1116. doneP = abs(lumaEndP) >= gradientScaled;
  1117. if (!doneN) posN.x -= offNP.x * FXAA_QUALITY__P12;
  1118. if (!doneN) posN.y -= offNP.y * FXAA_QUALITY__P12;
  1119. doneNP = (!doneN) || (!doneP);
  1120. if (!doneP) posP.x += offNP.x * FXAA_QUALITY__P12;
  1121. if (!doneP) posP.y += offNP.y * FXAA_QUALITY__P12;
  1122. /*--------------------------------------------------------------------------*/
  1123. }
  1124. #endif
  1125. /*--------------------------------------------------------------------------*/
  1126. }
  1127. #endif
  1128. /*--------------------------------------------------------------------------*/
  1129. }
  1130. #endif
  1131. /*--------------------------------------------------------------------------*/
  1132. }
  1133. #endif
  1134. /*--------------------------------------------------------------------------*/
  1135. }
  1136. #endif
  1137. /*--------------------------------------------------------------------------*/
  1138. }
  1139. #endif
  1140. /*--------------------------------------------------------------------------*/
  1141. }
  1142. #endif
  1143. /*--------------------------------------------------------------------------*/
  1144. }
  1145. #endif
  1146. /*--------------------------------------------------------------------------*/
  1147. }
  1148. #endif
  1149. /*--------------------------------------------------------------------------*/
  1150. }
  1151. #endif
  1152. /*--------------------------------------------------------------------------*/
  1153. }
  1154. /*--------------------------------------------------------------------------*/
  1155. FxaaFloat dstN = posM.x - posN.x;
  1156. FxaaFloat dstP = posP.x - posM.x;
  1157. if (!horzSpan) dstN = posM.y - posN.y;
  1158. if (!horzSpan) dstP = posP.y - posM.y;
  1159. /*--------------------------------------------------------------------------*/
  1160. FxaaBool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;
  1161. FxaaFloat spanLength = (dstP + dstN);
  1162. FxaaBool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;
  1163. FxaaFloat spanLengthRcp = 1.0 / spanLength;
  1164. /*--------------------------------------------------------------------------*/
  1165. FxaaBool directionN = dstN < dstP;
  1166. FxaaFloat dst = min(dstN, dstP);
  1167. FxaaBool goodSpan = directionN ? goodSpanN : goodSpanP;
  1168. FxaaFloat subpixG = subpixF * subpixF;
  1169. FxaaFloat pixelOffset = (dst * (-spanLengthRcp)) + 0.5;
  1170. FxaaFloat subpixH = subpixG * fxaaQualitySubpix;
  1171. /*--------------------------------------------------------------------------*/
  1172. FxaaFloat pixelOffsetGood = goodSpan ? pixelOffset : 0.0;
  1173. FxaaFloat pixelOffsetSubpix = max(pixelOffsetGood, subpixH);
  1174. if (!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;
  1175. if (horzSpan) posM.y += pixelOffsetSubpix * lengthSign;
  1176. #if (FXAA_DISCARD == 1)
  1177. return FxaaTexTop(tex, posM);
  1178. #else
  1179. return FxaaFloat4(FxaaTexTop(tex, posM).xyz, lumaM);
  1180. #endif
  1181. }
  1182. /*==========================================================================*/
  1183. #endif
  1184. /*============================================================================
  1185. FXAA3 CONSOLE - PC VERSION
  1186. ------------------------------------------------------------------------------
  1187. Instead of using this on PC, I'd suggest just using FXAA Quality with
  1188. #define FXAA_QUALITY__PRESET 10
  1189. Or
  1190. #define FXAA_QUALITY__PRESET 20
  1191. Either are higher qualilty and almost as fast as this on modern PC GPUs.
  1192. ============================================================================*/
  1193. #if (FXAA_PC_CONSOLE == 1)
  1194. /*--------------------------------------------------------------------------*/
  1195. FxaaFloat4 FxaaPixelShader(
  1196. // See FXAA Quality FxaaPixelShader() source for docs on Inputs!
  1197. FxaaFloat2 pos,
  1198. FxaaFloat4 fxaaConsolePosPos,
  1199. FxaaTex tex,
  1200. FxaaTex fxaaConsole360TexExpBiasNegOne,
  1201. FxaaTex fxaaConsole360TexExpBiasNegTwo,
  1202. FxaaFloat2 fxaaQualityRcpFrame,
  1203. FxaaFloat4 fxaaConsoleRcpFrameOpt,
  1204. FxaaFloat4 fxaaConsoleRcpFrameOpt2,
  1205. FxaaFloat4 fxaaConsole360RcpFrameOpt2,
  1206. FxaaFloat fxaaQualitySubpix,
  1207. FxaaFloat fxaaQualityEdgeThreshold,
  1208. FxaaFloat fxaaQualityEdgeThresholdMin,
  1209. FxaaFloat fxaaConsoleEdgeSharpness,
  1210. FxaaFloat fxaaConsoleEdgeThreshold,
  1211. FxaaFloat fxaaConsoleEdgeThresholdMin,
  1212. FxaaFloat4 fxaaConsole360ConstDir
  1213. )
  1214. {
  1215. /*--------------------------------------------------------------------------*/
  1216. FxaaFloat lumaNw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xy));
  1217. FxaaFloat lumaSw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xw));
  1218. FxaaFloat lumaNe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zy));
  1219. FxaaFloat lumaSe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zw));
  1220. /*--------------------------------------------------------------------------*/
  1221. FxaaFloat4 rgbyM = FxaaTexTop(tex, pos.xy);
  1222. #if (FXAA_GREEN_AS_LUMA == 0)
  1223. FxaaFloat lumaM = rgbyM.w;
  1224. #else
  1225. FxaaFloat lumaM = rgbyM.y;
  1226. #endif
  1227. /*--------------------------------------------------------------------------*/
  1228. FxaaFloat lumaMaxNwSw = max(lumaNw, lumaSw);
  1229. lumaNe += 1.0 / 384.0;
  1230. FxaaFloat lumaMinNwSw = min(lumaNw, lumaSw);
  1231. /*--------------------------------------------------------------------------*/
  1232. FxaaFloat lumaMaxNeSe = max(lumaNe, lumaSe);
  1233. FxaaFloat lumaMinNeSe = min(lumaNe, lumaSe);
  1234. /*--------------------------------------------------------------------------*/
  1235. FxaaFloat lumaMax = max(lumaMaxNeSe, lumaMaxNwSw);
  1236. FxaaFloat lumaMin = min(lumaMinNeSe, lumaMinNwSw);
  1237. /*--------------------------------------------------------------------------*/
  1238. FxaaFloat lumaMaxScaled = lumaMax * fxaaConsoleEdgeThreshold;
  1239. /*--------------------------------------------------------------------------*/
  1240. FxaaFloat lumaMinM = min(lumaMin, lumaM);
  1241. FxaaFloat lumaMaxScaledClamped = max(fxaaConsoleEdgeThresholdMin, lumaMaxScaled);
  1242. FxaaFloat lumaMaxM = max(lumaMax, lumaM);
  1243. FxaaFloat dirSwMinusNe = lumaSw - lumaNe;
  1244. FxaaFloat lumaMaxSubMinM = lumaMaxM - lumaMinM;
  1245. FxaaFloat dirSeMinusNw = lumaSe - lumaNw;
  1246. if (lumaMaxSubMinM < lumaMaxScaledClamped) return rgbyM;
  1247. /*--------------------------------------------------------------------------*/
  1248. FxaaFloat2 dir;
  1249. dir.x = dirSwMinusNe + dirSeMinusNw;
  1250. dir.y = dirSwMinusNe - dirSeMinusNw;
  1251. /*--------------------------------------------------------------------------*/
  1252. FxaaFloat2 dir1 = normalize(dir.xy);
  1253. FxaaFloat4 rgbyN1 = FxaaTexTop(tex, pos.xy - dir1 * fxaaConsoleRcpFrameOpt.zw);
  1254. FxaaFloat4 rgbyP1 = FxaaTexTop(tex, pos.xy + dir1 * fxaaConsoleRcpFrameOpt.zw);
  1255. /*--------------------------------------------------------------------------*/
  1256. FxaaFloat dirAbsMinTimesC = min(abs(dir1.x), abs(dir1.y)) * fxaaConsoleEdgeSharpness;
  1257. FxaaFloat2 dir2 = clamp(dir1.xy / dirAbsMinTimesC, -2.0, 2.0);
  1258. /*--------------------------------------------------------------------------*/
  1259. FxaaFloat4 rgbyN2 = FxaaTexTop(tex, pos.xy - dir2 * fxaaConsoleRcpFrameOpt2.zw);
  1260. FxaaFloat4 rgbyP2 = FxaaTexTop(tex, pos.xy + dir2 * fxaaConsoleRcpFrameOpt2.zw);
  1261. /*--------------------------------------------------------------------------*/
  1262. FxaaFloat4 rgbyA = rgbyN1 + rgbyP1;
  1263. FxaaFloat4 rgbyB = ((rgbyN2 + rgbyP2) * 0.25) + (rgbyA * 0.25);
  1264. /*--------------------------------------------------------------------------*/
  1265. #if (FXAA_GREEN_AS_LUMA == 0)
  1266. FxaaBool twoTap = (rgbyB.w < lumaMin) || (rgbyB.w > lumaMax);
  1267. #else
  1268. FxaaBool twoTap = (rgbyB.y < lumaMin) || (rgbyB.y > lumaMax);
  1269. #endif
  1270. if (twoTap) rgbyB.xyz = rgbyA.xyz * 0.5;
  1271. return rgbyB;
  1272. }
  1273. /*==========================================================================*/
  1274. #endif
  1275. /*============================================================================
  1276. FXAA3 CONSOLE - 360 PIXEL SHADER
  1277. ------------------------------------------------------------------------------
  1278. This optimized version thanks to suggestions from Andy Luedke.
  1279. Should be fully tex bound in all cases.
  1280. As of the FXAA 3.11 release, I have still not tested this code,
  1281. however I fixed a bug which was in both FXAA 3.9 and FXAA 3.10.
  1282. And note this is replacing the old unoptimized version.
  1283. If it does not work, please let me know so I can fix it.
  1284. ============================================================================*/
  1285. #if (FXAA_360 == 1)
  1286. /*--------------------------------------------------------------------------*/
  1287. [reduceTempRegUsage(4)]
  1288. float4 FxaaPixelShader(
  1289. // See FXAA Quality FxaaPixelShader() source for docs on Inputs!
  1290. FxaaFloat2 pos,
  1291. FxaaFloat4 fxaaConsolePosPos,
  1292. FxaaTex tex,
  1293. FxaaTex fxaaConsole360TexExpBiasNegOne,
  1294. FxaaTex fxaaConsole360TexExpBiasNegTwo,
  1295. FxaaFloat2 fxaaQualityRcpFrame,
  1296. FxaaFloat4 fxaaConsoleRcpFrameOpt,
  1297. FxaaFloat4 fxaaConsoleRcpFrameOpt2,
  1298. FxaaFloat4 fxaaConsole360RcpFrameOpt2,
  1299. FxaaFloat fxaaQualitySubpix,
  1300. FxaaFloat fxaaQualityEdgeThreshold,
  1301. FxaaFloat fxaaQualityEdgeThresholdMin,
  1302. FxaaFloat fxaaConsoleEdgeSharpness,
  1303. FxaaFloat fxaaConsoleEdgeThreshold,
  1304. FxaaFloat fxaaConsoleEdgeThresholdMin,
  1305. FxaaFloat4 fxaaConsole360ConstDir
  1306. )
  1307. {
  1308. /*--------------------------------------------------------------------------*/
  1309. float4 lumaNwNeSwSe;
  1310. #if (FXAA_GREEN_AS_LUMA == 0)
  1311. asm
  1312. {
  1313. tfetch2D lumaNwNeSwSe.w___, tex, pos.xy, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD = false
  1314. tfetch2D lumaNwNeSwSe._w__, tex, pos.xy, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD = false
  1315. tfetch2D lumaNwNeSwSe.__w_, tex, pos.xy, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD = false
  1316. tfetch2D lumaNwNeSwSe.___w, tex, pos.xy, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD = false
  1317. };
  1318. #else
  1319. asm
  1320. {
  1321. tfetch2D lumaNwNeSwSe.y___, tex, pos.xy, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD = false
  1322. tfetch2D lumaNwNeSwSe._y__, tex, pos.xy, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD = false
  1323. tfetch2D lumaNwNeSwSe.__y_, tex, pos.xy, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD = false
  1324. tfetch2D lumaNwNeSwSe.___y, tex, pos.xy, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD = false
  1325. };
  1326. #endif
  1327. /*--------------------------------------------------------------------------*/
  1328. lumaNwNeSwSe.y += 1.0 / 384.0;
  1329. float2 lumaMinTemp = min(lumaNwNeSwSe.xy, lumaNwNeSwSe.zw);
  1330. float2 lumaMaxTemp = max(lumaNwNeSwSe.xy, lumaNwNeSwSe.zw);
  1331. float lumaMin = min(lumaMinTemp.x, lumaMinTemp.y);
  1332. float lumaMax = max(lumaMaxTemp.x, lumaMaxTemp.y);
  1333. /*--------------------------------------------------------------------------*/
  1334. float4 rgbyM = tex2Dlod(tex, float4(pos.xy, 0.0, 0.0));
  1335. #if (FXAA_GREEN_AS_LUMA == 0)
  1336. float lumaMinM = min(lumaMin, rgbyM.w);
  1337. float lumaMaxM = max(lumaMax, rgbyM.w);
  1338. #else
  1339. float lumaMinM = min(lumaMin, rgbyM.y);
  1340. float lumaMaxM = max(lumaMax, rgbyM.y);
  1341. #endif
  1342. if ((lumaMaxM - lumaMinM) < max(fxaaConsoleEdgeThresholdMin, lumaMax * fxaaConsoleEdgeThreshold)) return rgbyM;
  1343. /*--------------------------------------------------------------------------*/
  1344. float2 dir;
  1345. dir.x = dot(lumaNwNeSwSe, fxaaConsole360ConstDir.yyxx);
  1346. dir.y = dot(lumaNwNeSwSe, fxaaConsole360ConstDir.xyxy);
  1347. dir = normalize(dir);
  1348. /*--------------------------------------------------------------------------*/
  1349. float4 dir1 = dir.xyxy * fxaaConsoleRcpFrameOpt.xyzw;
  1350. /*--------------------------------------------------------------------------*/
  1351. float4 dir2;
  1352. float dirAbsMinTimesC = min(abs(dir.x), abs(dir.y)) * fxaaConsoleEdgeSharpness;
  1353. dir2 = saturate(fxaaConsole360ConstDir.zzww * dir.xyxy / dirAbsMinTimesC + 0.5);
  1354. dir2 = dir2 * fxaaConsole360RcpFrameOpt2.xyxy + fxaaConsole360RcpFrameOpt2.zwzw;
  1355. /*--------------------------------------------------------------------------*/
  1356. float4 rgbyN1 = tex2Dlod(fxaaConsole360TexExpBiasNegOne, float4(pos.xy + dir1.xy, 0.0, 0.0));
  1357. float4 rgbyP1 = tex2Dlod(fxaaConsole360TexExpBiasNegOne, float4(pos.xy + dir1.zw, 0.0, 0.0));
  1358. float4 rgbyN2 = tex2Dlod(fxaaConsole360TexExpBiasNegTwo, float4(pos.xy + dir2.xy, 0.0, 0.0));
  1359. float4 rgbyP2 = tex2Dlod(fxaaConsole360TexExpBiasNegTwo, float4(pos.xy + dir2.zw, 0.0, 0.0));
  1360. /*--------------------------------------------------------------------------*/
  1361. float4 rgbyA = rgbyN1 + rgbyP1;
  1362. float4 rgbyB = rgbyN2 + rgbyP2 + rgbyA * 0.5;
  1363. /*--------------------------------------------------------------------------*/
  1364. float4 rgbyR = ((FxaaLuma(rgbyB) - lumaMax) > 0.0) ? rgbyA : rgbyB;
  1365. rgbyR = ((FxaaLuma(rgbyB) - lumaMin) > 0.0) ? rgbyR : rgbyA;
  1366. return rgbyR;
  1367. }
  1368. /*==========================================================================*/
  1369. #endif
  1370. /*============================================================================
  1371. FXAA3 CONSOLE - OPTIMIZED PS3 PIXEL SHADER (NO EARLY EXIT)
  1372. ==============================================================================
  1373. The code below does not exactly match the assembly.
  1374. I have a feeling that 12 cycles is possible, but was not able to get there.
  1375. Might have to increase register count to get full performance.
  1376. Note this shader does not use perspective interpolation.
  1377. Use the following cgc options,
  1378. --fenable-bx2 --fastmath --fastprecision --nofloatbindings
  1379. ------------------------------------------------------------------------------
  1380. NVSHADERPERF OUTPUT
  1381. ------------------------------------------------------------------------------
  1382. For reference and to aid in debug, output of NVShaderPerf should match this,
  1383. Shader to schedule:
  1384. 0: texpkb h0.w(TRUE), v5.zyxx, #0
  1385. 2: addh h2.z(TRUE), h0.w, constant(0.001953, 0.000000, 0.000000, 0.000000).x
  1386. 4: texpkb h0.w(TRUE), v5.xwxx, #0
  1387. 6: addh h0.z(TRUE), -h2, h0.w
  1388. 7: texpkb h1.w(TRUE), v5, #0
  1389. 9: addh h0.x(TRUE), h0.z, -h1.w
  1390. 10: addh h3.w(TRUE), h0.z, h1
  1391. 11: texpkb h2.w(TRUE), v5.zwzz, #0
  1392. 13: addh h0.z(TRUE), h3.w, -h2.w
  1393. 14: addh h0.x(TRUE), h2.w, h0
  1394. 15: nrmh h1.xz(TRUE), h0_n
  1395. 16: minh_m8 h0.x(TRUE), |h1|, |h1.z|
  1396. 17: maxh h4.w(TRUE), h0, h1
  1397. 18: divx h2.xy(TRUE), h1_n.xzzw, h0_n
  1398. 19: movr r1.zw(TRUE), v4.xxxy
  1399. 20: madr r2.xz(TRUE), -h1, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zzww, r1.zzww
  1400. 22: minh h5.w(TRUE), h0, h1
  1401. 23: texpkb h0(TRUE), r2.xzxx, #0
  1402. 25: madr r0.zw(TRUE), h1.xzxz, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w), r1
  1403. 27: maxh h4.x(TRUE), h2.z, h2.w
  1404. 28: texpkb h1(TRUE), r0.zwzz, #0
  1405. 30: addh_d2 h1(TRUE), h0, h1
  1406. 31: madr r0.xy(TRUE), -h2, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz
  1407. 33: texpkb h0(TRUE), r0, #0
  1408. 35: minh h4.z(TRUE), h2, h2.w
  1409. 36: fenct TRUE
  1410. 37: madr r1.xy(TRUE), h2, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz
  1411. 39: texpkb h2(TRUE), r1, #0
  1412. 41: addh_d2 h0(TRUE), h0, h2
  1413. 42: maxh h2.w(TRUE), h4, h4.x
  1414. 43: minh h2.x(TRUE), h5.w, h4.z
  1415. 44: addh_d2 h0(TRUE), h0, h1
  1416. 45: slth h2.x(TRUE), h0.w, h2
  1417. 46: sgth h2.w(TRUE), h0, h2
  1418. 47: movh h0(TRUE), h0
  1419. 48: addx.c0 rc(TRUE), h2, h2.w
  1420. 49: movh h0(c0.NE.x), h1
  1421. IPU0 ------ Simplified schedule: --------
  1422. Pass | Unit | uOp | PC: Op
  1423. -----+--------+------+-------------------------
  1424. 1 | SCT0/1 | mov | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0;
  1425. | TEX | txl | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0;
  1426. | SCB1 | add | 2: ADDh h2.z, h0.--w-, const.--x-;
  1427. | | |
  1428. 2 | SCT0/1 | mov | 4: TXLr h0.w, g[TEX1].xwxx, const.xxxx, TEX0;
  1429. | TEX | txl | 4: TXLr h0.w, g[TEX1].xwxx, const.xxxx, TEX0;
  1430. | SCB1 | add | 6: ADDh h0.z,-h2, h0.--w-;
  1431. | | |
  1432. 3 | SCT0/1 | mov | 7: TXLr h1.w, g[TEX1], const.xxxx, TEX0;
  1433. | TEX | txl | 7: TXLr h1.w, g[TEX1], const.xxxx, TEX0;
  1434. | SCB0 | add | 9: ADDh h0.x, h0.z---,-h1.w---;
  1435. | SCB1 | add | 10: ADDh h3.w, h0.---z, h1;
  1436. | | |
  1437. 4 | SCT0/1 | mov | 11: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0;
  1438. | TEX | txl | 11: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0;
  1439. | SCB0 | add | 14: ADDh h0.x, h2.w---, h0;
  1440. | SCB1 | add | 13: ADDh h0.z, h3.--w-,-h2.--w-;
  1441. | | |
  1442. 5 | SCT1 | mov | 15: NRMh h1.xz, h0;
  1443. | SRB | nrm | 15: NRMh h1.xz, h0;
  1444. | SCB0 | min | 16: MINh*8 h0.x, |h1|, |h1.z---|;
  1445. | SCB1 | max | 17: MAXh h4.w, h0, h1;
  1446. | | |
  1447. 6 | SCT0 | div | 18: DIVx h2.xy, h1.xz--, h0;
  1448. | SCT1 | mov | 19: MOVr r1.zw, g[TEX0].--xy;
  1449. | SCB0 | mad | 20: MADr r2.xz,-h1, const.z-w-, r1.z-w-;
  1450. | SCB1 | min | 22: MINh h5.w, h0, h1;
  1451. | | |
  1452. 7 | SCT0/1 | mov | 23: TXLr h0, r2.xzxx, const.xxxx, TEX0;
  1453. | TEX | txl | 23: TXLr h0, r2.xzxx, const.xxxx, TEX0;
  1454. | SCB0 | max | 27: MAXh h4.x, h2.z---, h2.w---;
  1455. | SCB1 | mad | 25: MADr r0.zw, h1.--xz, const, r1;
  1456. | | |
  1457. 8 | SCT0/1 | mov | 28: TXLr h1, r0.zwzz, const.xxxx, TEX0;
  1458. | TEX | txl | 28: TXLr h1, r0.zwzz, const.xxxx, TEX0;
  1459. | SCB0/1 | add | 30: ADDh/2 h1, h0, h1;
  1460. | | |
  1461. 9 | SCT0 | mad | 31: MADr r0.xy,-h2, const.xy--, r1.zw--;
  1462. | SCT1 | mov | 33: TXLr h0, r0, const.zzzz, TEX0;
  1463. | TEX | txl | 33: TXLr h0, r0, const.zzzz, TEX0;
  1464. | SCB1 | min | 35: MINh h4.z, h2, h2.--w-;
  1465. | | |
  1466. 10 | SCT0 | mad | 37: MADr r1.xy, h2, const.xy--, r1.zw--;
  1467. | SCT1 | mov | 39: TXLr h2, r1, const.zzzz, TEX0;
  1468. | TEX | txl | 39: TXLr h2, r1, const.zzzz, TEX0;
  1469. | SCB0/1 | add | 41: ADDh/2 h0, h0, h2;
  1470. | | |
  1471. 11 | SCT0 | min | 43: MINh h2.x, h5.w---, h4.z---;
  1472. | SCT1 | max | 42: MAXh h2.w, h4, h4.---x;
  1473. | SCB0/1 | add | 44: ADDh/2 h0, h0, h1;
  1474. | | |
  1475. 12 | SCT0 | set | 45: SLTh h2.x, h0.w---, h2;
  1476. | SCT1 | set | 46: SGTh h2.w, h0, h2;
  1477. | SCB0/1 | mul | 47: MOVh h0, h0;
  1478. | | |
  1479. 13 | SCT0 | mad | 48: ADDxc0_s rc, h2, h2.w---;
  1480. | SCB0/1 | mul | 49: MOVh h0(NE0.xxxx), h1;
  1481. Pass SCT TEX SCB
  1482. 1: 0% 100% 25%
  1483. 2: 0% 100% 25%
  1484. 3: 0% 100% 50%
  1485. 4: 0% 100% 50%
  1486. 5: 0% 0% 50%
  1487. 6: 100% 0% 75%
  1488. 7: 0% 100% 75%
  1489. 8: 0% 100% 100%
  1490. 9: 0% 100% 25%
  1491. 10: 0% 100% 100%
  1492. 11: 50% 0% 100%
  1493. 12: 50% 0% 100%
  1494. 13: 25% 0% 100%
  1495. MEAN: 17% 61% 67%
  1496. Pass SCT0 SCT1 TEX SCB0 SCB1
  1497. 1: 0% 0% 100% 0% 100%
  1498. 2: 0% 0% 100% 0% 100%
  1499. 3: 0% 0% 100% 100% 100%
  1500. 4: 0% 0% 100% 100% 100%
  1501. 5: 0% 0% 0% 100% 100%
  1502. 6: 100% 100% 0% 100% 100%
  1503. 7: 0% 0% 100% 100% 100%
  1504. 8: 0% 0% 100% 100% 100%
  1505. 9: 0% 0% 100% 0% 100%
  1506. 10: 0% 0% 100% 100% 100%
  1507. 11: 100% 100% 0% 100% 100%
  1508. 12: 100% 100% 0% 100% 100%
  1509. 13: 100% 0% 0% 100% 100%
  1510. MEAN: 30% 23% 61% 76% 100%
  1511. Fragment Performance Setup: Driver RSX Compiler, GPU RSX, Flags 0x5
  1512. Results 13 cycles, 3 r regs, 923,076,923 pixels/s
  1513. ============================================================================*/
  1514. #if (FXAA_PS3 == 1) && (FXAA_EARLY_EXIT == 0)
  1515. /*--------------------------------------------------------------------------*/
  1516. #pragma regcount 7
  1517. #pragma disablepc all
  1518. #pragma option O3
  1519. #pragma option OutColorPrec=fp16
  1520. #pragma texformat default RGBA8
  1521. /*==========================================================================*/
  1522. half4 FxaaPixelShader(
  1523. // See FXAA Quality FxaaPixelShader() source for docs on Inputs!
  1524. FxaaFloat2 pos,
  1525. FxaaFloat4 fxaaConsolePosPos,
  1526. FxaaTex tex,
  1527. FxaaTex fxaaConsole360TexExpBiasNegOne,
  1528. FxaaTex fxaaConsole360TexExpBiasNegTwo,
  1529. FxaaFloat2 fxaaQualityRcpFrame,
  1530. FxaaFloat4 fxaaConsoleRcpFrameOpt,
  1531. FxaaFloat4 fxaaConsoleRcpFrameOpt2,
  1532. FxaaFloat4 fxaaConsole360RcpFrameOpt2,
  1533. FxaaFloat fxaaQualitySubpix,
  1534. FxaaFloat fxaaQualityEdgeThreshold,
  1535. FxaaFloat fxaaQualityEdgeThresholdMin,
  1536. FxaaFloat fxaaConsoleEdgeSharpness,
  1537. FxaaFloat fxaaConsoleEdgeThreshold,
  1538. FxaaFloat fxaaConsoleEdgeThresholdMin,
  1539. FxaaFloat4 fxaaConsole360ConstDir
  1540. )
  1541. {
  1542. /*--------------------------------------------------------------------------*/
  1543. // (1)
  1544. half4 dir;
  1545. half4 lumaNe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zy, 0, 0));
  1546. #if (FXAA_GREEN_AS_LUMA == 0)
  1547. lumaNe.w += half(1.0 / 512.0);
  1548. dir.x = -lumaNe.w;
  1549. dir.z = -lumaNe.w;
  1550. #else
  1551. lumaNe.y += half(1.0 / 512.0);
  1552. dir.x = -lumaNe.y;
  1553. dir.z = -lumaNe.y;
  1554. #endif
  1555. /*--------------------------------------------------------------------------*/
  1556. // (2)
  1557. half4 lumaSw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xw, 0, 0));
  1558. #if (FXAA_GREEN_AS_LUMA == 0)
  1559. dir.x += lumaSw.w;
  1560. dir.z += lumaSw.w;
  1561. #else
  1562. dir.x += lumaSw.y;
  1563. dir.z += lumaSw.y;
  1564. #endif
  1565. /*--------------------------------------------------------------------------*/
  1566. // (3)
  1567. half4 lumaNw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xy, 0, 0));
  1568. #if (FXAA_GREEN_AS_LUMA == 0)
  1569. dir.x -= lumaNw.w;
  1570. dir.z += lumaNw.w;
  1571. #else
  1572. dir.x -= lumaNw.y;
  1573. dir.z += lumaNw.y;
  1574. #endif
  1575. /*--------------------------------------------------------------------------*/
  1576. // (4)
  1577. half4 lumaSe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zw, 0, 0));
  1578. #if (FXAA_GREEN_AS_LUMA == 0)
  1579. dir.x += lumaSe.w;
  1580. dir.z -= lumaSe.w;
  1581. #else
  1582. dir.x += lumaSe.y;
  1583. dir.z -= lumaSe.y;
  1584. #endif
  1585. /*--------------------------------------------------------------------------*/
  1586. // (5)
  1587. half4 dir1_pos;
  1588. dir1_pos.xy = normalize(dir.xyz).xz;
  1589. half dirAbsMinTimesC = min(abs(dir1_pos.x), abs(dir1_pos.y)) * half(FXAA_CONSOLE__PS3_EDGE_SHARPNESS);
  1590. /*--------------------------------------------------------------------------*/
  1591. // (6)
  1592. half4 dir2_pos;
  1593. dir2_pos.xy = clamp(dir1_pos.xy / dirAbsMinTimesC, half(-2.0), half(2.0));
  1594. dir1_pos.zw = pos.xy;
  1595. dir2_pos.zw = pos.xy;
  1596. half4 temp1N;
  1597. temp1N.xy = dir1_pos.zw - dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw;
  1598. /*--------------------------------------------------------------------------*/
  1599. // (7)
  1600. temp1N = h4tex2Dlod(tex, half4(temp1N.xy, 0.0, 0.0));
  1601. half4 rgby1;
  1602. rgby1.xy = dir1_pos.zw + dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw;
  1603. /*--------------------------------------------------------------------------*/
  1604. // (8)
  1605. rgby1 = h4tex2Dlod(tex, half4(rgby1.xy, 0.0, 0.0));
  1606. rgby1 = (temp1N + rgby1) * 0.5;
  1607. /*--------------------------------------------------------------------------*/
  1608. // (9)
  1609. half4 temp2N;
  1610. temp2N.xy = dir2_pos.zw - dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw;
  1611. temp2N = h4tex2Dlod(tex, half4(temp2N.xy, 0.0, 0.0));
  1612. /*--------------------------------------------------------------------------*/
  1613. // (10)
  1614. half4 rgby2;
  1615. rgby2.xy = dir2_pos.zw + dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw;
  1616. rgby2 = h4tex2Dlod(tex, half4(rgby2.xy, 0.0, 0.0));
  1617. rgby2 = (temp2N + rgby2) * 0.5;
  1618. /*--------------------------------------------------------------------------*/
  1619. // (11)
  1620. // compilier moves these scalar ops up to other cycles
  1621. #if (FXAA_GREEN_AS_LUMA == 0)
  1622. half lumaMin = min(min(lumaNw.w, lumaSw.w), min(lumaNe.w, lumaSe.w));
  1623. half lumaMax = max(max(lumaNw.w, lumaSw.w), max(lumaNe.w, lumaSe.w));
  1624. #else
  1625. half lumaMin = min(min(lumaNw.y, lumaSw.y), min(lumaNe.y, lumaSe.y));
  1626. half lumaMax = max(max(lumaNw.y, lumaSw.y), max(lumaNe.y, lumaSe.y));
  1627. #endif
  1628. rgby2 = (rgby2 + rgby1) * 0.5;
  1629. /*--------------------------------------------------------------------------*/
  1630. // (12)
  1631. #if (FXAA_GREEN_AS_LUMA == 0)
  1632. bool twoTapLt = rgby2.w < lumaMin;
  1633. bool twoTapGt = rgby2.w > lumaMax;
  1634. #else
  1635. bool twoTapLt = rgby2.y < lumaMin;
  1636. bool twoTapGt = rgby2.y > lumaMax;
  1637. #endif
  1638. /*--------------------------------------------------------------------------*/
  1639. // (13)
  1640. if (twoTapLt || twoTapGt) rgby2 = rgby1;
  1641. /*--------------------------------------------------------------------------*/
  1642. return rgby2;
  1643. }
  1644. /*==========================================================================*/
  1645. #endif
  1646. /*============================================================================
  1647. FXAA3 CONSOLE - OPTIMIZED PS3 PIXEL SHADER (WITH EARLY EXIT)
  1648. ==============================================================================
  1649. The code mostly matches the assembly.
  1650. I have a feeling that 14 cycles is possible, but was not able to get there.
  1651. Might have to increase register count to get full performance.
  1652. Note this shader does not use perspective interpolation.
  1653. Use the following cgc options,
  1654. --fenable-bx2 --fastmath --fastprecision --nofloatbindings
  1655. Use of FXAA_GREEN_AS_LUMA currently adds a cycle (16 clks).
  1656. Will look at fixing this for FXAA 3.12.
  1657. ------------------------------------------------------------------------------
  1658. NVSHADERPERF OUTPUT
  1659. ------------------------------------------------------------------------------
  1660. For reference and to aid in debug, output of NVShaderPerf should match this,
  1661. Shader to schedule:
  1662. 0: texpkb h0.w(TRUE), v5.zyxx, #0
  1663. 2: addh h2.y(TRUE), h0.w, constant(0.001953, 0.000000, 0.000000, 0.000000).x
  1664. 4: texpkb h1.w(TRUE), v5.xwxx, #0
  1665. 6: addh h0.x(TRUE), h1.w, -h2.y
  1666. 7: texpkb h2.w(TRUE), v5.zwzz, #0
  1667. 9: minh h4.w(TRUE), h2.y, h2
  1668. 10: maxh h5.x(TRUE), h2.y, h2.w
  1669. 11: texpkb h0.w(TRUE), v5, #0
  1670. 13: addh h3.w(TRUE), -h0, h0.x
  1671. 14: addh h0.x(TRUE), h0.w, h0
  1672. 15: addh h0.z(TRUE), -h2.w, h0.x
  1673. 16: addh h0.x(TRUE), h2.w, h3.w
  1674. 17: minh h5.y(TRUE), h0.w, h1.w
  1675. 18: nrmh h2.xz(TRUE), h0_n
  1676. 19: minh_m8 h2.w(TRUE), |h2.x|, |h2.z|
  1677. 20: divx h4.xy(TRUE), h2_n.xzzw, h2_n.w
  1678. 21: movr r1.zw(TRUE), v4.xxxy
  1679. 22: maxh h2.w(TRUE), h0, h1
  1680. 23: fenct TRUE
  1681. 24: madr r0.xy(TRUE), -h2.xzzw, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zwzz, r1.zwzz
  1682. 26: texpkb h0(TRUE), r0, #0
  1683. 28: maxh h5.x(TRUE), h2.w, h5
  1684. 29: minh h5.w(TRUE), h5.y, h4
  1685. 30: madr r1.xy(TRUE), h2.xzzw, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zwzz, r1.zwzz
  1686. 32: texpkb h2(TRUE), r1, #0
  1687. 34: addh_d2 h2(TRUE), h0, h2
  1688. 35: texpkb h1(TRUE), v4, #0
  1689. 37: maxh h5.y(TRUE), h5.x, h1.w
  1690. 38: minh h4.w(TRUE), h1, h5
  1691. 39: madr r0.xy(TRUE), -h4, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz
  1692. 41: texpkb h0(TRUE), r0, #0
  1693. 43: addh_m8 h5.z(TRUE), h5.y, -h4.w
  1694. 44: madr r2.xy(TRUE), h4, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz
  1695. 46: texpkb h3(TRUE), r2, #0
  1696. 48: addh_d2 h0(TRUE), h0, h3
  1697. 49: addh_d2 h3(TRUE), h0, h2
  1698. 50: movh h0(TRUE), h3
  1699. 51: slth h3.x(TRUE), h3.w, h5.w
  1700. 52: sgth h3.w(TRUE), h3, h5.x
  1701. 53: addx.c0 rc(TRUE), h3.x, h3
  1702. 54: slth.c0 rc(TRUE), h5.z, h5
  1703. 55: movh h0(c0.NE.w), h2
  1704. 56: movh h0(c0.NE.x), h1
  1705. IPU0 ------ Simplified schedule: --------
  1706. Pass | Unit | uOp | PC: Op
  1707. -----+--------+------+-------------------------
  1708. 1 | SCT0/1 | mov | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0;
  1709. | TEX | txl | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0;
  1710. | SCB0 | add | 2: ADDh h2.y, h0.-w--, const.-x--;
  1711. | | |
  1712. 2 | SCT0/1 | mov | 4: TXLr h1.w, g[TEX1].xwxx, const.xxxx, TEX0;
  1713. | TEX | txl | 4: TXLr h1.w, g[TEX1].xwxx, const.xxxx, TEX0;
  1714. | SCB0 | add | 6: ADDh h0.x, h1.w---,-h2.y---;
  1715. | | |
  1716. 3 | SCT0/1 | mov | 7: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0;
  1717. | TEX | txl | 7: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0;
  1718. | SCB0 | max | 10: MAXh h5.x, h2.y---, h2.w---;
  1719. | SCB1 | min | 9: MINh h4.w, h2.---y, h2;
  1720. | | |
  1721. 4 | SCT0/1 | mov | 11: TXLr h0.w, g[TEX1], const.xxxx, TEX0;
  1722. | TEX | txl | 11: TXLr h0.w, g[TEX1], const.xxxx, TEX0;
  1723. | SCB0 | add | 14: ADDh h0.x, h0.w---, h0;
  1724. | SCB1 | add | 13: ADDh h3.w,-h0, h0.---x;
  1725. | | |
  1726. 5 | SCT0 | mad | 16: ADDh h0.x, h2.w---, h3.w---;
  1727. | SCT1 | mad | 15: ADDh h0.z,-h2.--w-, h0.--x-;
  1728. | SCB0 | min | 17: MINh h5.y, h0.-w--, h1.-w--;
  1729. | | |
  1730. 6 | SCT1 | mov | 18: NRMh h2.xz, h0;
  1731. | SRB | nrm | 18: NRMh h2.xz, h0;
  1732. | SCB1 | min | 19: MINh*8 h2.w, |h2.---x|, |h2.---z|;
  1733. | | |
  1734. 7 | SCT0 | div | 20: DIVx h4.xy, h2.xz--, h2.ww--;
  1735. | SCT1 | mov | 21: MOVr r1.zw, g[TEX0].--xy;
  1736. | SCB1 | max | 22: MAXh h2.w, h0, h1;
  1737. | | |
  1738. 8 | SCT0 | mad | 24: MADr r0.xy,-h2.xz--, const.zw--, r1.zw--;
  1739. | SCT1 | mov | 26: TXLr h0, r0, const.xxxx, TEX0;
  1740. | TEX | txl | 26: TXLr h0, r0, const.xxxx, TEX0;
  1741. | SCB0 | max | 28: MAXh h5.x, h2.w---, h5;
  1742. | SCB1 | min | 29: MINh h5.w, h5.---y, h4;
  1743. | | |
  1744. 9 | SCT0 | mad | 30: MADr r1.xy, h2.xz--, const.zw--, r1.zw--;
  1745. | SCT1 | mov | 32: TXLr h2, r1, const.xxxx, TEX0;
  1746. | TEX | txl | 32: TXLr h2, r1, const.xxxx, TEX0;
  1747. | SCB0/1 | add | 34: ADDh/2 h2, h0, h2;
  1748. | | |
  1749. 10 | SCT0/1 | mov | 35: TXLr h1, g[TEX0], const.xxxx, TEX0;
  1750. | TEX | txl | 35: TXLr h1, g[TEX0], const.xxxx, TEX0;
  1751. | SCB0 | max | 37: MAXh h5.y, h5.-x--, h1.-w--;
  1752. | SCB1 | min | 38: MINh h4.w, h1, h5;
  1753. | | |
  1754. 11 | SCT0 | mad | 39: MADr r0.xy,-h4, const.xy--, r1.zw--;
  1755. | SCT1 | mov | 41: TXLr h0, r0, const.zzzz, TEX0;
  1756. | TEX | txl | 41: TXLr h0, r0, const.zzzz, TEX0;
  1757. | SCB0 | mad | 44: MADr r2.xy, h4, const.xy--, r1.zw--;
  1758. | SCB1 | add | 43: ADDh*8 h5.z, h5.--y-,-h4.--w-;
  1759. | | |
  1760. 12 | SCT0/1 | mov | 46: TXLr h3, r2, const.xxxx, TEX0;
  1761. | TEX | txl | 46: TXLr h3, r2, const.xxxx, TEX0;
  1762. | SCB0/1 | add | 48: ADDh/2 h0, h0, h3;
  1763. | | |
  1764. 13 | SCT0/1 | mad | 49: ADDh/2 h3, h0, h2;
  1765. | SCB0/1 | mul | 50: MOVh h0, h3;
  1766. | | |
  1767. 14 | SCT0 | set | 51: SLTh h3.x, h3.w---, h5.w---;
  1768. | SCT1 | set | 52: SGTh h3.w, h3, h5.---x;
  1769. | SCB0 | set | 54: SLThc0 rc, h5.z---, h5;
  1770. | SCB1 | add | 53: ADDxc0_s rc, h3.---x, h3;
  1771. | | |
  1772. 15 | SCT0/1 | mul | 55: MOVh h0(NE0.wwww), h2;
  1773. | SCB0/1 | mul | 56: MOVh h0(NE0.xxxx), h1;
  1774. Pass SCT TEX SCB
  1775. 1: 0% 100% 25%
  1776. 2: 0% 100% 25%
  1777. 3: 0% 100% 50%
  1778. 4: 0% 100% 50%
  1779. 5: 50% 0% 25%
  1780. 6: 0% 0% 25%
  1781. 7: 100% 0% 25%
  1782. 8: 0% 100% 50%
  1783. 9: 0% 100% 100%
  1784. 10: 0% 100% 50%
  1785. 11: 0% 100% 75%
  1786. 12: 0% 100% 100%
  1787. 13: 100% 0% 100%
  1788. 14: 50% 0% 50%
  1789. 15: 100% 0% 100%
  1790. MEAN: 26% 60% 56%
  1791. Pass SCT0 SCT1 TEX SCB0 SCB1
  1792. 1: 0% 0% 100% 100% 0%
  1793. 2: 0% 0% 100% 100% 0%
  1794. 3: 0% 0% 100% 100% 100%
  1795. 4: 0% 0% 100% 100% 100%
  1796. 5: 100% 100% 0% 100% 0%
  1797. 6: 0% 0% 0% 0% 100%
  1798. 7: 100% 100% 0% 0% 100%
  1799. 8: 0% 0% 100% 100% 100%
  1800. 9: 0% 0% 100% 100% 100%
  1801. 10: 0% 0% 100% 100% 100%
  1802. 11: 0% 0% 100% 100% 100%
  1803. 12: 0% 0% 100% 100% 100%
  1804. 13: 100% 100% 0% 100% 100%
  1805. 14: 100% 100% 0% 100% 100%
  1806. 15: 100% 100% 0% 100% 100%
  1807. MEAN: 33% 33% 60% 86% 80%
  1808. Fragment Performance Setup: Driver RSX Compiler, GPU RSX, Flags 0x5
  1809. Results 15 cycles, 3 r regs, 800,000,000 pixels/s
  1810. ============================================================================*/
  1811. #if (FXAA_PS3 == 1) && (FXAA_EARLY_EXIT == 1)
  1812. /*--------------------------------------------------------------------------*/
  1813. #pragma regcount 7
  1814. #pragma disablepc all
  1815. #pragma option O2
  1816. #pragma option OutColorPrec=fp16
  1817. #pragma texformat default RGBA8
  1818. /*==========================================================================*/
  1819. half4 FxaaPixelShader(
  1820. // See FXAA Quality FxaaPixelShader() source for docs on Inputs!
  1821. FxaaFloat2 pos,
  1822. FxaaFloat4 fxaaConsolePosPos,
  1823. FxaaTex tex,
  1824. FxaaTex fxaaConsole360TexExpBiasNegOne,
  1825. FxaaTex fxaaConsole360TexExpBiasNegTwo,
  1826. FxaaFloat2 fxaaQualityRcpFrame,
  1827. FxaaFloat4 fxaaConsoleRcpFrameOpt,
  1828. FxaaFloat4 fxaaConsoleRcpFrameOpt2,
  1829. FxaaFloat4 fxaaConsole360RcpFrameOpt2,
  1830. FxaaFloat fxaaQualitySubpix,
  1831. FxaaFloat fxaaQualityEdgeThreshold,
  1832. FxaaFloat fxaaQualityEdgeThresholdMin,
  1833. FxaaFloat fxaaConsoleEdgeSharpness,
  1834. FxaaFloat fxaaConsoleEdgeThreshold,
  1835. FxaaFloat fxaaConsoleEdgeThresholdMin,
  1836. FxaaFloat4 fxaaConsole360ConstDir
  1837. )
  1838. {
  1839. /*--------------------------------------------------------------------------*/
  1840. // (1)
  1841. half4 rgbyNe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zy, 0, 0));
  1842. #if (FXAA_GREEN_AS_LUMA == 0)
  1843. half lumaNe = rgbyNe.w + half(1.0 / 512.0);
  1844. #else
  1845. half lumaNe = rgbyNe.y + half(1.0 / 512.0);
  1846. #endif
  1847. /*--------------------------------------------------------------------------*/
  1848. // (2)
  1849. half4 lumaSw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xw, 0, 0));
  1850. #if (FXAA_GREEN_AS_LUMA == 0)
  1851. half lumaSwNegNe = lumaSw.w - lumaNe;
  1852. #else
  1853. half lumaSwNegNe = lumaSw.y - lumaNe;
  1854. #endif
  1855. /*--------------------------------------------------------------------------*/
  1856. // (3)
  1857. half4 lumaNw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xy, 0, 0));
  1858. #if (FXAA_GREEN_AS_LUMA == 0)
  1859. half lumaMaxNwSw = max(lumaNw.w, lumaSw.w);
  1860. half lumaMinNwSw = min(lumaNw.w, lumaSw.w);
  1861. #else
  1862. half lumaMaxNwSw = max(lumaNw.y, lumaSw.y);
  1863. half lumaMinNwSw = min(lumaNw.y, lumaSw.y);
  1864. #endif
  1865. /*--------------------------------------------------------------------------*/
  1866. // (4)
  1867. half4 lumaSe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zw, 0, 0));
  1868. #if (FXAA_GREEN_AS_LUMA == 0)
  1869. half dirZ = lumaNw.w + lumaSwNegNe;
  1870. half dirX = -lumaNw.w + lumaSwNegNe;
  1871. #else
  1872. half dirZ = lumaNw.y + lumaSwNegNe;
  1873. half dirX = -lumaNw.y + lumaSwNegNe;
  1874. #endif
  1875. /*--------------------------------------------------------------------------*/
  1876. // (5)
  1877. half3 dir;
  1878. dir.y = 0.0;
  1879. #if (FXAA_GREEN_AS_LUMA == 0)
  1880. dir.x = lumaSe.w + dirX;
  1881. dir.z = -lumaSe.w + dirZ;
  1882. half lumaMinNeSe = min(lumaNe, lumaSe.w);
  1883. #else
  1884. dir.x = lumaSe.y + dirX;
  1885. dir.z = -lumaSe.y + dirZ;
  1886. half lumaMinNeSe = min(lumaNe, lumaSe.y);
  1887. #endif
  1888. /*--------------------------------------------------------------------------*/
  1889. // (6)
  1890. half4 dir1_pos;
  1891. dir1_pos.xy = normalize(dir).xz;
  1892. half dirAbsMinTimes8 = min(abs(dir1_pos.x), abs(dir1_pos.y)) * half(FXAA_CONSOLE__PS3_EDGE_SHARPNESS);
  1893. /*--------------------------------------------------------------------------*/
  1894. // (7)
  1895. half4 dir2_pos;
  1896. dir2_pos.xy = clamp(dir1_pos.xy / dirAbsMinTimes8, half(-2.0), half(2.0));
  1897. dir1_pos.zw = pos.xy;
  1898. dir2_pos.zw = pos.xy;
  1899. #if (FXAA_GREEN_AS_LUMA == 0)
  1900. half lumaMaxNeSe = max(lumaNe, lumaSe.w);
  1901. #else
  1902. half lumaMaxNeSe = max(lumaNe, lumaSe.y);
  1903. #endif
  1904. /*--------------------------------------------------------------------------*/
  1905. // (8)
  1906. half4 temp1N;
  1907. temp1N.xy = dir1_pos.zw - dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw;
  1908. temp1N = h4tex2Dlod(tex, half4(temp1N.xy, 0.0, 0.0));
  1909. half lumaMax = max(lumaMaxNwSw, lumaMaxNeSe);
  1910. half lumaMin = min(lumaMinNwSw, lumaMinNeSe);
  1911. /*--------------------------------------------------------------------------*/
  1912. // (9)
  1913. half4 rgby1;
  1914. rgby1.xy = dir1_pos.zw + dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw;
  1915. rgby1 = h4tex2Dlod(tex, half4(rgby1.xy, 0.0, 0.0));
  1916. rgby1 = (temp1N + rgby1) * 0.5;
  1917. /*--------------------------------------------------------------------------*/
  1918. // (10)
  1919. half4 rgbyM = h4tex2Dlod(tex, half4(pos.xy, 0.0, 0.0));
  1920. #if (FXAA_GREEN_AS_LUMA == 0)
  1921. half lumaMaxM = max(lumaMax, rgbyM.w);
  1922. half lumaMinM = min(lumaMin, rgbyM.w);
  1923. #else
  1924. half lumaMaxM = max(lumaMax, rgbyM.y);
  1925. half lumaMinM = min(lumaMin, rgbyM.y);
  1926. #endif
  1927. /*--------------------------------------------------------------------------*/
  1928. // (11)
  1929. half4 temp2N;
  1930. temp2N.xy = dir2_pos.zw - dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw;
  1931. temp2N = h4tex2Dlod(tex, half4(temp2N.xy, 0.0, 0.0));
  1932. half4 rgby2;
  1933. rgby2.xy = dir2_pos.zw + dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw;
  1934. half lumaRangeM = (lumaMaxM - lumaMinM) / FXAA_CONSOLE__PS3_EDGE_THRESHOLD;
  1935. /*--------------------------------------------------------------------------*/
  1936. // (12)
  1937. rgby2 = h4tex2Dlod(tex, half4(rgby2.xy, 0.0, 0.0));
  1938. rgby2 = (temp2N + rgby2) * 0.5;
  1939. /*--------------------------------------------------------------------------*/
  1940. // (13)
  1941. rgby2 = (rgby2 + rgby1) * 0.5;
  1942. /*--------------------------------------------------------------------------*/
  1943. // (14)
  1944. #if (FXAA_GREEN_AS_LUMA == 0)
  1945. bool twoTapLt = rgby2.w < lumaMin;
  1946. bool twoTapGt = rgby2.w > lumaMax;
  1947. #else
  1948. bool twoTapLt = rgby2.y < lumaMin;
  1949. bool twoTapGt = rgby2.y > lumaMax;
  1950. #endif
  1951. bool earlyExit = lumaRangeM < lumaMax;
  1952. bool twoTap = twoTapLt || twoTapGt;
  1953. /*--------------------------------------------------------------------------*/
  1954. // (15)
  1955. if (twoTap) rgby2 = rgby1;
  1956. if (earlyExit) rgby2 = rgbyM;
  1957. /*--------------------------------------------------------------------------*/
  1958. return rgby2;
  1959. }
  1960. /*==========================================================================*/
  1961. #endif
  1962. #endif // __FXAA3_INC__