You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2073 lines
83 KiB

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