1// Copyright (c) 2015 Sergio Gonzalez. All rights reserved. 2// License: https://github.com/serge-rgb/milton#license 3 4uniform sampler2D u_canvas; 5uniform vec2 u_screen_size; 6 7vec4 FxaaPixelShader( 8 vec2 pos, 9 vec4 fxaaConsolePosPos, 10 sampler2D tex, 11 sampler2D fxaaConsole360TexExpBiasNegOne, 12 sampler2D fxaaConsole360TexExpBiasNegTwo, 13 vec2 fxaaQualityRcpFrame, 14 vec4 fxaaConsoleRcpFrameOpt, 15 vec4 fxaaConsoleRcpFrameOpt2, 16 vec4 fxaaConsole360RcpFrameOpt2, 17 float fxaaQualitySubpix, 18 float fxaaQualityEdgeThreshold, 19 float fxaaQualityEdgeThresholdMin, 20 float fxaaConsoleEdgeSharpness, 21 float fxaaConsoleEdgeThreshold, 22 float fxaaConsoleEdgeThresholdMin, 23 vec4 fxaaConsole360ConstDir 24); 25 26void 27main() 28{ 29 // Pixel width / height. 30 float pw = 1 / u_screen_size.x; 31 float ph = 1 / u_screen_size.y; 32 vec2 coord = gl_FragCoord.xy / u_screen_size; 33 34 out_color = texture(u_canvas, coord, 0); 35 out_color.rgb = FxaaPixelShader( 36 // Use noperspective interpolation here (turn off perspective interpolation). 37 // {xy} = center of pixel 38 gl_FragCoord.xy / u_screen_size, // FxaaFloat2 pos, 39 // 40 // Used only for FXAA Console, and not used on the 360 version. 41 // Use noperspective interpolation here (turn off perspective interpolation). 42 // {xy__} = upper left of pixel 43 // {__zw} = lower right of pixel 44 vec4(0), // FxaaFloat4 fxaaConsolePosPos, 45 // 46 // Input color texture. 47 // {rgb_} = color in linear or perceptual color space 48 // if (FXAA_GREEN_AS_LUMA == 0) 49 // {___a} = luma in perceptual color space (not linear) 50 u_canvas, // FxaaTex tex, 51 // 52 // Only used on the optimized 360 version of FXAA Console. 53 // For everything but 360, just use the same input here as for tex. 54 // For 360, same texture, just alias with a 2nd sampler. 55 // This sampler needs to have an exponent bias of -1. 56 u_canvas, // FxaaTex fxaaConsole360TexExpBiasNegOne, 57 // 58 // Only used on the optimized 360 version of FXAA Console. 59 // For everything but 360, just use the same input here as for texÏ. 60 // For 360, same texture, just alias with a 3nd sampler. 61 // This sampler needs to have an exponent bias of -2. 62 u_canvas, // FxaaTex fxaaConsole360TexExpBiasNegTwo, 63 // 64 // Only used on FXAA Quality. 65 // This must be from a constant/uniform. 66 // {x_} = 1.0/screenWidthInPixels 67 // {_y} = 1.0/screenHeightInPixels 68 1/u_screen_size, //FxaaFloat2 fxaaQualityRcpFrame, 69 // 70 // Only used on FXAA Console. 71 // This must be from a constant/uniform. 72 // This effects sub-pixel AA quality and inversely sharpness. 73 // Where N ranges between, 74 // N = 0.50 (default) 75 // N = 0.33 (sharper) 76 // {x___} = -N/screenWidthInPixels 77 // {_y__} = -N/screenHeightInPixels 78 // {__z_} = N/screenWidthInPixels 79 // {___w} = N/screenHeightInPixels 80 vec4(0), // FxaaFloat4 fxaaConsoleRcpFrameOpt, 81 // 82 // Only used on FXAA Console. 83 // Not used on 360, but used on PS3 and PC. 84 // This must be from a constant/uniform. 85 // {x___} = -2.0/screenWidthInPixels 86 // {_y__} = -2.0/screenHeightInPixels 87 // {__z_} = 2.0/screenWidthInPixels 88 // {___w} = 2.0/screenHeightInPixels 89 vec4(0), //FxaaFloat4 fxaaConsoleRcpFrameOpt2, 90 // 91 // Only used on FXAA Console. 92 // Only used on 360 in place of fxaaConsoleRcpFrameOpt2. 93 // This must be from a constant/uniform. 94 // {x___} = 8.0/screenWidthInPixels 95 // {_y__} = 8.0/screenHeightInPixels 96 // {__z_} = -4.0/screenWidthInPixels 97 // {___w} = -4.0/screenHeightInPixels 98 vec4(0), // FxaaFloat4 fxaaConsole360RcpFrameOpt2, 99 // 100 // Only used on FXAA Quality. 101 // This used to be the FXAA_QUALITY__SUBPIX define. 102 // It is here now to allow easier tuning. 103 // Choose the amount of sub-pixel aliasing removal. 104 // This can effect sharpness. 105 // 1.00 - upper limit (softer) 106 // 0.75 - default amount of filtering 107 // 0.50 - lower limit (sharper, less sub-pixel aliasing removal) 108 // 0.25 - almost off 109 // 0.00 - completely off 110 0.25, // FxaaFloat fxaaQualitySubpix, 111 // 112 // Only used on FXAA Quality. 113 // This used to be the FXAA_QUALITY__EDGE_THRESHOLD define. 114 // It is here now to allow easier tuning. 115 // The minimum amount of local contrast required to apply algorithm. 116 // 0.333 - too little (faster) 117 // 0.250 - low quality 118 // 0.166 - default 119 // 0.125 - high quality 120 // 0.063 - overkill (slower) 121 0.063, // FxaaFloat fxaaQualityEdgeThreshold, 122 // 123 // Only used on FXAA Quality. 124 // This used to be the FXAA_QUALITY__EDGE_THRESHOLD_MIN define. 125 // It is here now to allow easier tuning. 126 // Trims the algorithm from processing darks. 127 // 0.0833 - upper limit (default, the start of visible unfiltered edges) 128 // 0.0625 - high quality (faster) 129 // 0.0312 - visible limit (slower) 130 // Special notes when using FXAA_GREEN_AS_LUMA, 131 // Likely want to set this to zero. 132 // As colors that are mostly not-green 133 // will appear very dark in the green channel! 134 // Tune by looking at mostly non-green content, 135 // then start at zero and increase until aliasing is a problem. 136 0.0312, // FxaaFloat fxaaQualityEdgeThresholdMin, 137 // 138 // Only used on FXAA Console. 139 // This used to be the FXAA_CONSOLE__EDGE_SHARPNESS define. 140 // It is here now to allow easier tuning. 141 // This does not effect PS3, as this needs to be compiled in. 142 // Use FXAA_CONSOLE__PS3_EDGE_SHARPNESS for PS3. 143 // Due to the PS3 being ALU bound, 144 // there are only three safe values here: 2 and 4 and 8. 145 // These options use the shaders ability to a free *|/ by 2|4|8. 146 // For all other platforms can be a non-power of two. 147 // 8.0 is sharper (default!!!) 148 // 4.0 is softer 149 // 2.0 is really soft (good only for vector graphics inputs) 150 0.0, // FxaaFloat fxaaConsoleEdgeSharpness, 151 // 152 // Only used on FXAA Console. 153 // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD define. 154 // It is here now to allow easier tuning. 155 // This does not effect PS3, as this needs to be compiled in. 156 // Use FXAA_CONSOLE__PS3_EDGE_THRESHOLD for PS3. 157 // Due to the PS3 being ALU bound, 158 // there are only two safe values here: 1/4 and 1/8. 159 // These options use the shaders ability to a free *|/ by 2|4|8. 160 // The console setting has a different mapping than the quality setting. 161 // Other platforms can use other values. 162 // 0.125 leaves less aliasing, but is softer (default!!!) 163 // 0.25 leaves more aliasing, and is sharper 164 0.0, //FxaaFloat fxaaConsoleEdgeThreshold, 165 // 166 // Only used on FXAA Console. 167 // This used to be the FXAA_CONSOLE__EDGE_THRESHOLD_MIN define. 168 // It is here now to allow easier tuning. 169 // Trims the algorithm from processing darks. 170 // The console setting has a different mapping than the quality setting. 171 // This only applies when FXAA_EARLY_EXIT is 1. 172 // This does not apply to PS3, 173 // PS3 was simplified to avoid more shader instructions. 174 // 0.06 - faster but more aliasing in darks 175 // 0.05 - default 176 // 0.04 - slower and less aliasing in darks 177 // Special notes when using FXAA_GREEN_AS_LUMA, 178 // Likely want to set this to zero. 179 // As colors that are mostly not-green 180 // will appear very dark in the green channel! 181 // Tune by looking at mostly non-green content, 182 // then start at zero and increase until aliasing is a problem. 183 0.0, // FxaaFloat fxaaConsoleEdgeThresholdMin, 184 // 185 // Extra constants for 360 FXAA Console only. 186 // Use zeros or anything else for other platforms. 187 // These must be in physical constant registers and NOT immedates. 188 // Immedates will result in compiler un-optimizing. 189 // {xyzw} = float4(1.0, -1.0, 0.25, -0.25) 190 vec4(0) // FxaaFloat4 fxaaConsole360ConstDir 191 ).rgb; 192} 193