Counter Strike : Global Offensive Source Code
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.

2089 lines
85 KiB

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