Guest User

Untitled

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