├── README.md ├── Shaders ├── 256color.fx ├── ASSMAA.fx ├── BasicMotionBlur.fx ├── FSMAA.fx ├── HQAA.fx ├── HQAALite.fx ├── ImageSoften.fx ├── QXAA.fx ├── STAA.fx ├── SmartBrightnessBooster.fx ├── TSMAA2.fx ├── deprecated │ ├── HQAA1.7.fx │ ├── HQLAA.fx │ ├── TSMAA.fx │ ├── XHQAA.fx │ └── readme.md └── readme.md ├── download └── main.zip └── textures ├── AreaTex.png ├── SearchTex.png └── readme.md /README.md: -------------------------------------------------------------------------------- 1 | Me pretending like I'm a programmer, yay! All the things I've made for ReShade so far. 2 | 3 | https://reshade.me/ 4 | -------------------------------------------------------------------------------- /Shaders/256color.fx: -------------------------------------------------------------------------------- 1 | /* 256 Color Converter for ReShade 2 | * 3 | * (Snaps sampled sRGB colors to values representing 8-bit 256 color mode) 4 | * 5 | * by lordbean 6 | * 7 | * (c) 2022 Derek Brush aka lordbean 8 | * derekbrush@gmail.com 9 | */ 10 | 11 | /** 12 | * Permission is hereby granted, free of charge, to any person obtaining a copy 13 | * this software and associated documentation files (the "Software"), to deal in 14 | * the Software without restriction, including without limitation the rights to 15 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 16 | * of the Software, and to permit persons to whom the Software is furnished to 17 | * do so, subject to the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be included in 20 | * all copies or substantial portions of the Software. As clarification, there 21 | * is no requirement that the copyright notice and permission be included in 22 | * binary distributions of the Software. 23 | **/ 24 | 25 | /*------------------------------------------------------------------------------ 26 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 | * SOFTWARE. 33 | *-------------------------------------------------------------------------------*/ 34 | 35 | #include "ReShade.fxh" 36 | 37 | float3 EightBitEmulationPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 38 | { 39 | float3 original = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy).rgb; 40 | float3 output; 41 | output.b = 0.333333 * round(original.b / 0.333333); 42 | output.rg = 0.142857 * round(original.rg / 0.142857); 43 | return output; 44 | } 45 | 46 | technique EightBitEmulation 47 | { 48 | pass Emulate256Color 49 | { 50 | VertexShader = PostProcessVS; 51 | PixelShader = EightBitEmulationPS; 52 | } 53 | } -------------------------------------------------------------------------------- /Shaders/ASSMAA.fx: -------------------------------------------------------------------------------- 1 | /** 2 | * _______ ___ ___ ___ ___ 3 | * / || \/ | / \ / \ 4 | * | (---- | \ / | / ^ \ / ^ \ 5 | * \ \ | |\/| | / /_\ \ / /_\ \ 6 | * ----) | | | | | / _____ \ / _____ \ 7 | * |_______/ |__| |__| /__/ \__\ /__/ \__\ 8 | * 9 | * E N H A N C E D 10 | * S U B P I X E L M O R P H O L O G I C A L A N T I A L I A S I N G 11 | * 12 | * for ReShade 3.0+ 13 | */ 14 | 15 | //------------------- Preprocessor Settings ------------------- 16 | 17 | #if !defined(SMAA_PRESET_LOW) && !defined(SMAA_PRESET_MEDIUM) && !defined(SMAA_PRESET_HIGH) && !defined(SMAA_PRESET_ULTRA) 18 | #define SMAA_PRESET_CUSTOM // Do not use a quality preset by default 19 | #endif 20 | 21 | //----------------------- UI Variables ------------------------ 22 | 23 | #include "ReShadeUI.fxh" 24 | 25 | uniform int EdgeDetectionType < __UNIFORM_COMBO_INT1 26 | ui_items = "Luminance edge detection\0Color edge detection\0Both, biasing Clarity\0Both, biasing Anti-Aliasing\0"; 27 | ui_label = "Edge Detection Type"; 28 | > = 3; 29 | 30 | #ifdef SMAA_PRESET_CUSTOM 31 | uniform float EdgeDetectionThreshold < __UNIFORM_DRAG_FLOAT1 32 | ui_min = 0.05; ui_max = 0.2; ui_step = 0.001; 33 | ui_label = "Edge Detection Threshold"; 34 | > = 0.0625; 35 | 36 | uniform int MaxSearchSteps < __UNIFORM_SLIDER_INT1 37 | ui_min = 1; ui_max = 112; 38 | ui_label = "Max Search Steps"; 39 | ui_tooltip = "Determines the radius SMAA will search for aliased edges"; 40 | > = 112; 41 | 42 | uniform int MaxSearchStepsDiagonal < __UNIFORM_SLIDER_INT1 43 | ui_min = 1; ui_max = 20; 44 | ui_label = "Max Search Steps Diagonal"; 45 | ui_tooltip = "Determines the radius SMAA will search for diagonal aliased edges"; 46 | > = 20; 47 | 48 | uniform int CornerRounding < __UNIFORM_SLIDER_INT1 49 | ui_min = 0; ui_max = 100; 50 | ui_label = "Corner Rounding"; 51 | ui_tooltip = "Determines the percent of anti-aliasing to apply to corners"; 52 | > = 10; 53 | 54 | uniform float ContrastAdaptationFactor < __UNIFORM_DRAG_FLOAT1 55 | ui_min = 1.0; ui_max = 8.0; ui_step = 0.01; 56 | ui_label = "Local Contrast Adaptation Factor"; 57 | ui_tooltip = "Low values preserve detail, high values increase anti-aliasing effect"; 58 | > = 1.60; 59 | #endif 60 | 61 | uniform int DebugOutput < __UNIFORM_COMBO_INT1 62 | ui_items = "None\0View edges\0View weights\0"; 63 | ui_label = "Debug Output"; 64 | > = false; 65 | 66 | #ifdef SMAA_PRESET_CUSTOM 67 | #define SMAA_THRESHOLD EdgeDetectionThreshold 68 | #define SMAA_MAX_SEARCH_STEPS MaxSearchSteps 69 | #define SMAA_CORNER_ROUNDING CornerRounding 70 | #define SMAA_MAX_SEARCH_STEPS_DIAG MaxSearchStepsDiagonal 71 | #define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR ContrastAdaptationFactor 72 | #endif 73 | 74 | #define SMAA_RT_METRICS float4(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT, BUFFER_WIDTH, BUFFER_HEIGHT) 75 | #define SMAA_CUSTOM_SL 1 76 | 77 | #define SMAATexture2D(tex) sampler tex 78 | #define SMAATexturePass2D(tex) tex 79 | #define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, coord)) 80 | #define SMAASampleLevelZeroPoint(tex, coord) SMAASampleLevelZero(tex, coord) 81 | #define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlodoffset(tex, float4(coord, coord), offset) 82 | #define SMAASample(tex, coord) tex2D(tex, coord) 83 | #define SMAASamplePoint(tex, coord) SMAASample(tex, coord) 84 | #define SMAASampleOffset(tex, coord, offset) tex2Doffset(tex, coord, offset) 85 | #define SMAA_BRANCH [branch] 86 | #define SMAA_FLATTEN [flatten] 87 | 88 | #if (__RENDERER__ == 0xb000 || __RENDERER__ == 0xb100) 89 | #define SMAAGather(tex, coord) tex2Dgather(tex, coord, 0) 90 | #endif 91 | 92 | #include "SMAA.fxh" 93 | #include "ReShade.fxh" 94 | 95 | // Textures 96 | 97 | texture edgesTex < pooled = true; > 98 | { 99 | Width = BUFFER_WIDTH; 100 | Height = BUFFER_HEIGHT; 101 | Format = RG8; 102 | }; 103 | texture blendTex < pooled = true; > 104 | { 105 | Width = BUFFER_WIDTH; 106 | Height = BUFFER_HEIGHT; 107 | Format = RGBA8; 108 | }; 109 | 110 | texture areaTex < source = "AreaTex.png"; > 111 | { 112 | Width = 160; 113 | Height = 560; 114 | Format = RG8; 115 | }; 116 | texture searchTex < source = "SearchTex.png"; > 117 | { 118 | Width = 64; 119 | Height = 16; 120 | Format = R8; 121 | }; 122 | 123 | // Samplers 124 | 125 | sampler colorGammaSampler 126 | { 127 | Texture = ReShade::BackBufferTex; 128 | AddressU = Clamp; AddressV = Clamp; 129 | MipFilter = Point; MinFilter = Linear; MagFilter = Linear; 130 | SRGBTexture = false; 131 | }; 132 | sampler colorLinearSampler 133 | { 134 | Texture = ReShade::BackBufferTex; 135 | AddressU = Clamp; AddressV = Clamp; 136 | MipFilter = Point; MinFilter = Linear; MagFilter = Linear; 137 | SRGBTexture = true; 138 | }; 139 | sampler edgesSampler 140 | { 141 | Texture = edgesTex; 142 | AddressU = Clamp; AddressV = Clamp; 143 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 144 | SRGBTexture = false; 145 | }; 146 | sampler blendSampler 147 | { 148 | Texture = blendTex; 149 | AddressU = Clamp; AddressV = Clamp; 150 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 151 | SRGBTexture = false; 152 | }; 153 | sampler areaSampler 154 | { 155 | Texture = areaTex; 156 | AddressU = Clamp; AddressV = Clamp; AddressW = Clamp; 157 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 158 | SRGBTexture = false; 159 | }; 160 | sampler searchSampler 161 | { 162 | Texture = searchTex; 163 | AddressU = Clamp; AddressV = Clamp; AddressW = Clamp; 164 | MipFilter = Point; MinFilter = Point; MagFilter = Point; 165 | SRGBTexture = false; 166 | }; 167 | 168 | // Vertex shaders 169 | 170 | void SMAAEdgeDetectionWrapVS( 171 | in uint id : SV_VertexID, 172 | out float4 position : SV_Position, 173 | out float2 texcoord : TEXCOORD0, 174 | out float4 offset[3] : TEXCOORD1) 175 | { 176 | PostProcessVS(id, position, texcoord); 177 | SMAAEdgeDetectionVS(texcoord, offset); 178 | } 179 | void SMAABlendingWeightCalculationWrapVS( 180 | in uint id : SV_VertexID, 181 | out float4 position : SV_Position, 182 | out float2 texcoord : TEXCOORD0, 183 | out float2 pixcoord : TEXCOORD1, 184 | out float4 offset[3] : TEXCOORD2) 185 | { 186 | PostProcessVS(id, position, texcoord); 187 | SMAABlendingWeightCalculationVS(texcoord, pixcoord, offset); 188 | } 189 | void SMAANeighborhoodBlendingWrapVS( 190 | in uint id : SV_VertexID, 191 | out float4 position : SV_Position, 192 | out float2 texcoord : TEXCOORD0, 193 | out float4 offset : TEXCOORD1) 194 | { 195 | PostProcessVS(id, position, texcoord); 196 | SMAANeighborhoodBlendingVS(texcoord, offset); 197 | } 198 | 199 | // Pixel shaders 200 | 201 | float2 SMAAEdgeDetectionWrapPS( 202 | float4 position : SV_Position, 203 | float2 texcoord : TEXCOORD0, 204 | float4 offset[3] : TEXCOORD1) : SV_Target 205 | { 206 | if (EdgeDetectionType == 0) 207 | return SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaSampler); 208 | else if (EdgeDetectionType == 1) 209 | return SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaSampler); 210 | else if (EdgeDetectionType == 2) 211 | return (SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaSampler) && SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaSampler)); 212 | else 213 | return ((SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaSampler) + SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaSampler))/2); 214 | } 215 | float4 SMAABlendingWeightCalculationWrapPS( 216 | float4 position : SV_Position, 217 | float2 texcoord : TEXCOORD0, 218 | float2 pixcoord : TEXCOORD1, 219 | float4 offset[3] : TEXCOORD2) : SV_Target 220 | { 221 | return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesSampler, areaSampler, searchSampler, 0.0); 222 | } 223 | 224 | float3 SMAANeighborhoodBlendingWrapPS( 225 | float4 position : SV_Position, 226 | float2 texcoord : TEXCOORD0, 227 | float4 offset : TEXCOORD1) : SV_Target 228 | { 229 | if (DebugOutput == 1) 230 | return tex2D(edgesSampler, texcoord).rgb; 231 | if (DebugOutput == 2) 232 | return tex2D(blendSampler, texcoord).rgb; 233 | 234 | return SMAANeighborhoodBlendingPS(texcoord, offset, colorLinearSampler, blendSampler).rgb; 235 | } 236 | 237 | // Rendering passes 238 | 239 | technique ASSMAA 240 | { 241 | pass EdgeDetectionPass 242 | { 243 | VertexShader = SMAAEdgeDetectionWrapVS; 244 | PixelShader = SMAAEdgeDetectionWrapPS; 245 | RenderTarget = edgesTex; 246 | ClearRenderTargets = true; 247 | StencilEnable = true; 248 | StencilPass = REPLACE; 249 | StencilRef = 1; 250 | } 251 | pass BlendWeightCalculationPass 252 | { 253 | VertexShader = SMAABlendingWeightCalculationWrapVS; 254 | PixelShader = SMAABlendingWeightCalculationWrapPS; 255 | RenderTarget = blendTex; 256 | ClearRenderTargets = true; 257 | StencilEnable = true; 258 | StencilPass = KEEP; 259 | StencilFunc = EQUAL; 260 | StencilRef = 1; 261 | } 262 | pass NeighborhoodBlendingPass 263 | { 264 | VertexShader = SMAANeighborhoodBlendingWrapVS; 265 | PixelShader = SMAANeighborhoodBlendingWrapPS; 266 | StencilEnable = false; 267 | SRGBWriteEnable = true; 268 | } 269 | } -------------------------------------------------------------------------------- /Shaders/BasicMotionBlur.fx: -------------------------------------------------------------------------------- 1 | 2 | // This shader is copyright (c) Derek Brush aka "lordbean" (derekbrush@gmail.com) 3 | 4 | /** Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to 9 | * do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. As clarification, there 13 | * is no requirement that the copyright notice and permission be included in 14 | * binary distributions of the Software. 15 | **/ 16 | 17 | /*------------------------------------------------------------------------------ 18 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | *-------------------------------------------------------------------------------*/ 26 | 27 | 28 | /*****************************************************************************************************************************************/ 29 | /*********************************************************** UI SETUP START **************************************************************/ 30 | /*****************************************************************************************************************************************/ 31 | 32 | #include "ReShadeUI.fxh" 33 | 34 | uniform float frameweight 35 | < 36 | ui_type = "slider"; 37 | ui_spacing = 6; 38 | ui_label = "Previous Frame Weight"; 39 | ui_min = 0; ui_max = 0.75; ui_step = 0.01; 40 | ui_tooltip = "Amount of weight given to previous frame.\n" 41 | "Determines the strength of the blur effect."; 42 | > = 0.4; 43 | 44 | uniform float effectstrength 45 | < 46 | ui_type = "slider"; 47 | ui_label = "Falloff Delay"; 48 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.01; 49 | ui_tooltip = "Adjusts how quickly blurred areas\n" 50 | "normalize. 0.0 normalizes in one\n" 51 | "frame, 1.0 normalizes slowly."; 52 | > = 0.8; 53 | 54 | #define __BB ReShade::BackBuffer 55 | 56 | /*****************************************************************************************************************************************/ 57 | /*********************************************************** UI SETUP END ****************************************************************/ 58 | /*****************************************************************************************************************************************/ 59 | 60 | /***************************************************************************************************************************************/ 61 | /*********************************************************** SHADER SETUP START ********************************************************/ 62 | /***************************************************************************************************************************************/ 63 | 64 | #include "ReShade.fxh" 65 | 66 | texture oldBBstore 67 | { 68 | Width = BUFFER_WIDTH; 69 | Height = BUFFER_HEIGHT; 70 | Format = RGBA16F; 71 | }; 72 | sampler oldBB {Texture = oldBBstore;}; 73 | 74 | texture orgBBstore 75 | { 76 | Width = BUFFER_WIDTH; 77 | Height = BUFFER_HEIGHT; 78 | Format = RGBA16F; 79 | }; 80 | sampler orgBB {Texture = orgBBstore;}; 81 | 82 | texture tempBBstore 83 | { 84 | Width = BUFFER_WIDTH; 85 | Height = BUFFER_HEIGHT; 86 | Format = RGBA16F; 87 | }; 88 | sampler tempBB {Texture = tempBBstore;}; 89 | 90 | /*****************************************************************************************************************************************/ 91 | /*********************************************************** SHADER SETUP END ************************************************************/ 92 | /*****************************************************************************************************************************************/ 93 | 94 | float4 BlendPreviousFrame(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_TARGET 95 | { 96 | float4 current = tex2Dlod(__BB, texcoord.xyxy); 97 | float4 old = tex2Dlod(oldBB, texcoord.xyxy); 98 | float4 org = tex2Dlod(orgBB, texcoord.xyxy); 99 | float4 weighted = lerp(org, old, effectstrength); 100 | return lerp(current, weighted, frameweight); 101 | } 102 | 103 | float4 DumpBuffer(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_TARGET 104 | { 105 | return tex2Dlod(__BB, texcoord.xyxy); 106 | } 107 | 108 | float4 DumpSnapshot(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_TARGET 109 | { 110 | return tex2Dlod(tempBB, texcoord.xyxy); 111 | } 112 | 113 | technique basicmotionblur < 114 | ui_label = "Basic Motion Blur"; 115 | > 116 | { 117 | pass preblursnapshot 118 | { 119 | VertexShader = PostProcessVS; 120 | PixelShader = DumpBuffer; 121 | RenderTarget = tempBBstore; 122 | ClearRenderTargets = true; 123 | } 124 | pass motionblur 125 | { 126 | VertexShader = PostProcessVS; 127 | PixelShader = BlendPreviousFrame; 128 | } 129 | pass savesnapshot 130 | { 131 | VertexShader = PostProcessVS; 132 | PixelShader = DumpSnapshot; 133 | RenderTarget = orgBBstore; 134 | ClearRenderTargets = true; 135 | } 136 | pass saveblurredbuffer 137 | { 138 | VertexShader = PostProcessVS; 139 | PixelShader = DumpBuffer; 140 | RenderTarget = oldBBstore; 141 | ClearRenderTargets = true; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /Shaders/FSMAA.fx: -------------------------------------------------------------------------------- 1 | /** 2 | * _______ ___ ___ ___ ___ 3 | * / || \/ | / \ / \ 4 | * | (---- | \ / | / ^ \ / ^ \ 5 | * \ \ | |\/| | / /_\ \ / /_\ \ 6 | * ----) | | | | | / _____ \ / _____ \ 7 | * |_______/ |__| |__| /__/ \__\ /__/ \__\ 8 | * 9 | * E N H A N C E D 10 | * S U B P I X E L M O R P H O L O G I C A L A N T I A L I A S I N G 11 | * 12 | * for ReShade 3.0+ 13 | */ 14 | 15 | //------------------- Preprocessor Settings ------------------- 16 | 17 | #if !defined(SMAA_PRESET_LOW) && !defined(SMAA_PRESET_MEDIUM) && !defined(SMAA_PRESET_HIGH) && !defined(SMAA_PRESET_ULTRA) 18 | #define SMAA_PRESET_CUSTOM // Do not use a quality preset by default 19 | #define SMAA_DISABLE_DIAG_DETECTION 20 | #define SMAA_DISABLE_DEPTH_BUFFER 21 | #endif 22 | 23 | //----------------------- UI Variables ------------------------ 24 | 25 | #include "ReShadeUI.fxh" 26 | 27 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 28 | uniform int EdgeDetectionType < __UNIFORM_COMBO_INT1 29 | ui_items = "Luminance edge detection\0Color edge detection\0Depth edge detection\0"; 30 | ui_label = "Edge Detection Type"; 31 | > = 1; 32 | #else 33 | uniform int EdgeDetectionType < __UNIFORM_COMBO_INT1 34 | ui_items = "Luminance edge detection\0Color edge detection\0"; 35 | ui_label = "Edge Detection Type"; 36 | > = 1; 37 | #endif 38 | 39 | 40 | #ifdef SMAA_PRESET_CUSTOM 41 | uniform float EdgeDetectionThreshold < __UNIFORM_DRAG_FLOAT1 42 | ui_min = 0.05; ui_max = 0.20; ui_step = 0.001; 43 | ui_tooltip = "Edge detection threshold. If SMAA misses some edges try lowering this slightly."; 44 | ui_label = "Edge Detection Threshold"; 45 | > = 0.10; 46 | 47 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 48 | uniform float DepthEdgeDetectionThreshold < __UNIFORM_DRAG_FLOAT1 49 | ui_min = 0.001; ui_max = 0.10; ui_step = 0.001; 50 | ui_tooltip = "Depth Edge detection threshold. If SMAA misses some edges try lowering this slightly."; 51 | ui_label = "Depth Edge Detection Threshold"; 52 | > = 0.01; 53 | #endif 54 | 55 | uniform int MaxSearchSteps < __UNIFORM_SLIDER_INT1 56 | ui_min = 0; ui_max = 112; 57 | ui_label = "Max Search Steps"; 58 | ui_tooltip = "Determines the radius SMAA will search for aliased edges."; 59 | > = 32; 60 | 61 | #ifndef SMAA_DISABLE_DIAG_DETECTION 62 | uniform int MaxSearchStepsDiagonal < __UNIFORM_SLIDER_INT1 63 | ui_min = 0; ui_max = 20; 64 | ui_label = "Max Search Steps Diagonal"; 65 | ui_tooltip = "Determines the radius SMAA will search for diagonal aliased edges"; 66 | > = 16; 67 | #endif 68 | 69 | #ifndef SMAA_DISABLE_CORNER_DETECTION 70 | uniform int CornerRounding < __UNIFORM_SLIDER_INT1 71 | ui_min = 0; ui_max = 100; 72 | ui_label = "Corner Rounding"; 73 | ui_tooltip = "Determines the percent of anti-aliasing to apply to corners."; 74 | > = 25; 75 | #endif 76 | 77 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 78 | uniform bool PredicationEnabled < __UNIFORM_INPUT_BOOL1 79 | ui_label = "Enable Predicated Thresholding"; 80 | > = false; 81 | 82 | uniform float PredicationThreshold < __UNIFORM_DRAG_FLOAT1 83 | ui_min = 0.005; ui_max = 1.00; ui_step = 0.01; 84 | ui_tooltip = "Threshold to be used in the additional predication buffer."; 85 | ui_label = "Predication Threshold"; 86 | > = 0.01; 87 | 88 | uniform float PredicationScale < __UNIFORM_SLIDER_FLOAT1 89 | ui_min = 1; ui_max = 8; 90 | ui_tooltip = "How much to scale the global threshold used for luma or color edge."; 91 | ui_label = "Predication Scale"; 92 | > = 2.0; 93 | 94 | uniform float PredicationStrength < __UNIFORM_SLIDER_FLOAT1 95 | ui_min = 0; ui_max = 10; 96 | ui_tooltip = "How much to locally decrease the threshold."; 97 | ui_label = "Predication Strength"; 98 | > = 0.4; 99 | #endif 100 | #endif 101 | 102 | uniform int DebugOutput < __UNIFORM_COMBO_INT1 103 | ui_items = "None\0View edges\0View weights\0"; 104 | ui_label = "Debug Output"; 105 | > = false; 106 | 107 | #ifdef SMAA_PRESET_CUSTOM 108 | #define SMAA_THRESHOLD EdgeDetectionThreshold 109 | #define SMAA_MAX_SEARCH_STEPS MaxSearchSteps 110 | #ifndef SMAA_DISABLE_CORNER_DETECTION 111 | #define SMAA_CORNER_ROUNDING CornerRounding 112 | #endif 113 | #ifndef SMAA_DISABLE_DIAG_DETECTION 114 | #define SMAA_MAX_SEARCH_STEPS_DIAG MaxSearchStepsDiagonal 115 | #endif 116 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 117 | #define SMAA_DEPTH_THRESHOLD DepthEdgeDetectionThreshold 118 | #define SMAA_PREDICATION PredicationEnabled 119 | #define SMAA_PREDICATION_THRESHOLD PredicationThreshold 120 | #define SMAA_PREDICATION_SCALE PredicationScale 121 | #define SMAA_PREDICATION_STRENGTH PredicationStrength 122 | #else 123 | #define SMAA_PREDICATION false 124 | #endif 125 | #endif 126 | 127 | #define SMAA_RT_METRICS float4(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT, BUFFER_WIDTH, BUFFER_HEIGHT) 128 | #define SMAA_CUSTOM_SL 1 129 | 130 | #define SMAATexture2D(tex) sampler tex 131 | #define SMAATexturePass2D(tex) tex 132 | #define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, coord)) 133 | #define SMAASampleLevelZeroPoint(tex, coord) SMAASampleLevelZero(tex, coord) 134 | #define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlodoffset(tex, float4(coord, coord), offset) 135 | #define SMAASample(tex, coord) tex2D(tex, coord) 136 | #define SMAASamplePoint(tex, coord) SMAASample(tex, coord) 137 | #define SMAASampleOffset(tex, coord, offset) tex2Doffset(tex, coord, offset) 138 | #define SMAA_BRANCH [branch] 139 | #define SMAA_FLATTEN [flatten] 140 | 141 | #if (__RENDERER__ == 0xb000 || __RENDERER__ == 0xb100) 142 | #define SMAAGather(tex, coord) tex2Dgather(tex, coord, 0) 143 | #endif 144 | 145 | #include "SMAA.fxh" 146 | #include "ReShade.fxh" 147 | 148 | // Textures 149 | 150 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 151 | texture depthTex < pooled = true; > 152 | { 153 | Width = BUFFER_WIDTH; 154 | Height = BUFFER_HEIGHT; 155 | Format = R16F; 156 | }; 157 | #endif 158 | 159 | texture edgesTex < pooled = true; > 160 | { 161 | Width = BUFFER_WIDTH; 162 | Height = BUFFER_HEIGHT; 163 | Format = RG8; 164 | }; 165 | texture blendTex < pooled = true; > 166 | { 167 | Width = BUFFER_WIDTH; 168 | Height = BUFFER_HEIGHT; 169 | Format = RGBA8; 170 | }; 171 | 172 | texture areaTex < source = "AreaTex.png"; > 173 | { 174 | Width = 160; 175 | Height = 560; 176 | Format = RG8; 177 | }; 178 | texture searchTex < source = "SearchTex.png"; > 179 | { 180 | Width = 64; 181 | Height = 16; 182 | Format = R8; 183 | }; 184 | 185 | // Samplers 186 | 187 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 188 | sampler depthLinearSampler 189 | { 190 | Texture = depthTex; 191 | }; 192 | #endif 193 | 194 | sampler colorGammaSampler 195 | { 196 | Texture = ReShade::BackBufferTex; 197 | AddressU = Clamp; AddressV = Clamp; 198 | MipFilter = Point; MinFilter = Linear; MagFilter = Linear; 199 | SRGBTexture = false; 200 | }; 201 | sampler colorLinearSampler 202 | { 203 | Texture = ReShade::BackBufferTex; 204 | AddressU = Clamp; AddressV = Clamp; 205 | MipFilter = Point; MinFilter = Linear; MagFilter = Linear; 206 | SRGBTexture = true; 207 | }; 208 | sampler edgesSampler 209 | { 210 | Texture = edgesTex; 211 | AddressU = Clamp; AddressV = Clamp; 212 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 213 | SRGBTexture = false; 214 | }; 215 | sampler blendSampler 216 | { 217 | Texture = blendTex; 218 | AddressU = Clamp; AddressV = Clamp; 219 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 220 | SRGBTexture = false; 221 | }; 222 | sampler areaSampler 223 | { 224 | Texture = areaTex; 225 | AddressU = Clamp; AddressV = Clamp; AddressW = Clamp; 226 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 227 | SRGBTexture = false; 228 | }; 229 | sampler searchSampler 230 | { 231 | Texture = searchTex; 232 | AddressU = Clamp; AddressV = Clamp; AddressW = Clamp; 233 | MipFilter = Point; MinFilter = Point; MagFilter = Point; 234 | SRGBTexture = false; 235 | }; 236 | 237 | // Vertex shaders 238 | 239 | void SMAAEdgeDetectionWrapVS( 240 | in uint id : SV_VertexID, 241 | out float4 position : SV_Position, 242 | out float2 texcoord : TEXCOORD0, 243 | out float4 offset[3] : TEXCOORD1) 244 | { 245 | PostProcessVS(id, position, texcoord); 246 | SMAAEdgeDetectionVS(texcoord, offset); 247 | } 248 | void SMAABlendingWeightCalculationWrapVS( 249 | in uint id : SV_VertexID, 250 | out float4 position : SV_Position, 251 | out float2 texcoord : TEXCOORD0, 252 | out float2 pixcoord : TEXCOORD1, 253 | out float4 offset[3] : TEXCOORD2) 254 | { 255 | PostProcessVS(id, position, texcoord); 256 | SMAABlendingWeightCalculationVS(texcoord, pixcoord, offset); 257 | } 258 | void SMAANeighborhoodBlendingWrapVS( 259 | in uint id : SV_VertexID, 260 | out float4 position : SV_Position, 261 | out float2 texcoord : TEXCOORD0, 262 | out float4 offset : TEXCOORD1) 263 | { 264 | PostProcessVS(id, position, texcoord); 265 | SMAANeighborhoodBlendingVS(texcoord, offset); 266 | } 267 | 268 | // Pixel shaders 269 | 270 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 271 | float SMAADepthLinearizationPS( 272 | float4 position : SV_Position, 273 | float2 texcoord : TEXCOORD) : SV_Target 274 | { 275 | return ReShade::GetLinearizedDepth(texcoord); 276 | } 277 | #endif 278 | 279 | float2 SMAAEdgeDetectionWrapPS( 280 | float4 position : SV_Position, 281 | float2 texcoord : TEXCOORD0, 282 | float4 offset[3] : TEXCOORD1) : SV_Target 283 | { 284 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 285 | if (EdgeDetectionType == 0 && SMAA_PREDICATION == true) 286 | return SMAALumaEdgePredicationDetectionPS(texcoord, offset, colorGammaSampler, depthLinearSampler); 287 | else 288 | #endif 289 | if (EdgeDetectionType == 0) 290 | return SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaSampler); 291 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 292 | if (EdgeDetectionType == 2) 293 | return SMAADepthEdgeDetectionPS(texcoord, offset, depthLinearSampler); 294 | 295 | if (SMAA_PREDICATION) 296 | return SMAAColorEdgePredicationDetectionPS(texcoord, offset, colorGammaSampler, depthLinearSampler); 297 | else 298 | #endif 299 | return SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaSampler); 300 | } 301 | float4 SMAABlendingWeightCalculationWrapPS( 302 | float4 position : SV_Position, 303 | float2 texcoord : TEXCOORD0, 304 | float2 pixcoord : TEXCOORD1, 305 | float4 offset[3] : TEXCOORD2) : SV_Target 306 | { 307 | return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesSampler, areaSampler, searchSampler, 0.0); 308 | } 309 | 310 | float3 SMAANeighborhoodBlendingWrapPS( 311 | float4 position : SV_Position, 312 | float2 texcoord : TEXCOORD0, 313 | float4 offset : TEXCOORD1) : SV_Target 314 | { 315 | if (DebugOutput == 1) 316 | return tex2D(edgesSampler, texcoord).rgb; 317 | if (DebugOutput == 2) 318 | return tex2D(blendSampler, texcoord).rgb; 319 | 320 | return SMAANeighborhoodBlendingPS(texcoord, offset, colorLinearSampler, blendSampler).rgb; 321 | } 322 | 323 | // Rendering passes 324 | 325 | technique SMAA 326 | < ui_tooltip = "Fast SMAA skips most of the enhanced features of the shader in order to\n" 327 | "apply its basic effect to the scene with a very low overhead.\n\n" 328 | "There are no changes to any of the core enhanced SMAA code, only the\n" 329 | "addition of one built-in pre-processor define plus one new one I created.\n" 330 | "This shader can be reverted to full enhanced SMAA by deleting the 2 added\n" 331 | "pre-processor defines if so desired. This UI tooltip is the ONLY new\n" 332 | "piece of code in the shader."; > 333 | { 334 | #ifndef SMAA_DISABLE_DEPTH_BUFFER 335 | pass LinearizeDepthPass 336 | { 337 | VertexShader = PostProcessVS; 338 | PixelShader = SMAADepthLinearizationPS; 339 | RenderTarget = depthTex; 340 | } 341 | #endif 342 | pass EdgeDetectionPass 343 | { 344 | VertexShader = SMAAEdgeDetectionWrapVS; 345 | PixelShader = SMAAEdgeDetectionWrapPS; 346 | RenderTarget = edgesTex; 347 | ClearRenderTargets = true; 348 | StencilEnable = true; 349 | StencilPass = REPLACE; 350 | StencilRef = 1; 351 | } 352 | pass BlendWeightCalculationPass 353 | { 354 | VertexShader = SMAABlendingWeightCalculationWrapVS; 355 | PixelShader = SMAABlendingWeightCalculationWrapPS; 356 | RenderTarget = blendTex; 357 | ClearRenderTargets = true; 358 | StencilEnable = true; 359 | StencilPass = KEEP; 360 | StencilFunc = EQUAL; 361 | StencilRef = 1; 362 | } 363 | pass NeighborhoodBlendingPass 364 | { 365 | VertexShader = SMAANeighborhoodBlendingWrapVS; 366 | PixelShader = SMAANeighborhoodBlendingWrapPS; 367 | StencilEnable = false; 368 | SRGBWriteEnable = true; 369 | } 370 | } -------------------------------------------------------------------------------- /Shaders/ImageSoften.fx: -------------------------------------------------------------------------------- 1 | /* Image Softening for ReShade 3.1.1+ 2 | * 3 | * (Smart Error-Controlled Geometric Pattern Average Blur Shader) 4 | * 5 | * by lordbean 6 | * 7 | * (c) 2022 Derek Brush aka lordbean 8 | * derekbrush@gmail.com 9 | */ 10 | 11 | /** 12 | * Permission is hereby granted, free of charge, to any person obtaining a copy 13 | * this software and associated documentation files (the "Software"), to deal in 14 | * the Software without restriction, including without limitation the rights to 15 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 16 | * of the Software, and to permit persons to whom the Software is furnished to 17 | * do so, subject to the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be included in 20 | * all copies or substantial portions of the Software. As clarification, there 21 | * is no requirement that the copyright notice and permission be included in 22 | * binary distributions of the Software. 23 | **/ 24 | 25 | /*------------------------------------------------------------------------------ 26 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 | * SOFTWARE. 33 | *-------------------------------------------------------------------------------*/ 34 | 35 | 36 | /*****************************************************************************************************************************************/ 37 | /*********************************************************** UI SETUP START **************************************************************/ 38 | /*****************************************************************************************************************************************/ 39 | 40 | #include "ReShadeUI.fxh" 41 | 42 | uniform int ImageSoftenIntroduction < 43 | ui_spacing = 3; 44 | ui_type = "radio"; 45 | ui_label = "Version: 1.0"; 46 | ui_text = "-------------------------------------------------------------------------\n" 47 | "Smart Image Softening, a shader by lordbean\n" 48 | "https://github.com/lordbean-git/reshade-shaders/\n" 49 | "-------------------------------------------------------------------------\n\n" 50 | "This shader measures multiple geometric patterns around each pixel and\n" 51 | "controls for spurious readings by omitting the strongest and weakest\n" 52 | "recorded patterns. The final result is interpolated with the original dot\n" 53 | "to produce a subtle blur effect.\n\n" 54 | "-------------------------------------------------------------------------"; 55 | ui_tooltip = "Based on HQAA 27.5"; 56 | ui_category = "About"; 57 | ui_category_closed = true; 58 | >; 59 | 60 | uniform int ImageSoftenIntroEOF < 61 | ui_type = "radio"; 62 | ui_label = " "; 63 | ui_text = "\n--------------------------------------------------------------------------------"; 64 | >; 65 | 66 | uniform float ImageSoftenStrength < 67 | ui_type = "slider"; 68 | ui_min = 0.0; 69 | ui_max = 1.0; 70 | ui_step = 0.001; 71 | ui_label = "Softening Strength"; 72 | ui_tooltip = "Interpolation factor with original pixel"; 73 | > = 0.75; 74 | 75 | uniform float ImageSoftenOffset < 76 | ui_type = "slider"; 77 | ui_min = 0.0; 78 | ui_max = 2.0; 79 | ui_step = 0.001; 80 | ui_label = "Sampling Offset"; 81 | ui_tooltip = "Distance (in pixels) from center dot\n" 82 | "to measure geometric patterns.\n" 83 | "Lower gives the middle more weight,\n" 84 | "higher increases the amount of blur."; 85 | > = 0.75; 86 | 87 | uniform int ImageSoftenEOF < 88 | ui_type = "radio"; 89 | ui_label = " "; 90 | ui_text = "\n--------------------------------------------------------------------------------"; 91 | >; 92 | 93 | /*****************************************************************************************************************************************/ 94 | /*********************************************************** UI SETUP END ****************************************************************/ 95 | /*****************************************************************************************************************************************/ 96 | 97 | /*****************************************************************************************************************************************/ 98 | /******************************************************** SYNTAX SETUP START *************************************************************/ 99 | /*****************************************************************************************************************************************/ 100 | 101 | #define ISmax3(x,y,z) max(max(x,y),z) 102 | #define ISmax4(w,x,y,z) max(max(w,x),max(y,z)) 103 | #define ISmax5(v,w,x,y,z) max(max(max(v,w),x),max(y,z)) 104 | #define ISmax6(u,v,w,x,y,z) max(max(max(u,v),max(w,x)),max(y,z)) 105 | #define ISmax7(t,u,v,w,x,y,z) max(max(max(t,u),max(v,w)),max(max(x,y),z)) 106 | #define ISmax8(s,t,u,v,w,x,y,z) max(max(max(s,t),max(u,v)),max(max(w,x),max(y,z))) 107 | #define ISmax9(r,s,t,u,v,w,x,y,z) max(max(max(max(r,s),t),max(u,v)),max(max(w,x),max(y,z))) 108 | #define ISmax10(q,r,s,t,u,v,w,x,y,z) max(max(max(max(q,r),max(s,t)),max(u,v)),max(max(w,x),max(y,z))) 109 | #define ISmax11(p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(p,q),max(r,s)),max(max(t,u),v)),max(max(w,x),max(y,z))) 110 | #define ISmax12(o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(o,p),max(q,r)),max(max(s,t),max(u,v))),max(max(w,x),max(y,z))) 111 | #define ISmax13(n,o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(n,o),max(p,q)),max(max(r,s),max(t,u))),max(max(max(v,w),x),max(y,z))) 112 | #define ISmax14(m,n,o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(m,n),max(o,p)),max(max(q,r),max(s,t))),max(max(max(u,v),max(w,x)),max(y,z))) 113 | #define ISmax15(l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(l,m),max(n,o)),max(max(p,q),max(r,s))),max(max(max(t,u),max(v,w)),max(max(x,y),z))) 114 | #define ISmax16(k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(k,l),max(m,n)),max(max(o,p),max(q,r))),max(max(max(s,t),max(u,v)),max(max(w,x),max(y,z)))) 115 | 116 | #define ISmin3(x,y,z) min(min(x,y),z) 117 | #define ISmin4(w,x,y,z) min(min(w,x),min(y,z)) 118 | #define ISmin5(v,w,x,y,z) min(min(min(v,w),x),min(y,z)) 119 | #define ISmin6(u,v,w,x,y,z) min(min(min(u,v),min(w,x)),min(y,z)) 120 | #define ISmin7(t,u,v,w,x,y,z) min(min(min(t,u),min(v,w)),min(min(x,y),z)) 121 | #define ISmin8(s,t,u,v,w,x,y,z) min(min(min(s,t),min(u,v)),min(min(w,x),min(y,z))) 122 | #define ISmin9(r,s,t,u,v,w,x,y,z) min(min(min(min(r,s),t),min(u,v)),min(min(w,x),min(y,z))) 123 | #define ISmin10(q,r,s,t,u,v,w,x,y,z) min(min(min(min(q,r),min(s,t)),min(u,v)),min(min(w,x),min(y,z))) 124 | #define ISmin11(p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(p,q),min(r,s)),min(min(t,u),v)),min(min(w,x),min(y,z))) 125 | #define ISmin12(o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(o,p),min(q,r)),min(min(s,t),min(u,v))),min(min(w,x),min(y,z))) 126 | #define ISmin13(n,o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(n,o),min(p,q)),min(min(r,s),min(t,u))),min(min(min(v,w),x),min(y,z))) 127 | #define ISmin14(m,n,o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(m,n),min(o,p)),min(min(q,r),min(s,t))),min(min(min(u,v),min(w,x)),min(y,z))) 128 | #define ISmin15(l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(l,m),min(n,o)),min(min(p,q),min(r,s))),min(min(min(t,u),min(v,w)),min(min(x,y),z))) 129 | #define ISmin16(k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(k,l),min(m,n)),min(min(o,p),min(q,r))),min(min(min(s,t),min(u,v)),min(min(w,x),min(y,z)))) 130 | 131 | #include "ReShade.fxh" 132 | 133 | /*****************************************************************************************************************************************/ 134 | /********************************************************* SYNTAX SETUP END **************************************************************/ 135 | /*****************************************************************************************************************************************/ 136 | 137 | /***************************************************************************************************************************************/ 138 | /******************************************************* SOFTENER SHADER CODE START ****************************************************/ 139 | /***************************************************************************************************************************************/ 140 | 141 | float3 ImageSoftenerPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 142 | { 143 | float4 offset = float2(ImageSoftenOffset * float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT)).xyxy; 144 | 145 | // pattern: 146 | // e f g 147 | // h a b 148 | // i c d 149 | 150 | float3 a = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy).rgb; 151 | float3 b = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy + float2(1, 0).xyxy * offset).rgb; 152 | float3 c = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy + float2(0, 1).xyxy * offset).rgb; 153 | float3 d = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy + float2(1, 1).xyxy * offset).rgb; 154 | float3 e = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy + float2(-1, -1).xyxy * offset).rgb; 155 | float3 f = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy + float2(0, -1).xyxy * offset).rgb; 156 | float3 g = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy + float2(1, -1).xyxy * offset).rgb; 157 | float3 h = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy + float2(-1, 0).xyxy * offset).rgb; 158 | float3 i = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy + float2(-1, 1).xyxy * offset).rgb; 159 | 160 | float3 x1 = (e + f + g) / 3.0; 161 | float3 x2 = (h + b) / 2.0; 162 | float3 x3 = (i + c + d) / 3.0; 163 | float3 y1 = (e + h + i) / 3.0; 164 | float3 y2 = (f + c) / 2.0; 165 | float3 y3 = (g + b + d) / 3.0; 166 | float3 xy1 = (e + d) / 2.0; 167 | float3 xy2 = (i + g) / 2.0; 168 | float3 diamond = (h + f + c + b) / 4.0; 169 | float3 square = (e + g + i + d) / 4.0; 170 | float3 cap = (h + e + f + g + b) / 5.0; 171 | float3 bucket = (h + i + c + d + b) / 5.0; 172 | float3 letter = (f + e + h + i + c) / 5.0; 173 | float3 magnet = (f + g + b + d + c) / 5.0; 174 | float3 box = (e + f + g + b + d + c + i + h) / 8.0; 175 | 176 | float3 highterm = ISmax15(x1, x2, x3, y1, y2, y3, xy1, xy2, diamond, square, cap, bucket, letter, magnet, box); 177 | float3 lowterm = ISmin15(x1, x2, x3, y1, y2, y3, xy1, xy2, diamond, square, cap, bucket, letter, magnet, box); 178 | 179 | float3 localavg = ((x1 + x2 + x3 + y1 + y2 + y3 + xy1 + xy2 + diamond + square + cap + bucket + letter + magnet + box) - (highterm + lowterm)) / 13.0; 180 | 181 | return lerp(a, localavg, ImageSoftenStrength); 182 | } 183 | 184 | /***************************************************************************************************************************************/ 185 | /******************************************************** SOFTENER SHADER CODE END *****************************************************/ 186 | /***************************************************************************************************************************************/ 187 | 188 | technique ImageSoftening < 189 | ui_tooltip = "============================================================\n" 190 | "This shader measures an error-controlled average of many\n" 191 | "geometric patterns around each pixel to generate a subtle\n" 192 | "blur effect. Warning: may eat stars.\n" 193 | "============================================================"; 194 | > 195 | { 196 | pass ImageSoftening 197 | { 198 | VertexShader = PostProcessVS; 199 | PixelShader = ImageSoftenerPS; 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /Shaders/QXAA.fx: -------------------------------------------------------------------------------- 1 | /* QXAA for ReShade 3.1.1+ 2 | * 3 | * (high-Quality approXimate Anti-Aliasing) 4 | * 5 | * Quality-optimized stand-alone FXAA shader 6 | * 7 | * based on the implementation in HQAA 8 | * 9 | * by lordbean 10 | * 11 | */ 12 | 13 | // This shader includes code adapted from: 14 | 15 | /**============================================================================ 16 | 17 | 18 | NVIDIA FXAA 3.11 by TIMOTHY LOTTES 19 | 20 | 21 | ------------------------------------------------------------------------------ 22 | COPYRIGHT (C) 2010, 2011 NVIDIA CORPORATION. ALL RIGHTS RESERVED. 23 | ------------------------------------------------------------------------------*/ 24 | 25 | /* AMD CONTRAST ADAPTIVE SHARPENING 26 | // ======= 27 | // Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved. 28 | // ------- 29 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 30 | // files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 31 | // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 32 | // Software is furnished to do so, subject to the following conditions: 33 | // ------- 34 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 35 | // Software. 36 | // --------*/ 37 | 38 | // All original code not attributed to the above authors is copyright (c) Derek Brush aka "lordbean" (derekbrush@gmail.com) 39 | 40 | /** Permission is hereby granted, free of charge, to any person obtaining a copy 41 | * this software and associated documentation files (the "Software"), to deal in 42 | * the Software without restriction, including without limitation the rights to 43 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 44 | * of the Software, and to permit persons to whom the Software is furnished to 45 | * do so, subject to the following conditions: 46 | * 47 | * The above copyright notice and this permission notice shall be included in 48 | * all copies or substantial portions of the Software. As clarification, there 49 | * is no requirement that the copyright notice and permission be included in 50 | * binary distributions of the Software. 51 | **/ 52 | 53 | /*------------------------------------------------------------------------------ 54 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 55 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 56 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 57 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 58 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 59 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 60 | * SOFTWARE. 61 | *-------------------------------------------------------------------------------*/ 62 | 63 | 64 | /*****************************************************************************************************************************************/ 65 | /*********************************************************** UI SETUP START **************************************************************/ 66 | /*****************************************************************************************************************************************/ 67 | 68 | #include "ReShadeUI.fxh" 69 | 70 | /////////////////////////////////////////////////////// CONFIGURABLE TOGGLES ////////////////////////////////////////////////////////////// 71 | 72 | #ifndef QXAA_OUTPUT_MODE 73 | #define QXAA_OUTPUT_MODE 0 74 | #endif //QXAA_TARGET_COLOR_SPACE 75 | 76 | #ifndef QXAA_MULTISAMPLING 77 | #define QXAA_MULTISAMPLING 2 78 | #endif 79 | 80 | /////////////////////////////////////////////////////// GLOBAL SETUP OPTIONS ////////////////////////////////////////////////////////////// 81 | 82 | uniform int QXAAintroduction < 83 | ui_spacing = 3; 84 | ui_type = "radio"; 85 | ui_label = "Version: 1.8"; 86 | ui_text = "-------------------------------------------------------------------------\n" 87 | " high-Quality approXimate Anti-Aliasing, a shader by lordbean\n" 88 | " https://github.com/lordbean-git/reshade-shaders/\n" 89 | "-------------------------------------------------------------------------\n\n" 90 | "Currently Compiled Configuration:\n\n" 91 | #if QXAA_OUTPUT_MODE == 1 92 | "Output Mode: HDR nits *\n" 93 | #elif QXAA_OUTPUT_MODE == 2 94 | "Output Mode: PQ accurate *\n" 95 | #elif QXAA_OUTPUT_MODE == 3 96 | "Output Mode: PQ approx *\n" 97 | #else 98 | "Output Mode: Gamma 2.2\n" 99 | #endif //QXAA_TARGET_COLOR_SPACE 100 | #if QXAA_MULTISAMPLING < 2 101 | "Multisampling: off *\n" 102 | #elif QXAA_MULTISAMPLING > 3 103 | "Multisampling: 4x *\n" 104 | #elif QXAA_MULTISAMPLING > 2 105 | "Multisampling: 3x *\n" 106 | #elif QXAA_MULTISAMPLING > 1 107 | "Multisampling: 2x\n" 108 | #endif //QXAA_MULTISAMPLING 109 | 110 | "\nRemarks:\n" 111 | 112 | "\nQXAA sharpening/tonemap processing has no performance penalty when\n" 113 | "disabled. It shares the same pass used to run Hysteresis correction and\n" 114 | "is compiled out of the shader when ReShade is in Performance Mode.\n" 115 | 116 | "\nTry using more than two multisamples if you have GPU headroom! Quality\n" 117 | "typically increases slightly with each extra pass. Valid up to 4.\n" 118 | "\nValid Output Modes (QXAA_OUTPUT_MODE):\n" 119 | "0: Gamma 2.2 (default)\n" 120 | "1: HDR, direct nits scale\n" 121 | "2: HDR10, accurate encoding\n" 122 | "3: HDR10, fast encoding\n" 123 | "\n-------------------------------------------------------------------------" 124 | "\nSee the 'Preprocessor definitions' section for color & feature toggles.\n" 125 | "-------------------------------------------------------------------------"; 126 | ui_tooltip = "Because it worked so well when it was an accident"; 127 | ui_category = "About"; 128 | ui_category_closed = true; 129 | >; 130 | 131 | #if QXAA_OUTPUT_MODE == 1 132 | uniform float QxaaHdrNits < 133 | ui_spacing = 3; 134 | ui_type = "slider"; 135 | ui_min = 500.0; ui_max = 10000.0; ui_step = 100.0; 136 | ui_label = "HDR Nits"; 137 | ui_tooltip = "If the scene brightness changes after QXAA runs, try\n" 138 | "adjusting this value up or down until it looks right."; 139 | > = 1000.0; 140 | #endif //QXAA_TARGET_COLOR_SPACE 141 | 142 | uniform int QxaaAboutEOF < 143 | ui_type = "radio"; 144 | ui_label = " "; 145 | ui_text = "\n--------------------------------------------------------------------------------"; 146 | >; 147 | 148 | uniform float QxaaThreshold < 149 | ui_spacing = 3; 150 | ui_type = "slider"; 151 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 152 | ui_label = "Edge Detection Threshold"; 153 | ui_tooltip = "Local contrast (luma difference) required to be considered an edge.\nQXAA does not do dynamic thresholding, but it\nhandles extreme settings very well."; 154 | ui_category = "Anti-Aliasing"; 155 | ui_category_closed = true; 156 | > = 0.015; 157 | 158 | uniform uint QxaaScanIterations < 159 | ui_type = "slider"; 160 | ui_min = 1; ui_max = 200; ui_step = 1; 161 | ui_label = "Gradient Scan Iterations"; 162 | ui_tooltip = "Edge gradient search iterations.\nNote that this is per-pass, not total."; 163 | ui_category = "Anti-Aliasing"; 164 | ui_category_closed = true; 165 | > = 30; 166 | 167 | uniform float QxaaTexelSize < 168 | ui_type = "slider"; 169 | ui_min = 0.1; ui_max = 2.0; ui_step = 0.001; 170 | ui_label = "Edge Gradient Texel Size"; 171 | ui_tooltip = "Determines how far along an edge QXAA will move\nfrom one scan iteration to the next.\n\nLower = slower, more accurate\nHigher = faster, more artifacts"; 172 | ui_category = "Anti-Aliasing"; 173 | ui_category_closed = true; 174 | > = 0.333333; 175 | 176 | uniform float QxaaStrength < 177 | ui_type = "slider"; 178 | ui_min = 0; ui_max = 100; ui_step = 1; 179 | ui_label = "Effect Strength"; 180 | ui_tooltip = "Although more costly, you can get better results\nby using multisampling and a lower strength."; 181 | ui_category = "Anti-Aliasing"; 182 | ui_category_closed = true; 183 | > = 100; 184 | 185 | uniform float QxaaHysteresisStrength < 186 | ui_spacing = 3; 187 | ui_label = "Hysteresis Strength"; 188 | ui_tooltip = "Performs detail reconstruction to minimize the\n" 189 | "visual impact of artifacts that may be caused\n" 190 | "by QXAA."; 191 | ui_type = "slider"; 192 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 193 | ui_category = "Anti-Aliasing"; 194 | ui_category_closed = true; 195 | > = 0.125; 196 | 197 | uniform float QxaaHysteresisFudgeFactor < 198 | ui_label = "Hysteresis Fudge Factor"; 199 | ui_tooltip = "Pixels that have changed less than this\n" 200 | "amount will be skipped."; 201 | ui_type = "slider"; 202 | ui_min = 0.0; ui_max = 0.2; ui_step = 0.001; 203 | ui_category = "Anti-Aliasing"; 204 | ui_category_closed = true; 205 | > = 0.04; 206 | 207 | uniform float QxaaNoiseControlStrength < 208 | ui_type = "slider"; 209 | ui_min = 0; ui_max = 100; ui_step = 1; 210 | ui_label = "Noise Control Strength\n\n"; 211 | ui_tooltip = "Determines how strongly QXAA will clamp its output\n" 212 | "when the resulting blend will have a high luma delta.\n" 213 | "Useful when using more than two anti-aliasing passes."; 214 | ui_category = "Anti-Aliasing"; 215 | ui_category_closed = true; 216 | > = 0; 217 | 218 | uniform bool QxaaEnableSharpening < 219 | ui_spacing = 3; 220 | ui_label = "Enable Sharpening"; 221 | ui_tooltip = "Performs fast CAS sharpening when enabled."; 222 | ui_category = "Sharpening"; 223 | ui_category_closed = true; 224 | > = false; 225 | 226 | uniform float QxaaSharpenerStrength < 227 | ui_spacing = 3; 228 | ui_type = "slider"; 229 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 230 | ui_label = "Strength"; 231 | ui_tooltip = "Amount of sharpening to apply. 1.0 is default."; 232 | ui_category = "Sharpening"; 233 | ui_category_closed = true; 234 | > = 0.625; 235 | 236 | uniform float QxaaSharpenerAdaptation < 237 | ui_type = "slider"; 238 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 239 | ui_label = "Contrast Adaptation\n\n"; 240 | ui_tooltip = "Adjusts the amount of high-contrast sharpening\n" 241 | "applied. 0.0 is default, above 0.5 is not recommended."; 242 | ui_category = "Sharpening"; 243 | ui_category_closed = true; 244 | > = 0.125; 245 | 246 | uniform bool QxaaEnableTonemap < 247 | ui_label = "Enable Tonemap Processing"; 248 | ui_spacing = 3; 249 | ui_tooltip = "Enables processing of this category. Individual\n" 250 | "effects will still be compiled out when they\n" 251 | "do not result in a change to the output."; 252 | ui_category = "Tonemap"; 253 | ui_category_closed = true; 254 | > = false; 255 | 256 | uniform uint QxaaTonemapping < 257 | ui_spacing = 3; 258 | ui_type = "combo"; 259 | ui_label = "Tonemapping Function"; 260 | ui_items = "None\0Reinhard Extended\0Reinhard Luminance\0Reinhard-Jodie\0Uncharted 2\0ACES approx\0Logarithmic Fake HDR\0Dynamic Range Compression\0"; 261 | ui_category = "Tonemap"; 262 | ui_category_closed = true; 263 | > = 0; 264 | 265 | uniform float QxaaTonemappingParameter < 266 | ui_type = "slider"; 267 | ui_label = "Tonemapping Function Parameter"; 268 | ui_tooltip = "Input parameter for tonemapping functions that use one.\n" 269 | "Logarithmic functions will generate artifacts if the\n" 270 | "value exceeds euler's number (~2.718282)."; 271 | ui_min = 0.0; ui_max = 2.718; ui_step = 0.001; 272 | ui_category = "Tonemap"; 273 | ui_category_closed = true; 274 | > = 1.0; 275 | 276 | uniform float QxaaGainStrength < 277 | ui_type = "slider"; 278 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 279 | ui_spacing = 3; 280 | ui_label = "Brightness Gain"; 281 | ui_category = "Tonemap"; 282 | ui_category_closed = true; 283 | > = 0.0; 284 | 285 | uniform bool QxaaGainLowLumaCorrection < 286 | ui_label = "Contrast Washout Correction"; 287 | ui_tooltip = "Calculates new expected black point after gain\n" 288 | "and adjusts saturation levels to reduce perceived\n" 289 | "contrast washout (or 'airy' look)."; 290 | ui_category = "Tonemap"; 291 | ui_category_closed = true; 292 | > = false; 293 | 294 | uniform float QxaaBlueLightFilter < 295 | ui_spacing = 3; 296 | ui_type = "slider"; 297 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 298 | ui_label = "Blue Light Filter"; 299 | ui_tooltip = "Reduces strength of blue light for eye comfort.\n"; 300 | ui_category = "Tonemap"; 301 | ui_category_closed = true; 302 | > = 0.0; 303 | 304 | uniform float QxaaSaturationStrength < 305 | ui_spacing = 3; 306 | ui_type = "slider"; 307 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 308 | ui_label = "Saturation\n\n"; 309 | ui_tooltip = "Increases or decreases saturation of the scene.\n" 310 | "Higher makes colors appear more vibrant, lower\n" 311 | "washes them out. 0.5 is neutral."; 312 | ui_category = "Tonemap"; 313 | ui_category_closed = true; 314 | > = 0.5; 315 | 316 | uniform int QxaaOptionsEOF < 317 | ui_type = "radio"; 318 | ui_label = " "; 319 | ui_text = "\n--------------------------------------------------------------------------------"; 320 | >; 321 | 322 | /*****************************************************************************************************************************************/ 323 | /*********************************************************** UI SETUP END ****************************************************************/ 324 | /*****************************************************************************************************************************************/ 325 | 326 | /*****************************************************************************************************************************************/ 327 | /******************************************************** SYNTAX SETUP START *************************************************************/ 328 | /*****************************************************************************************************************************************/ 329 | 330 | #define __QXAA_MIN_STEP rcp(pow(2., BUFFER_COLOR_BIT_DEPTH)) 331 | #define __QXAA_LUMA_REF float3(0.2126, 0.7152, 0.0722) 332 | #define __QXAA_GREEN_LUMA float3(1./5., 7./10., 1./10.) 333 | #define __QXAA_RED_LUMA float3(5./8., 1./4., 1./8.) 334 | #define __QXAA_BLUE_LUMA float3(1./8., 3./8., 1./2.) 335 | #define __QXAA_CONST_E 2.7182818284590452353602874713527 336 | #define __QXAA_CONST_HALFROOT2 (sqrt(2.)/2.) 337 | 338 | #define QXAA_Tex2D(tex, coord) tex2Dlod(tex, (coord).xyxy) 339 | #define QXAA_Tex2DOffset(tex, coord, offset) tex2Dlodoffset(tex, (coord).xyxy, offset) 340 | #define QXAA_DecodeTex2D(tex, coord) ConditionalDecode(tex2Dlod(tex, (coord).xyxy)) 341 | #define QXAA_DecodeTex2DOffset(tex, coord, offset) ConditionalDecode(tex2Dlodoffset(tex, (coord).xyxy, offset)) 342 | 343 | #define QXAAmax3(x,y,z) max(max(x,y),z) 344 | #define QXAAmax4(w,x,y,z) max(max(w,x),max(y,z)) 345 | #define QXAAmax5(v,w,x,y,z) max(max(max(v,w),x),max(y,z)) 346 | #define QXAAmax6(u,v,w,x,y,z) max(max(max(u,v),max(w,x)),max(y,z)) 347 | #define QXAAmax7(t,u,v,w,x,y,z) max(max(max(t,u),max(v,w)),max(max(x,y),z)) 348 | #define QXAAmax8(s,t,u,v,w,x,y,z) max(max(max(s,t),max(u,v)),max(max(w,x),max(y,z))) 349 | #define QXAAmax9(r,s,t,u,v,w,x,y,z) max(max(max(max(r,s),t),max(u,v)),max(max(w,x),max(y,z))) 350 | #define QXAAmax10(q,r,s,t,u,v,w,x,y,z) max(max(max(max(q,r),max(s,t)),max(u,v)),max(max(w,x),max(y,z))) 351 | #define QXAAmax11(p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(p,q),max(r,s)),max(max(t,u),v)),max(max(w,x),max(y,z))) 352 | #define QXAAmax12(o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(o,p),max(q,r)),max(max(s,t),max(u,v))),max(max(w,x),max(y,z))) 353 | #define QXAAmax13(n,o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(n,o),max(p,q)),max(max(r,s),max(t,u))),max(max(max(v,w),x),max(y,z))) 354 | #define QXAAmax14(m,n,o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(m,n),max(o,p)),max(max(q,r),max(s,t))),max(max(max(u,v),max(w,x)),max(y,z))) 355 | 356 | #define QXAAmin3(x,y,z) min(min(x,y),z) 357 | #define QXAAmin4(w,x,y,z) min(min(w,x),min(y,z)) 358 | #define QXAAmin5(v,w,x,y,z) min(min(min(v,w),x),min(y,z)) 359 | #define QXAAmin6(u,v,w,x,y,z) min(min(min(u,v),min(w,x)),min(y,z)) 360 | #define QXAAmin7(t,u,v,w,x,y,z) min(min(min(t,u),min(v,w)),min(min(x,y),z)) 361 | #define QXAAmin8(s,t,u,v,w,x,y,z) min(min(min(s,t),min(u,v)),min(min(w,x),min(y,z))) 362 | #define QXAAmin9(r,s,t,u,v,w,x,y,z) min(min(min(min(r,s),t),min(u,v)),min(min(w,x),min(y,z))) 363 | #define QXAAmin10(q,r,s,t,u,v,w,x,y,z) min(min(min(min(q,r),min(s,t)),min(u,v)),min(min(w,x),min(y,z))) 364 | #define QXAAmin11(p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(p,q),min(r,s)),min(min(t,u),v)),min(min(w,x),min(y,z))) 365 | #define QXAAmin12(o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(o,p),min(q,r)),min(min(s,t),min(u,v))),min(min(w,x),min(y,z))) 366 | #define QXAAmin13(n,o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(n,o),min(p,q)),min(min(r,s),min(t,u))),min(min(min(v,w),x),min(y,z))) 367 | #define QXAAmin14(m,n,o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(m,n),min(o,p)),min(min(q,r),min(s,t))),min(min(min(u,v),min(w,x)),min(y,z))) 368 | 369 | #define QXAAdotmax(x) max(max((x).r, (x).g), (x).b) 370 | #define QXAAdotmin(x) min(min((x).r, (x).g), (x).b) 371 | 372 | /*****************************************************************************************************************************************/ 373 | /********************************************************* SYNTAX SETUP END **************************************************************/ 374 | /*****************************************************************************************************************************************/ 375 | 376 | /*****************************************************************************************************************************************/ 377 | /******************************************************** SUPPORT CODE START *************************************************************/ 378 | /*****************************************************************************************************************************************/ 379 | 380 | /////////////////////////////////////////////////////// TRANSFER FUNCTIONS //////////////////////////////////////////////////////////////// 381 | 382 | #if QXAA_OUTPUT_MODE == 2 383 | float encodePQ(float x) 384 | { 385 | /* float nits = 10000.0; 386 | float m2rcp = 0.012683; // 1 / (2523/32) 387 | float m1rcp = 6.277395; // 1 / (1305/8192) 388 | float c1 = 0.8359375; // 107 / 128 389 | float c2 = 18.8515625; // 2413 / 128 390 | float c3 = 18.6875; // 2392 / 128 391 | */ 392 | float xpm2rcp = pow(saturate(x), 0.012683); 393 | float numerator = max(xpm2rcp - 0.8359375, 0.0); 394 | float denominator = 18.8515625 - (18.6875 * xpm2rcp); 395 | 396 | float output = pow(abs(numerator / denominator), 6.277395); 397 | #if BUFFER_COLOR_BIT_DEPTH == 10 398 | output *= 500.0; 399 | #else 400 | output *= 10000.0; 401 | #endif 402 | return output; 403 | } 404 | float2 encodePQ(float2 x) 405 | { 406 | float2 xpm2rcp = pow(saturate(x), 0.012683); 407 | float2 numerator = max(xpm2rcp - 0.8359375, 0.0); 408 | float2 denominator = 18.8515625 - (18.6875 * xpm2rcp); 409 | 410 | float2 output = pow(abs(numerator / denominator), 6.277395); 411 | #if BUFFER_COLOR_BIT_DEPTH == 10 412 | output *= 500.0; 413 | #else 414 | output *= 10000.0; 415 | #endif 416 | return output; 417 | } 418 | float3 encodePQ(float3 x) 419 | { 420 | float3 xpm2rcp = pow(saturate(x), 0.012683); 421 | float3 numerator = max(xpm2rcp - 0.8359375, 0.0); 422 | float3 denominator = 18.8515625 - (18.6875 * xpm2rcp); 423 | 424 | float3 output = pow(abs(numerator / denominator), 6.277395); 425 | #if BUFFER_COLOR_BIT_DEPTH == 10 426 | output *= 500.0; 427 | #else 428 | output *= 10000.0; 429 | #endif 430 | return output; 431 | } 432 | float4 encodePQ(float4 x) 433 | { 434 | float4 xpm2rcp = pow(saturate(x), 0.012683); 435 | float4 numerator = max(xpm2rcp - 0.8359375, 0.0); 436 | float4 denominator = 18.8515625 - (18.6875 * xpm2rcp); 437 | 438 | float4 output = pow(abs(numerator / denominator), 6.277395); 439 | #if BUFFER_COLOR_BIT_DEPTH == 10 440 | output *= 500.0; 441 | #else 442 | output *= 10000.0; 443 | #endif 444 | return output; 445 | } 446 | 447 | float decodePQ(float x) 448 | { 449 | /* float nits = 10000.0; 450 | float m2 = 78.84375 // 2523 / 32 451 | float m1 = 0.159302; // 1305 / 8192 452 | float c1 = 0.8359375; // 107 / 128 453 | float c2 = 18.8515625; // 2413 / 128 454 | float c3 = 18.6875; // 2392 / 128 455 | */ 456 | #if BUFFER_COLOR_BIT_DEPTH == 10 457 | float xpm1 = pow(saturate(x / 500.0), 0.159302); 458 | #else 459 | float xpm1 = pow(saturate(x / 10000.0), 0.159302); 460 | #endif 461 | float numerator = 0.8359375 + (18.8515625 * xpm1); 462 | float denominator = 1.0 + (18.6875 * xpm1); 463 | 464 | return saturate(pow(abs(numerator / denominator), 78.84375)); 465 | } 466 | float2 decodePQ(float2 x) 467 | { 468 | #if BUFFER_COLOR_BIT_DEPTH == 10 469 | float2 xpm1 = pow(saturate(x / 500.0), 0.159302); 470 | #else 471 | float2 xpm1 = pow(saturate(x / 10000.0), 0.159302); 472 | #endif 473 | float2 numerator = 0.8359375 + (18.8515625 * xpm1); 474 | float2 denominator = 1.0 + (18.6875 * xpm1); 475 | 476 | return saturate(pow(abs(numerator / denominator), 78.84375)); 477 | } 478 | float3 decodePQ(float3 x) 479 | { 480 | #if BUFFER_COLOR_BIT_DEPTH == 10 481 | float3 xpm1 = pow(saturate(x / 500.0), 0.159302); 482 | #else 483 | float3 xpm1 = pow(saturate(x / 10000.0), 0.159302); 484 | #endif 485 | float3 numerator = 0.8359375 + (18.8515625 * xpm1); 486 | float3 denominator = 1.0 + (18.6875 * xpm1); 487 | 488 | return saturate(pow(abs(numerator / denominator), 78.84375)); 489 | } 490 | float4 decodePQ(float4 x) 491 | { 492 | #if BUFFER_COLOR_BIT_DEPTH == 10 493 | float4 xpm1 = pow(saturate(x / 500.0), 0.159302); 494 | #else 495 | float4 xpm1 = pow(saturate(x / 10000.0), 0.159302); 496 | #endif 497 | float4 numerator = 0.8359375 + (18.8515625 * xpm1); 498 | float4 denominator = 1.0 + (18.6875 * xpm1); 499 | 500 | return saturate(pow(abs(numerator / denominator), 78.84375)); 501 | } 502 | #endif //QXAA_OUTPUT_MODE == 2 503 | 504 | #if QXAA_OUTPUT_MODE == 3 505 | float fastencodePQ(float x) 506 | { 507 | #if BUFFER_COLOR_BIT_DEPTH == 10 508 | float y = saturate(x) * 4.728708; 509 | float z = 500.0; 510 | #else 511 | float y = saturate(x) * 10.0; 512 | float z = 10000.0; 513 | #endif 514 | y *= y; 515 | y *= y; 516 | return clamp(y, 0.0, z); 517 | } 518 | float2 fastencodePQ(float2 x) 519 | { 520 | #if BUFFER_COLOR_BIT_DEPTH == 10 521 | float2 y = saturate(x) * 4.728708; 522 | float z = 500.0; 523 | #else 524 | float2 y = saturate(x) * 10.0; 525 | float z = 10000.0; 526 | #endif 527 | y *= y; 528 | y *= y; 529 | return clamp(y, 0.0, z); 530 | } 531 | float3 fastencodePQ(float3 x) 532 | { 533 | #if BUFFER_COLOR_BIT_DEPTH == 10 534 | float3 y = saturate(x) * 4.728708; 535 | float z = 500.0; 536 | #else 537 | float3 y = saturate(x) * 10.0; 538 | float z = 10000.0; 539 | #endif 540 | y *= y; 541 | y *= y; 542 | return clamp(y, 0.0, z); 543 | } 544 | float4 fastencodePQ(float4 x) 545 | { 546 | #if BUFFER_COLOR_BIT_DEPTH == 10 547 | float4 y = saturate(x) * 4.728708; 548 | float z = 500.0; 549 | #else 550 | float4 y = saturate(x) * 10.0; 551 | float z = 10000.0; 552 | #endif 553 | y *= y; 554 | y *= y; 555 | return clamp(y, 0.0, z); 556 | } 557 | 558 | float fastdecodePQ(float x) 559 | { 560 | #if BUFFER_COLOR_BIT_DEPTH == 10 561 | return saturate((sqrt(sqrt(clamp(x, __QXAA_MIN_STEP, 500.0))) / 4.728708)); 562 | #else 563 | return saturate((sqrt(sqrt(clamp(x, __QXAA_MIN_STEP, 10000.0))) / 10.0)); 564 | #endif 565 | } 566 | float2 fastdecodePQ(float2 x) 567 | { 568 | #if BUFFER_COLOR_BIT_DEPTH == 10 569 | return saturate((sqrt(sqrt(clamp(x, __QXAA_MIN_STEP, 500.0))) / 4.728708)); 570 | #else 571 | return saturate((sqrt(sqrt(clamp(x, __QXAA_MIN_STEP, 10000.0))) / 10.0)); 572 | #endif 573 | } 574 | float3 fastdecodePQ(float3 x) 575 | { 576 | #if BUFFER_COLOR_BIT_DEPTH == 10 577 | return saturate((sqrt(sqrt(clamp(x, __QXAA_MIN_STEP, 500.0))) / 4.728708)); 578 | #else 579 | return saturate((sqrt(sqrt(clamp(x, __QXAA_MIN_STEP, 10000.0))) / 10.0)); 580 | #endif 581 | } 582 | float4 fastdecodePQ(float4 x) 583 | { 584 | #if BUFFER_COLOR_BIT_DEPTH == 10 585 | return saturate((sqrt(sqrt(clamp(x, __QXAA_MIN_STEP, 500.0))) / 4.728708)); 586 | #else 587 | return saturate((sqrt(sqrt(clamp(x, __QXAA_MIN_STEP, 10000.0))) / 10.0)); 588 | #endif 589 | } 590 | #endif //QXAA_OUTPUT_MODE == 3 591 | 592 | #if QXAA_OUTPUT_MODE == 1 593 | float encodeHDR(float x) 594 | { 595 | return saturate(x) * QxaaHdrNits; 596 | } 597 | float2 encodeHDR(float2 x) 598 | { 599 | return saturate(x) * QxaaHdrNits; 600 | } 601 | float3 encodeHDR(float3 x) 602 | { 603 | return saturate(x) * QxaaHdrNits; 604 | } 605 | float4 encodeHDR(float4 x) 606 | { 607 | return saturate(x) * QxaaHdrNits; 608 | } 609 | 610 | float decodeHDR(float x) 611 | { 612 | return saturate(x / QxaaHdrNits); 613 | } 614 | float2 decodeHDR(float2 x) 615 | { 616 | return saturate(x / QxaaHdrNits); 617 | } 618 | float3 decodeHDR(float3 x) 619 | { 620 | return saturate(x / QxaaHdrNits); 621 | } 622 | float4 decodeHDR(float4 x) 623 | { 624 | return saturate(x / QxaaHdrNits); 625 | } 626 | #endif //QXAA_OUTPUT_MODE == 1 627 | 628 | float ConditionalEncode(float x) 629 | { 630 | #if QXAA_OUTPUT_MODE == 1 631 | return encodeHDR(x); 632 | #elif QXAA_OUTPUT_MODE == 2 633 | return encodePQ(x); 634 | #elif QXAA_OUTPUT_MODE == 3 635 | return fastencodePQ(x); 636 | #else 637 | return x; 638 | #endif 639 | } 640 | float2 ConditionalEncode(float2 x) 641 | { 642 | #if QXAA_OUTPUT_MODE == 1 643 | return encodeHDR(x); 644 | #elif QXAA_OUTPUT_MODE == 2 645 | return encodePQ(x); 646 | #elif QXAA_OUTPUT_MODE == 3 647 | return fastencodePQ(x); 648 | #else 649 | return x; 650 | #endif 651 | } 652 | float3 ConditionalEncode(float3 x) 653 | { 654 | #if QXAA_OUTPUT_MODE == 1 655 | return encodeHDR(x); 656 | #elif QXAA_OUTPUT_MODE == 2 657 | return encodePQ(x); 658 | #elif QXAA_OUTPUT_MODE == 3 659 | return fastencodePQ(x); 660 | #else 661 | return x; 662 | #endif 663 | } 664 | float4 ConditionalEncode(float4 x) 665 | { 666 | #if QXAA_OUTPUT_MODE == 1 667 | return encodeHDR(x); 668 | #elif QXAA_OUTPUT_MODE == 2 669 | return encodePQ(x); 670 | #elif QXAA_OUTPUT_MODE == 3 671 | return fastencodePQ(x); 672 | #else 673 | return x; 674 | #endif 675 | } 676 | 677 | float ConditionalDecode(float x) 678 | { 679 | #if QXAA_OUTPUT_MODE == 1 680 | return decodeHDR(x); 681 | #elif QXAA_OUTPUT_MODE == 2 682 | return decodePQ(x); 683 | #elif QXAA_OUTPUT_MODE == 3 684 | return fastdecodePQ(x); 685 | #else 686 | return x; 687 | #endif 688 | } 689 | float2 ConditionalDecode(float2 x) 690 | { 691 | #if QXAA_OUTPUT_MODE == 1 692 | return decodeHDR(x); 693 | #elif QXAA_OUTPUT_MODE == 2 694 | return decodePQ(x); 695 | #elif QXAA_OUTPUT_MODE == 3 696 | return fastdecodePQ(x); 697 | #else 698 | return x; 699 | #endif 700 | } 701 | float3 ConditionalDecode(float3 x) 702 | { 703 | #if QXAA_OUTPUT_MODE == 1 704 | return decodeHDR(x); 705 | #elif QXAA_OUTPUT_MODE == 2 706 | return decodePQ(x); 707 | #elif QXAA_OUTPUT_MODE == 3 708 | return fastdecodePQ(x); 709 | #else 710 | return x; 711 | #endif 712 | } 713 | float4 ConditionalDecode(float4 x) 714 | { 715 | #if QXAA_OUTPUT_MODE == 1 716 | return decodeHDR(x); 717 | #elif QXAA_OUTPUT_MODE == 2 718 | return decodePQ(x); 719 | #elif QXAA_OUTPUT_MODE == 3 720 | return fastdecodePQ(x); 721 | #else 722 | return x; 723 | #endif 724 | } 725 | 726 | ////////////////////////////////////////////////////// HELPER FUNCTIONS //////////////////////////////////////////////////////////////// 727 | 728 | void QXAAMovc(bool2 cond, inout float2 variable, float2 value) 729 | { 730 | [flatten] if (cond.x) variable.x = value.x; 731 | [flatten] if (cond.y) variable.y = value.y; 732 | } 733 | void QXAAMovc(bool4 cond, inout float4 variable, float4 value) 734 | { 735 | QXAAMovc(cond.xy, variable.xy, value.xy); 736 | QXAAMovc(cond.zw, variable.zw, value.zw); 737 | } 738 | 739 | float lxor(float x, float y) 740 | { 741 | bool valid = (x == 0.0) ? ((y == 0.0) ? false : true) : ((y == 0.0) ? true : false); 742 | if (valid) return x + y; 743 | else return 0.0; 744 | } 745 | float2 lxor(float2 x, float2 y) 746 | { 747 | return float2(lxor(x.x, y.x), lxor(x.y, y.y)); 748 | } 749 | float3 lxor(float3 x, float3 y) 750 | { 751 | return float3(lxor(x.x, y.x), lxor(x.yz, y.yz)); 752 | } 753 | float4 lxor(float4 x, float4 y) 754 | { 755 | return float4(lxor(x.xy, y.xy), lxor(x.zw, y.zw)); 756 | } 757 | 758 | /* 759 | Ey = 0.299R+0.587G+0.114B 760 | Ecr = 0.713(R - Ey) = 0.500R-0.419G-0.081B 761 | Ecb = 0.564(B - Ey) = -0.169R-0.331G+0.500B 762 | 763 | where Ey, R, G and B are in the range [0,1] and Ecr and Ecb are in the range [-0.5,0.5] 764 | */ 765 | float3 RGBtoYUV(float3 input) 766 | { 767 | float3 argb = saturate(input); // value must be between [0,1] 768 | float3 yuv; 769 | 770 | yuv.x = saturate((0.299 * argb.r) + (0.587 * argb.g) + (0.114 * argb.b)); 771 | yuv.y = clamp(0.713 * (argb.r - yuv.x), -0.5, 0.5); 772 | yuv.z = clamp(0.564 * (argb.b - yuv.x), -0.5, 0.5); 773 | 774 | return yuv; 775 | } 776 | float4 RGBtoYUV(float4 input) 777 | { 778 | return float4(RGBtoYUV(input.rgb), input.a); 779 | } 780 | 781 | /* 782 | /* reverse transfer accomplished by solving original equations for R and B and then 783 | /* using those channels to solve the luma equation for G 784 | */ 785 | float3 YUVtoRGB(float3 yuv) 786 | { 787 | yuv.x = saturate(yuv.x); 788 | yuv.yz = clamp(yuv.yz, -0.5, 0.5); 789 | 790 | float3 argb; 791 | 792 | argb.r = (1.402525 * yuv.y) + yuv.x; 793 | argb.b = (1.77305 * yuv.z) + yuv.x; 794 | argb.g = (1.703578 * yuv.x) - (0.50937 * argb.r) - (0.194208 * argb.b); 795 | 796 | return argb; 797 | } 798 | float4 YUVtoRGB(float4 yuv) 799 | { 800 | return float4(YUVtoRGB(yuv.xyz), yuv.a); 801 | } 802 | 803 | float dotsat(float3 x) 804 | { 805 | // trunc(xl) only = 1 when x = float3(1,1,1) 806 | // float3(1,1,1) produces 0/0 in the original calculation 807 | // this should change it to 0/1 to avoid the possible NaN out 808 | float xl = dot(x, __QXAA_LUMA_REF); 809 | return ((QXAAdotmax(x) - QXAAdotmin(x)) / (1.0 - (2.0 * xl - 1.0) + trunc(xl))); 810 | } 811 | float dotsat(float4 x) 812 | { 813 | return dotsat(x.rgb); 814 | } 815 | 816 | float3 AdjustSaturation(float3 input, float requestedadjustment) 817 | { 818 | // change to YCrCb (component) color space 819 | // access: x=Y, y=Cr, z=Cb 820 | float3 yuv = RGBtoYUV(input); 821 | 822 | // convert absolute saturation to adjustment delta 823 | float adjustment = 2.0 * (saturate(requestedadjustment) - 0.5); 824 | 825 | // for a positive adjustment, determine ceiling and clamp if necessary 826 | if (adjustment > 0.0) 827 | { 828 | float maxboost = 1.0 / (max(abs(yuv.y), abs(yuv.z)) / 0.5); 829 | if (adjustment > maxboost) adjustment = maxboost; 830 | } 831 | 832 | // compute delta Cr,Cb 833 | yuv.y = yuv.y > 0.0 ? (yuv.y + (adjustment * yuv.y)) : (yuv.y - (adjustment * abs(yuv.y))); 834 | yuv.z = yuv.z > 0.0 ? (yuv.z + (adjustment * yuv.z)) : (yuv.z - (adjustment * abs(yuv.z))); 835 | 836 | // change back to ARGB color space 837 | return YUVtoRGB(yuv); 838 | } 839 | 840 | float3 tonemap_adjustluma(float3 x, float xl_out) 841 | { 842 | float xl = dot(x, __QXAA_LUMA_REF); 843 | return x * (xl_out / xl); 844 | } 845 | float3 reinhard_jodie(float3 x) 846 | { 847 | float xl = dot(x, __QXAA_LUMA_REF); 848 | float3 xv = x / (1.0 + x); 849 | return lerp(x / (1.0 + xl), xv, xv); 850 | } 851 | float3 extended_reinhard(float3 x) 852 | { 853 | float whitepoint = QxaaTonemappingParameter; 854 | float3 numerator = x * (1.0 + (x / (whitepoint * whitepoint))); 855 | return numerator / (1.0 + x); 856 | } 857 | float3 extended_reinhard_luma(float3 x) 858 | { 859 | float whitepoint = QxaaTonemappingParameter; 860 | float xl = dot(x, __QXAA_LUMA_REF); 861 | float numerator = xl * (1.0 + (xl / (whitepoint * whitepoint))); 862 | float xl_shift = numerator / (1.0 + xl); 863 | return tonemap_adjustluma(x, xl_shift); 864 | } 865 | float3 uncharted2_partial(float3 x) 866 | { 867 | float A = 0.15; 868 | float B = 0.5; 869 | float C = 0.1; 870 | float D = 0.2; 871 | float E = 0.02; 872 | float F = 0.3; 873 | 874 | return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F; 875 | } 876 | float3 uncharted2_filmic(float3 x) 877 | { 878 | float exposure_bias = 2.0; 879 | float3 curr = uncharted2_partial(x * exposure_bias); 880 | float3 whitescale = rcp(uncharted2_partial(float(11.2).xxx)); 881 | return curr * whitescale; 882 | } 883 | float3 aces_approx(float3 x) 884 | { 885 | float3 xout = x * 0.6; 886 | float A = 2.51; 887 | float B = 0.03; 888 | float C = 2.43; 889 | float D = 0.59; 890 | float E = 0.14; 891 | 892 | return saturate((xout*(A*xout+B))/(xout*(C*xout+D)+E)); 893 | } 894 | float3 logarithmic_fake_hdr(float3 x) 895 | { 896 | return saturate(pow(abs(__QXAA_CONST_E + (QxaaTonemappingParameter * (0.5 - log2(1.0 + dot(x, __QXAA_LUMA_REF))))), log(clamp(x, __QXAA_MIN_STEP, 1.0)))); 897 | } 898 | float3 logarithmic_range_compression(float3 x) 899 | { 900 | float luma = dot(x, __QXAA_LUMA_REF); 901 | float offset = QxaaTonemappingParameter * (0.5 - luma); 902 | float3 result = pow(abs(__QXAA_CONST_E - offset), log(clamp(x, __QXAA_MIN_STEP, 1.0))); 903 | return saturate(result); 904 | } 905 | 906 | /***************************************************************************************************************************************/ 907 | /******************************************************** SUPPORT CODE END *************************************************************/ 908 | /***************************************************************************************************************************************/ 909 | 910 | /***************************************************************************************************************************************/ 911 | /*********************************************************** SHADER SETUP START ********************************************************/ 912 | /***************************************************************************************************************************************/ 913 | 914 | #include "ReShade.fxh" 915 | 916 | texture QXAAHysteresisInfoTex 917 | #if __RESHADE__ < 50000 918 | < pooled = false; > 919 | #endif 920 | { 921 | Width = BUFFER_WIDTH; 922 | Height = BUFFER_HEIGHT; 923 | Format = R32F; 924 | }; 925 | 926 | sampler OriginalLuma { Texture = QXAAHysteresisInfoTex; }; 927 | 928 | /*****************************************************************************************************************************************/ 929 | /*********************************************************** SHADER SETUP END ************************************************************/ 930 | /*****************************************************************************************************************************************/ 931 | 932 | /***************************************************************************************************************************************/ 933 | /********************************************************** QXAA SHADER CODE START *****************************************************/ 934 | /***************************************************************************************************************************************/ 935 | 936 | float QXAAInitPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 937 | { 938 | float3 pixel = QXAA_Tex2D(ReShade::BackBuffer, texcoord).rgb; 939 | return dot(ConditionalDecode(pixel), __QXAA_LUMA_REF); 940 | } 941 | 942 | float3 QXAAPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 943 | { 944 | float3 original = QXAA_Tex2D(ReShade::BackBuffer, texcoord).rgb; 945 | 946 | //determine detection method 947 | float edgethreshold = QxaaThreshold; 948 | float3 middle = ConditionalDecode(original); 949 | float maxchannel = QXAAmax3(middle.r, middle.g, middle.b); 950 | float3 ref; 951 | if (middle.g == maxchannel) ref = __QXAA_GREEN_LUMA; 952 | else if (middle.r == maxchannel) ref = __QXAA_RED_LUMA; 953 | else ref = __QXAA_BLUE_LUMA; 954 | float lumaM = dot(middle, ref); 955 | float2 lengthSign = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); 956 | 957 | //setup cartesian neighbor data 958 | float lumaS = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, texcoord + float2(0.0, lengthSign.y)).rgb, ref); 959 | float lumaE = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, texcoord + float2(lengthSign.x, 0.0)).rgb, ref); 960 | float lumaN = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, texcoord + float2(0.0, -lengthSign.y)).rgb, ref); 961 | float lumaW = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, texcoord + float2(-lengthSign.x, 0.0)).rgb, ref); 962 | float4 crossdelta = abs(lumaM - float4(lumaS, lumaE, lumaN, lumaW)); 963 | float2 weightsHV = float2(crossdelta.x + crossdelta.z, crossdelta.y + crossdelta.w); 964 | 965 | // pattern 966 | // * z * 967 | // w * y 968 | // * x * 969 | 970 | //setup diagonal neighbor data 971 | //diagonal reads are performed at the same distance from origin as cartesian reads 972 | //solve using pythagorean theorem yields 1/2 sqrt(2) to match horz/vert distance 973 | //this bakes in a weighting bias to horz/vert giving diag code priority only when 974 | //it's the only viable option 975 | float2 diagstep = lengthSign * __QXAA_CONST_HALFROOT2; 976 | float lumaNW = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, texcoord - diagstep).rgb, ref); 977 | float lumaSE = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, texcoord + diagstep).rgb, ref); 978 | float lumaNE = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, texcoord + float2(diagstep.x, -diagstep.y)).rgb, ref); 979 | float lumaSW = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, texcoord + float2(-diagstep.x, diagstep.y)).rgb, ref); 980 | float4 diagdelta = abs(lumaM - float4(lumaNW, lumaSE, lumaNE, lumaSW)); 981 | float2 weightsDI = float2(diagdelta.w + diagdelta.z, diagdelta.x + diagdelta.y); 982 | 983 | // pattern 984 | // x * z 985 | // * * * 986 | // w * y 987 | 988 | //detect edge pattern 989 | bool diagSpan = max(weightsDI.x, weightsDI.y) * float(bool(lxor(weightsDI.x, weightsDI.y))) > max(weightsHV.x, weightsHV.y); 990 | bool inverseDiag = diagSpan && (weightsDI.y > weightsDI.x); 991 | bool horzSpan = weightsHV.x > weightsHV.y; 992 | 993 | // get highest single-point delta 994 | float4 crosscheck = max(crossdelta, diagdelta); 995 | float2 stepcheck = max(crosscheck.xy, crosscheck.zw); 996 | float range = max(stepcheck.x, stepcheck.y); 997 | 998 | // abort if not above edge threshold 999 | if (range < edgethreshold) return original; 1000 | 1001 | //setup scanning gradient 1002 | float2 lumaNP = float2(lumaN, lumaS); 1003 | QXAAMovc(!horzSpan.xx, lumaNP, float2(lumaW, lumaE)); 1004 | QXAAMovc(diagSpan.xx, lumaNP, float2(lumaNW, lumaSE)); 1005 | QXAAMovc((diagSpan && inverseDiag).xx, lumaNP, float2(lumaSW, lumaNE)); 1006 | float gradientN = abs(lumaNP.x - lumaM); 1007 | float gradientP = abs(lumaNP.y - lumaM); 1008 | float lumaNN = lumaNP.x + lumaM; 1009 | if (gradientN >= gradientP && !diagSpan) lengthSign = -lengthSign; 1010 | if (diagSpan && inverseDiag) lengthSign.y = -lengthSign.y; 1011 | if (gradientP > gradientN) lumaNN = lumaNP.y + lumaM; 1012 | float gradientScaled = max(gradientN, gradientP) * 0.25; 1013 | bool lumaMLTZero = mad(0.5, -lumaNN, lumaM) < 0.0; 1014 | 1015 | //setup gradient scanning texel step 1016 | float2 posB = texcoord; 1017 | float texelsize = QxaaTexelSize; 1018 | float2 offNP = float2(0.0, BUFFER_RCP_HEIGHT * texelsize); 1019 | QXAAMovc(bool(horzSpan).xx, offNP, float2(BUFFER_RCP_WIDTH * texelsize, 0.0)); 1020 | QXAAMovc(bool(diagSpan).xx, offNP, float2(BUFFER_RCP_WIDTH * texelsize, BUFFER_RCP_HEIGHT * texelsize)); 1021 | if (diagSpan && inverseDiag) offNP.y = -offNP.y; 1022 | 1023 | // 1/3 is the magic number here, I don't know how NVIDIA got 0.5. 1024 | QXAAMovc(bool2(!horzSpan || diagSpan, horzSpan || diagSpan), posB, float2(posB.x + lengthSign.x * 0.333333, posB.y + lengthSign.y * 0.333333)); 1025 | 1026 | //init scan tracking and do first iteration 1027 | float2 posN = posB - offNP; 1028 | float2 posP = posB + offNP; 1029 | float lumaEndN = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, posN).rgb, ref); 1030 | float lumaEndP = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, posP).rgb, ref); 1031 | lumaNN *= 0.5; 1032 | lumaEndN -= lumaNN; 1033 | lumaEndP -= lumaNN; 1034 | bool doneN = abs(lumaEndN) >= gradientScaled; 1035 | bool doneP = abs(lumaEndP) >= gradientScaled; 1036 | 1037 | //perform gradient scanning 1038 | uint iterations = 0; 1039 | uint maxiterations = QxaaScanIterations; 1040 | [loop] while (iterations < maxiterations) 1041 | { 1042 | if (doneN && doneP) break; 1043 | if (!doneN) 1044 | { 1045 | posN -= offNP; 1046 | lumaEndN = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, posN).rgb, ref); 1047 | lumaEndN -= lumaNN; 1048 | doneN = abs(lumaEndN) >= gradientScaled; 1049 | } 1050 | if (!doneP) 1051 | { 1052 | posP += offNP; 1053 | lumaEndP = dot(QXAA_DecodeTex2D(ReShade::BackBuffer, posP).rgb, ref); 1054 | lumaEndP -= lumaNN; 1055 | doneP = abs(lumaEndP) >= gradientScaled; 1056 | } 1057 | iterations++; 1058 | } 1059 | 1060 | //determine resulting distance from origin 1061 | //pythagorean theorem used to generate diagonal N/P distances [hypotenuse = sqrt(pow(x,2) + pow(y,2))] 1062 | float2 dstNP = float2(texcoord.y - posN.y, posP.y - texcoord.y); 1063 | QXAAMovc(bool(horzSpan).xx, dstNP, float2(texcoord.x - posN.x, posP.x - texcoord.x)); 1064 | QXAAMovc(bool(diagSpan).xx, dstNP, float2(sqrt(pow(abs(texcoord.y - posN.y), 2.0) + pow(abs(texcoord.x - posN.x), 2.0)), sqrt(pow(abs(posP.y - texcoord.y), 2.0) + pow(abs(posP.x - texcoord.x), 2.0)))); 1065 | 1066 | //perform noise control calculations 1067 | float endluma = (dstNP.x < dstNP.y) ? lumaEndN : lumaEndP; 1068 | bool goodSpan = endluma < 0.0 != lumaMLTZero; 1069 | float blendclamp = goodSpan ? 1.0 : (1.0 - abs(endluma - lumaM) * (QxaaNoiseControlStrength / 100.)); 1070 | 1071 | //calculate offset from origin 1072 | float pixelOffset = abs(mad(-rcp(dstNP.y + dstNP.x), min(dstNP.x, dstNP.y), 0.5)) * clamp(QxaaStrength / 100.0, 0.0, blendclamp); 1073 | 1074 | //calculate offset weight 1075 | float subpixOut = 1.0; 1076 | if (!goodSpan) // bad span 1077 | { 1078 | subpixOut = mad(mad(2.0, lumaS + lumaE + lumaN + lumaW, lumaNW + lumaSE + lumaNE + lumaSW), 0.083333, -lumaM) * (1.0 / range); //ABC 1079 | subpixOut = pow(saturate(mad(-2.0, subpixOut, 3.0) * (subpixOut * subpixOut)), 2.0); // DEFGH 1080 | } 1081 | subpixOut *= pixelOffset; 1082 | 1083 | //generate final sampling coordinates 1084 | float2 posM = texcoord; 1085 | QXAAMovc(bool2(!horzSpan || diagSpan, horzSpan || diagSpan), posM, float2(posM.x + lengthSign.x * subpixOut, posM.y + lengthSign.y * subpixOut)); 1086 | 1087 | //fart result 1088 | return QXAA_Tex2D(ReShade::BackBuffer, posM).rgb; 1089 | } 1090 | 1091 | // ordering = sharpen > hysteresis > tonemap > brightness > blue filter > saturation 1092 | float3 QXAAHysteresisPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 1093 | { 1094 | float3 pixel = QXAA_Tex2D(ReShade::BackBuffer, texcoord).rgb; 1095 | float3 original = pixel; 1096 | float preluma = QXAA_Tex2D(OriginalLuma, texcoord).r; 1097 | bool altered = false; 1098 | 1099 | if (!QxaaEnableSharpening) pixel = ConditionalDecode(pixel); 1100 | if (QxaaEnableSharpening) 1101 | { 1102 | float2 hvstep = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); 1103 | float2 diagstep = hvstep * __QXAA_CONST_HALFROOT2; 1104 | float3 casdot = pixel; 1105 | float3 a = QXAA_Tex2D(ReShade::BackBuffer, texcoord - diagstep).rgb; 1106 | float3 c = QXAA_Tex2D(ReShade::BackBuffer, texcoord + float2(diagstep.x, -diagstep.y)).rgb; 1107 | float3 g = QXAA_Tex2D(ReShade::BackBuffer, texcoord + float2(-diagstep.x, diagstep.y)).rgb; 1108 | float3 i = QXAA_Tex2D(ReShade::BackBuffer, texcoord + diagstep).rgb; 1109 | float3 b = QXAA_Tex2D(ReShade::BackBuffer, texcoord + float2(0.0, -hvstep.y)).rgb; 1110 | float3 d = QXAA_Tex2D(ReShade::BackBuffer, texcoord + float2(-hvstep.x, 0.0)).rgb; 1111 | float3 f = QXAA_Tex2D(ReShade::BackBuffer, texcoord + float2(hvstep.x, 0.0)).rgb; 1112 | float3 h = QXAA_Tex2D(ReShade::BackBuffer, texcoord + float2(0.0, hvstep.y)).rgb; 1113 | 1114 | float3 mnRGB = QXAAmin5(d, casdot, f, b, h); 1115 | float3 mnRGB2 = QXAAmin5(mnRGB, a, c, g, i); 1116 | 1117 | float3 mxRGB = QXAAmax5(d, casdot, f, b, h); 1118 | float3 mxRGB2 = QXAAmax5(mxRGB,a,c,g,i); 1119 | 1120 | casdot = ConditionalDecode(casdot); 1121 | mnRGB = ConditionalDecode(mnRGB); 1122 | mnRGB2 = ConditionalDecode(mnRGB2); 1123 | mxRGB = ConditionalDecode(mxRGB); 1124 | mxRGB2 = ConditionalDecode(mxRGB2); 1125 | 1126 | mnRGB += mnRGB2; 1127 | mxRGB += mxRGB2; 1128 | 1129 | float3 ampRGB = 1.0 / sqrt(saturate(min(mnRGB, 2.0 - mxRGB) * (1.0 / mxRGB))); 1130 | float3 wRGB = -(1.0 / (ampRGB * mad(-3.0, QxaaSharpenerAdaptation, 8.0))); 1131 | float3 window = (b + d) + (f + h); 1132 | 1133 | float3 outColor = saturate(mad(window, wRGB, casdot) * (1.0 / mad(4.0, wRGB, 1.0))); 1134 | casdot = lerp(casdot, outColor, QxaaSharpenerStrength); 1135 | 1136 | pixel = casdot; 1137 | altered = true; 1138 | } 1139 | 1140 | float hysteresis = (dot(pixel, __QXAA_LUMA_REF) - preluma) * QxaaHysteresisStrength; 1141 | if (abs(hysteresis) > QxaaHysteresisFudgeFactor) 1142 | { 1143 | bool3 truezero = !pixel; 1144 | pixel = pow(abs(1.0 + hysteresis) * 2.0, log2(pixel)); 1145 | pixel *= float3(!truezero); 1146 | altered = true; 1147 | } 1148 | 1149 | if (QxaaEnableTonemap && (QxaaTonemapping > 0)) 1150 | { 1151 | bool3 truezero = !pixel; 1152 | if (QxaaTonemapping == 1) pixel = extended_reinhard(pixel); 1153 | if (QxaaTonemapping == 2) pixel = extended_reinhard_luma(pixel); 1154 | if (QxaaTonemapping == 3) pixel = reinhard_jodie(pixel); 1155 | if (QxaaTonemapping == 4) pixel = uncharted2_filmic(pixel); 1156 | if (QxaaTonemapping == 5) pixel = aces_approx(pixel); 1157 | if (QxaaTonemapping == 6) pixel = logarithmic_fake_hdr(pixel) * float3(!truezero); 1158 | if (QxaaTonemapping == 7) pixel = logarithmic_range_compression(pixel) * float3(!truezero); 1159 | altered = true; 1160 | } 1161 | 1162 | if (QxaaEnableTonemap && (QxaaGainStrength > 0.0)) 1163 | { 1164 | float3 outdot = pixel; 1165 | float presaturation = dotsat(outdot); 1166 | float preluma = dot(outdot, __QXAA_LUMA_REF); 1167 | bool3 truezero = !outdot; 1168 | float colorgain = 2.0 - log2(QxaaGainStrength + 1.0); 1169 | float channelfloor = __QXAA_MIN_STEP; 1170 | outdot = log2(clamp(outdot, channelfloor, 1.0 - channelfloor)); 1171 | outdot = pow(abs(colorgain), outdot); 1172 | if (QxaaGainLowLumaCorrection) 1173 | { 1174 | // calculate new black level 1175 | channelfloor = pow(abs(colorgain), log2(channelfloor)); 1176 | // calculate reduction strength to apply 1177 | float contrastgain = log(1.0 / (dot(outdot, __QXAA_LUMA_REF) - channelfloor)) * pow(__QXAA_CONST_E, (1.0 + channelfloor) * __QXAA_CONST_E) * QxaaGainStrength * QxaaGainStrength; 1178 | outdot = pow(abs(2.0 + contrastgain) * 5.0, log10(outdot)); 1179 | float lumadelta = dot(outdot, __QXAA_LUMA_REF) - preluma; 1180 | outdot = RGBtoYUV(outdot); 1181 | outdot.x = saturate(outdot.x - lumadelta * channelfloor); 1182 | outdot = YUVtoRGB(outdot); 1183 | float newsat = dotsat(outdot); 1184 | float satadjust = abs(((newsat - presaturation) / 2.0) * (1.0 + QxaaGainStrength)); // compute difference in before/after saturation 1185 | if (satadjust != 0.0) outdot = AdjustSaturation(outdot, 0.5 + satadjust); 1186 | } 1187 | pixel = float3(!truezero) * outdot; 1188 | altered = true; 1189 | } 1190 | 1191 | if (QxaaEnableTonemap && (QxaaBlueLightFilter != 0.0)) 1192 | { 1193 | float3 outdot = RGBtoYUV(pixel); 1194 | float strength = 1.0 - QxaaBlueLightFilter; 1195 | float signalclamp = (outdot.x * 0.5) * dotsat(pixel) * abs(outdot.y); 1196 | if (outdot.z > 0.0) outdot.z = clamp(outdot.z * strength, signalclamp, 0.5); 1197 | pixel = YUVtoRGB(outdot); 1198 | altered = true; 1199 | } 1200 | 1201 | if (QxaaEnableTonemap && (QxaaSaturationStrength != 0.5)) 1202 | { 1203 | float3 outdot = AdjustSaturation(pixel, QxaaSaturationStrength); 1204 | pixel = outdot; 1205 | altered = true; 1206 | } 1207 | 1208 | if (altered) return ConditionalEncode(pixel); 1209 | else return original; 1210 | } 1211 | 1212 | /***************************************************************************************************************************************/ 1213 | /********************************************************** QXAA SHADER CODE END *******************************************************/ 1214 | /***************************************************************************************************************************************/ 1215 | 1216 | technique QXAA < 1217 | ui_tooltip = "============================================================\n" 1218 | "high-Quality approXimate Anti-Aliasing is a stand-alone\n" 1219 | "version of the FXAA pass used in HQAA. It is more costly\n" 1220 | "than normal FXAA but typically yields excellent results for\n" 1221 | "its execution cost.\n" 1222 | "============================================================"; 1223 | > 1224 | { 1225 | pass Init 1226 | { 1227 | VertexShader = PostProcessVS; 1228 | PixelShader = QXAAInitPS; 1229 | RenderTarget = QXAAHysteresisInfoTex; 1230 | ClearRenderTargets = true; 1231 | } 1232 | pass QXAA 1233 | { 1234 | VertexShader = PostProcessVS; 1235 | PixelShader = QXAAPS; 1236 | } 1237 | #if QXAA_MULTISAMPLING > 1 1238 | pass QXAA 1239 | { 1240 | VertexShader = PostProcessVS; 1241 | PixelShader = QXAAPS; 1242 | } 1243 | #if QXAA_MULTISAMPLING > 2 1244 | pass QXAA 1245 | { 1246 | VertexShader = PostProcessVS; 1247 | PixelShader = QXAAPS; 1248 | } 1249 | #if QXAA_MULTISAMPLING > 3 1250 | pass QXAA 1251 | { 1252 | VertexShader = PostProcessVS; 1253 | PixelShader = QXAAPS; 1254 | } 1255 | #endif //QXAA_MULTISAMPLING 3 1256 | #endif //QXAA_MULTISAMPLING 2 1257 | #endif //QXAA_MULTISAMPLING 1 1258 | pass Hysteresis 1259 | { 1260 | VertexShader = PostProcessVS; 1261 | PixelShader = QXAAHysteresisPS; 1262 | } 1263 | } 1264 | -------------------------------------------------------------------------------- /Shaders/STAA.fx: -------------------------------------------------------------------------------- 1 | /* STAA for ReShade 3.1.1+ 2 | * 3 | * (Subpixel-jittered Temporal Anti-Aliasing) 4 | * 5 | * by lordbean 6 | * 7 | */ 8 | 9 | // This shader includes code adapted from: 10 | 11 | /**============================================================================ 12 | 13 | 14 | NVIDIA FXAA 3.11 by TIMOTHY LOTTES 15 | 16 | 17 | ------------------------------------------------------------------------------ 18 | COPYRIGHT (C) 2010, 2011 NVIDIA CORPORATION. ALL RIGHTS RESERVED. 19 | ------------------------------------------------------------------------------*/ 20 | 21 | /* AMD CONTRAST ADAPTIVE SHARPENING 22 | // ======= 23 | // Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved. 24 | // ------- 25 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 26 | // files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 27 | // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 28 | // Software is furnished to do so, subject to the following conditions: 29 | // ------- 30 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 31 | // Software. 32 | // --------*/ 33 | 34 | // Original code is copyright (c) Derek Brush aka "lordbean" (derekbrush@gmail.com) 35 | 36 | /** Permission is hereby granted, free of charge, to any person obtaining a copy 37 | * this software and associated documentation files (the "Software"), to deal in 38 | * the Software without restriction, including without limitation the rights to 39 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 40 | * of the Software, and to permit persons to whom the Software is furnished to 41 | * do so, subject to the following conditions: 42 | * 43 | * The above copyright notice and this permission notice shall be included in 44 | * all copies or substantial portions of the Software. As clarification, there 45 | * is no requirement that the copyright notice and permission be included in 46 | * binary distributions of the Software. 47 | **/ 48 | 49 | /*------------------------------------------------------------------------------ 50 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 56 | * SOFTWARE. 57 | *-------------------------------------------------------------------------------*/ 58 | 59 | 60 | /*****************************************************************************************************************************************/ 61 | /*********************************************************** UI SETUP START **************************************************************/ 62 | /*****************************************************************************************************************************************/ 63 | 64 | #ifndef STAA_MULTISAMPLE_COUNT 65 | #define STAA_MULTISAMPLE_COUNT 2 66 | #endif 67 | 68 | #if STAA_MULTISAMPLE_COUNT > 4 || STAA_MULTISAMPLE_COUNT < 1 69 | #undef STAA_MULTISAMPLE_COUNT 70 | #define STAA_MULTISAMPLE_COUNT 2 71 | #endif 72 | 73 | #include "ReShadeUI.fxh" 74 | 75 | uniform uint FrameCounter ; 76 | 77 | uniform int StaaAboutSTART < 78 | ui_type = "radio"; 79 | ui_label = " "; 80 | ui_text = "\n----------------------------------- STAA 1.1 -----------------------------------"; 81 | >; 82 | 83 | uniform int StaaIntroduction < 84 | ui_spacing = 3; 85 | ui_type = "radio"; 86 | ui_label = "Version: 1.1"; 87 | ui_text = "-------------------------------------------------------------------------\n" 88 | " Subpixel-jittered Temporal Anti-Aliasing, a shader by lordbean\n" 89 | " https://github.com/lordbean-git/reshade-shaders/\n" 90 | "-------------------------------------------------------------------------\n\n" 91 | "STAA uses one QXAA pass to pre-smoothen the scene followed by two\n" 92 | "temporal jitter blending passes and then one CAS pass to counter some\n" 93 | "of the incurred blurring. Settings for QXAA and CAS are calculated using\n" 94 | "the TAA configuration in order to produce good output. Additional\n" 95 | "sharpening is recommended after STAA runs.\n" 96 | "\nIncreasing the number of blend passes may increase quality. Be aware\n" 97 | "that each extra pass requires additional VRAM for extra textures. Check\n" 98 | "the Statistics tab for information on how much VRAM the shader is using.\n" 99 | "\nJitter Blend Passes: " 100 | #if STAA_MULTISAMPLE_COUNT > 3 101 | "4x\n" 102 | #elif STAA_MULTISAMPLE_COUNT > 2 103 | "3x\n" 104 | #elif STAA_MULTISAMPLE_COUNT > 1 105 | "2x\n" 106 | #else 107 | "1x\n" 108 | #endif 109 | "\n-------------------------------------------------------------------------" 110 | "\nSee the 'Preprocessor definitions' section for color & feature toggles.\n" 111 | "-------------------------------------------------------------------------"; 112 | ui_tooltip = "Can now be considered a BIT less change-prone."; 113 | ui_category = "About"; 114 | ui_category_closed = true; 115 | >; 116 | 117 | uniform int StaaAboutEOF < 118 | ui_type = "radio"; 119 | ui_label = " "; 120 | ui_text = "\n--------------------------------------------------------------------------------"; 121 | >; 122 | 123 | uniform float EdgeThreshold < 124 | ui_type = "slider"; 125 | ui_label = "Edge Threshold"; 126 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 127 | ui_label = "Minimum contrast delta to be considered an edge.\n" 128 | "To control ghosting, temporal jittering only runs\n" 129 | "where edges are detected. Default should work well\n" 130 | "in most cases, 0 can be used to process full scene."; 131 | > = 0.04; 132 | 133 | uniform float JitterOffset < 134 | ui_type = "slider"; 135 | ui_label = "Jitter Offset"; 136 | ui_min = 0.0; ui_max = 0.5; ui_step = 0.001; 137 | ui_tooltip = "Distance (in pixels) that temporal samples\n" 138 | "will be jittered. Higher counteracts more\n" 139 | "aliasing and shimmering but increases blur."; 140 | > = 0.333333; 141 | 142 | uniform float TemporalWeight < 143 | ui_type = "slider"; 144 | ui_label = "Temporal Blend Weight"; 145 | ui_min = 0.0; ui_max = 0.5; ui_step = 0.001; 146 | ui_tooltip = "Amount of weight given to previous frame.\n" 147 | "Causes a bit of ghosting, but helps to\n" 148 | "cover shimmering and temporal aliasing.\n" 149 | "STAA still works with this set to zero,\n" 150 | "and will not produce any ghosting. It is\n" 151 | "simply less effective against shimmering."; 152 | > = 0.25; 153 | 154 | uniform float MinimumBlend < 155 | ui_type = "slider"; 156 | ui_label = "Minimum Blend Strength"; 157 | ui_tooltip = "Blends at least this much of the calculated\n" 158 | "jitter result when processing edges. The\n" 159 | "remaining portion is flexible and determined\n" 160 | "by the detection strength of the edge."; 161 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 162 | > = 0.333333; 163 | 164 | uniform int StaaOptionsEOF < 165 | ui_type = "radio"; 166 | ui_label = " "; 167 | ui_text = "\n--------------------------------------------------------------------------------"; 168 | >; 169 | 170 | /*****************************************************************************************************************************************/ 171 | /*********************************************************** UI SETUP END ****************************************************************/ 172 | /*****************************************************************************************************************************************/ 173 | 174 | /*****************************************************************************************************************************************/ 175 | /******************************************************** SYNTAX SETUP START *************************************************************/ 176 | /*****************************************************************************************************************************************/ 177 | 178 | #define __STAA_SMALLEST_COLOR_STEP rcp(pow(2., BUFFER_COLOR_BIT_DEPTH)) 179 | #define __STAA_CONST_E 2.7182818284590452353602874713527 180 | #define __STAA_CONST_HALFROOT2 (sqrt(2.)/2.) 181 | #define __STAA_LUMA_REF float3(0.2126, 0.7152, 0.0722) 182 | #define __STAA_AVERAGE_REF float3(0.333333, 0.333334, 0.333333) 183 | #define __STAA_GREEN_LUMA float3(1./5., 7./10., 1./10.) 184 | #define __STAA_RED_LUMA float3(5./8., 1./4., 1./8.) 185 | #define __STAA_BLUE_LUMA float3(1./8., 3./8., 1./2.) 186 | #define __STAA_BUFFER_STEP float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT) 187 | #define __STAA_OFFSET float2(JitterOffset * __STAA_BUFFER_STEP) 188 | #define __STAA_REVERSE float2(__STAA_OFFSET.x, -__STAA_OFFSET.y) 189 | 190 | #define STAA_Tex2D(tex, coord) tex2Dlod(tex, (coord).xyxy) 191 | 192 | #define STAAmax3(x,y,z) max(max(x,y),z) 193 | #define STAAmax4(w,x,y,z) max(max(w,x),max(y,z)) 194 | #define STAAmax5(v,w,x,y,z) max(max(max(v,w),x),max(y,z)) 195 | #define STAAmax6(u,v,w,x,y,z) max(max(max(u,v),max(w,x)),max(y,z)) 196 | #define STAAmax7(t,u,v,w,x,y,z) max(max(max(t,u),max(v,w)),max(max(x,y),z)) 197 | #define STAAmax8(s,t,u,v,w,x,y,z) max(max(max(s,t),max(u,v)),max(max(w,x),max(y,z))) 198 | #define STAAmax9(r,s,t,u,v,w,x,y,z) max(max(max(max(r,s),t),max(u,v)),max(max(w,x),max(y,z))) 199 | #define STAAmax10(q,r,s,t,u,v,w,x,y,z) max(max(max(max(q,r),max(s,t)),max(u,v)),max(max(w,x),max(y,z))) 200 | #define STAAmax11(p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(p,q),max(r,s)),max(max(t,u),v)),max(max(w,x),max(y,z))) 201 | #define STAAmax12(o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(o,p),max(q,r)),max(max(s,t),max(u,v))),max(max(w,x),max(y,z))) 202 | #define STAAmax13(n,o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(n,o),max(p,q)),max(max(r,s),max(t,u))),max(max(max(v,w),x),max(y,z))) 203 | #define STAAmax14(m,n,o,p,q,r,s,t,u,v,w,x,y,z) max(max(max(max(m,n),max(o,p)),max(max(q,r),max(s,t))),max(max(max(u,v),max(w,x)),max(y,z))) 204 | #define STAAmin3(x,y,z) min(min(x,y),z) 205 | #define STAAmin4(w,x,y,z) min(min(w,x),min(y,z)) 206 | #define STAAmin5(v,w,x,y,z) min(min(min(v,w),x),min(y,z)) 207 | #define STAAmin6(u,v,w,x,y,z) min(min(min(u,v),min(w,x)),min(y,z)) 208 | #define STAAmin7(t,u,v,w,x,y,z) min(min(min(t,u),min(v,w)),min(min(x,y),z)) 209 | #define STAAmin8(s,t,u,v,w,x,y,z) min(min(min(s,t),min(u,v)),min(min(w,x),min(y,z))) 210 | #define STAAmin9(r,s,t,u,v,w,x,y,z) min(min(min(min(r,s),t),min(u,v)),min(min(w,x),min(y,z))) 211 | #define STAAmin10(q,r,s,t,u,v,w,x,y,z) min(min(min(min(q,r),min(s,t)),min(u,v)),min(min(w,x),min(y,z))) 212 | #define STAAmin11(p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(p,q),min(r,s)),min(min(t,u),v)),min(min(w,x),min(y,z))) 213 | #define STAAmin12(o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(o,p),min(q,r)),min(min(s,t),min(u,v))),min(min(w,x),min(y,z))) 214 | #define STAAmin13(n,o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(n,o),min(p,q)),min(min(r,s),min(t,u))),min(min(min(v,w),x),min(y,z))) 215 | #define STAAmin14(m,n,o,p,q,r,s,t,u,v,w,x,y,z) min(min(min(min(m,n),min(o,p)),min(min(q,r),min(s,t))),min(min(min(u,v),min(w,x)),min(y,z))) 216 | 217 | /*****************************************************************************************************************************************/ 218 | /********************************************************* SYNTAX SETUP END **************************************************************/ 219 | /*****************************************************************************************************************************************/ 220 | 221 | /*****************************************************************************************************************************************/ 222 | /******************************************************** SUPPORT CODE START *************************************************************/ 223 | /*****************************************************************************************************************************************/ 224 | 225 | void STAAMovc(bool2 cond, inout float2 variable, float2 value) 226 | { 227 | [flatten] if (cond.x) variable.x = value.x; 228 | [flatten] if (cond.y) variable.y = value.y; 229 | } 230 | void STAAMovc(bool4 cond, inout float4 variable, float4 value) 231 | { 232 | STAAMovc(cond.xy, variable.xy, value.xy); 233 | STAAMovc(cond.zw, variable.zw, value.zw); 234 | } 235 | 236 | float lxor(float x, float y) 237 | { 238 | bool valid = (x == 0.0) ? ((y == 0.0) ? false : true) : ((y == 0.0) ? true : false); 239 | if (valid) return x + y; 240 | else return 0.0; 241 | } 242 | float2 lxor(float2 x, float2 y) 243 | { 244 | return float2(lxor(x.x, y.x), lxor(x.y, y.y)); 245 | } 246 | float3 lxor(float3 x, float3 y) 247 | { 248 | return float3(lxor(x.x, y.x), lxor(x.yz, y.yz)); 249 | } 250 | float4 lxor(float4 x, float4 y) 251 | { 252 | return float4(lxor(x.xy, y.xy), lxor(x.zw, y.zw)); 253 | } 254 | 255 | float lnand(float x, float y) 256 | { 257 | return y == 0.0 ? x : 0.0; 258 | } 259 | float2 lnand(float2 x, float2 y) 260 | { 261 | return float2(lnand(x.x, y.x), lnand(x.y, y.y)); 262 | } 263 | float3 lnand(float3 x, float3 y) 264 | { 265 | return float3(lnand(x.x, y.x), lnand(x.yz, y.yz)); 266 | } 267 | float4 lnand(float4 x, float4 y) 268 | { 269 | return float4(lnand(x.xy, y.xy), lnand(x.zw, y.zw)); 270 | } 271 | 272 | float chromadelta(float3 pixel1, float3 pixel2) 273 | { 274 | return dot(abs(pixel1 - pixel2), float3(0.333333, 0.333334, 0.333333)); 275 | } 276 | 277 | /***************************************************************************************************************************************/ 278 | /******************************************************** SUPPORT CODE END *************************************************************/ 279 | /***************************************************************************************************************************************/ 280 | 281 | /***************************************************************************************************************************************/ 282 | /*********************************************************** SHADER SETUP START ********************************************************/ 283 | /***************************************************************************************************************************************/ 284 | 285 | #include "ReShade.fxh" 286 | 287 | //////////////////////////////////////////////////////////// TEXTURES /////////////////////////////////////////////////////////////////// 288 | 289 | texture StaaJitterTex0 290 | { 291 | Width = BUFFER_WIDTH; 292 | Height = BUFFER_HEIGHT; 293 | #if BUFFER_COLOR_BIT_DEPTH == 8 294 | Format = RGBA8; 295 | #elif BUFFER_COLOR_BIT_DEPTH == 10 296 | Format = RGB10A2; 297 | #else 298 | Format = RGBA16F; 299 | #endif 300 | }; 301 | sampler JitterTex0 {Texture = StaaJitterTex0;}; 302 | 303 | texture StaaJitterTex1 304 | { 305 | Width = BUFFER_WIDTH; 306 | Height = BUFFER_HEIGHT; 307 | #if BUFFER_COLOR_BIT_DEPTH == 8 308 | Format = RGBA8; 309 | #elif BUFFER_COLOR_BIT_DEPTH == 10 310 | Format = RGB10A2; 311 | #else 312 | Format = RGBA16F; 313 | #endif 314 | }; 315 | sampler JitterTex1 {Texture = StaaJitterTex1;}; 316 | 317 | #if STAA_MULTISAMPLE_COUNT > 1 318 | texture StaaJitterTex2 319 | { 320 | Width = BUFFER_WIDTH; 321 | Height = BUFFER_HEIGHT; 322 | #if BUFFER_COLOR_BIT_DEPTH == 8 323 | Format = RGBA8; 324 | #elif BUFFER_COLOR_BIT_DEPTH == 10 325 | Format = RGB10A2; 326 | #else 327 | Format = RGBA16F; 328 | #endif 329 | }; 330 | sampler JitterTex2 {Texture = StaaJitterTex2;}; 331 | 332 | texture StaaJitterTex3 333 | { 334 | Width = BUFFER_WIDTH; 335 | Height = BUFFER_HEIGHT; 336 | #if BUFFER_COLOR_BIT_DEPTH == 8 337 | Format = RGBA8; 338 | #elif BUFFER_COLOR_BIT_DEPTH == 10 339 | Format = RGB10A2; 340 | #else 341 | Format = RGBA16F; 342 | #endif 343 | }; 344 | sampler JitterTex3 {Texture = StaaJitterTex3;}; 345 | #endif 346 | 347 | #if STAA_MULTISAMPLE_COUNT > 2 348 | texture StaaJitterTex4 349 | { 350 | Width = BUFFER_WIDTH; 351 | Height = BUFFER_HEIGHT; 352 | #if BUFFER_COLOR_BIT_DEPTH == 8 353 | Format = RGBA8; 354 | #elif BUFFER_COLOR_BIT_DEPTH == 10 355 | Format = RGB10A2; 356 | #else 357 | Format = RGBA16F; 358 | #endif 359 | }; 360 | sampler JitterTex4 {Texture = StaaJitterTex4;}; 361 | 362 | texture StaaJitterTex5 363 | { 364 | Width = BUFFER_WIDTH; 365 | Height = BUFFER_HEIGHT; 366 | #if BUFFER_COLOR_BIT_DEPTH == 8 367 | Format = RGBA8; 368 | #elif BUFFER_COLOR_BIT_DEPTH == 10 369 | Format = RGB10A2; 370 | #else 371 | Format = RGBA16F; 372 | #endif 373 | }; 374 | sampler JitterTex5 {Texture = StaaJitterTex5;}; 375 | #endif 376 | 377 | #if STAA_MULTISAMPLE_COUNT > 3 378 | texture StaaJitterTex6 379 | { 380 | Width = BUFFER_WIDTH; 381 | Height = BUFFER_HEIGHT; 382 | #if BUFFER_COLOR_BIT_DEPTH == 8 383 | Format = RGBA8; 384 | #elif BUFFER_COLOR_BIT_DEPTH == 10 385 | Format = RGB10A2; 386 | #else 387 | Format = RGBA16F; 388 | #endif 389 | }; 390 | sampler JitterTex6 {Texture = StaaJitterTex6;}; 391 | 392 | texture StaaJitterTex7 393 | { 394 | Width = BUFFER_WIDTH; 395 | Height = BUFFER_HEIGHT; 396 | #if BUFFER_COLOR_BIT_DEPTH == 8 397 | Format = RGBA8; 398 | #elif BUFFER_COLOR_BIT_DEPTH == 10 399 | Format = RGB10A2; 400 | #else 401 | Format = RGBA16F; 402 | #endif 403 | }; 404 | sampler JitterTex7 {Texture = StaaJitterTex7;}; 405 | #endif 406 | 407 | texture StaaEdgesTex 408 | { 409 | Width = BUFFER_WIDTH; 410 | Height = BUFFER_HEIGHT; 411 | Format = R32F; // high precision desired due to use in every pass 412 | }; 413 | sampler EdgesTex {Texture = StaaEdgesTex;}; 414 | 415 | /*****************************************************************************************************************************************/ 416 | /*********************************************************** SHADER SETUP END ************************************************************/ 417 | /*****************************************************************************************************************************************/ 418 | 419 | /*****************************************************************************************************************************************/ 420 | /************************************************************ SHADER CODE START **********************************************************/ 421 | /*****************************************************************************************************************************************/ 422 | 423 | float EdgeDetectionPS(float4 position : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 424 | { 425 | float3 middle = STAA_Tex2D(ReShade::BackBuffer, texcoord).rgb; 426 | float2 hvstep = __STAA_BUFFER_STEP; 427 | float2 diagstep = hvstep * __STAA_CONST_HALFROOT2; 428 | 429 | float Dtop = chromadelta(middle, STAA_Tex2D(ReShade::BackBuffer, texcoord - float2(0, hvstep.y)).rgb); 430 | float Dleft = chromadelta(middle, STAA_Tex2D(ReShade::BackBuffer, texcoord - float2(hvstep.x, 0)).rgb); 431 | float Dright = chromadelta(middle, STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(hvstep.x, 0)).rgb); 432 | float Dbottom = chromadelta(middle, STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(0, hvstep.y)).rgb); 433 | float Dtopleft = chromadelta(middle, STAA_Tex2D(ReShade::BackBuffer, texcoord - diagstep).rgb); 434 | float Dbottomright = chromadelta(middle, STAA_Tex2D(ReShade::BackBuffer, texcoord + diagstep).rgb); 435 | float Dtopright = chromadelta(middle, STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(diagstep.x, -diagstep.y)).rgb); 436 | float Dbottomleft = chromadelta(middle, STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(-diagstep.x, diagstep.y)).rgb); 437 | 438 | float crossedges = STAAmax4(Dleft, Dtop, Dright, Dbottom); 439 | float diagedges = STAAmax4(Dtopleft, Dbottomright, Dtopright, Dbottomleft); 440 | 441 | float edges = max(crossedges, diagedges); 442 | edges *= step(EdgeThreshold, edges); 443 | 444 | return edges; 445 | } 446 | 447 | float4 GenerateBufferJitterPS(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_Target 448 | { 449 | float2 offsetdir = 0.0.xx; 450 | if (FrameCounter & 1 == 0) offsetdir = __STAA_OFFSET; 451 | else offsetdir = __STAA_REVERSE; 452 | return (STAA_Tex2D(ReShade::BackBuffer, texcoord + offsetdir) + STAA_Tex2D(ReShade::BackBuffer, texcoord - offsetdir)) / 2.0; 453 | } 454 | 455 | float4 TransferJitterTexPS(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_Target 456 | { 457 | return STAA_Tex2D(JitterTex0, texcoord); 458 | } 459 | 460 | float4 TemporalBlendingPS(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_Target 461 | { 462 | float edges = STAA_Tex2D(EdgesTex, texcoord).r; 463 | float4 original = STAA_Tex2D(ReShade::BackBuffer, texcoord); 464 | if (!edges) return original; 465 | float blendweight = (1.0 - MinimumBlend) * sqrt(edges) + MinimumBlend; 466 | float4 jitter0 = STAA_Tex2D(JitterTex0, texcoord); 467 | float4 jitter1 = STAA_Tex2D(JitterTex1, texcoord); 468 | float4 temporaljitter = lerp(jitter0, jitter1, TemporalWeight); 469 | return lerp(original, temporaljitter, blendweight); 470 | } 471 | 472 | #if STAA_MULTISAMPLE_COUNT > 1 473 | float4 TransferJitterTexTwoPS(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_Target 474 | { 475 | return STAA_Tex2D(JitterTex2, texcoord); 476 | } 477 | 478 | float4 TemporalBlendingTwoPS(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_Target 479 | { 480 | float edges = STAA_Tex2D(EdgesTex, texcoord).r; 481 | float4 original = STAA_Tex2D(ReShade::BackBuffer, texcoord); 482 | if (!edges) return original; 483 | float blendweight = (1.0 - MinimumBlend) * sqrt(edges) + MinimumBlend; 484 | float4 jitter0 = STAA_Tex2D(JitterTex2, texcoord); 485 | float4 jitter1 = STAA_Tex2D(JitterTex3, texcoord); 486 | float4 temporaljitter = lerp(jitter0, jitter1, TemporalWeight); 487 | return lerp(original, temporaljitter, blendweight); 488 | } 489 | #endif 490 | 491 | #if STAA_MULTISAMPLE_COUNT > 2 492 | float4 TransferJitterTexThreePS(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_Target 493 | { 494 | return STAA_Tex2D(JitterTex4, texcoord); 495 | } 496 | 497 | float4 TemporalBlendingThreePS(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_Target 498 | { 499 | float edges = STAA_Tex2D(EdgesTex, texcoord).r; 500 | float4 original = STAA_Tex2D(ReShade::BackBuffer, texcoord); 501 | if (!edges) return original; 502 | float blendweight = (1.0 - MinimumBlend) * sqrt(edges) + MinimumBlend; 503 | float4 jitter0 = STAA_Tex2D(JitterTex4, texcoord); 504 | float4 jitter1 = STAA_Tex2D(JitterTex5, texcoord); 505 | float4 temporaljitter = lerp(jitter0, jitter1, TemporalWeight); 506 | return lerp(original, temporaljitter, blendweight); 507 | } 508 | #endif 509 | 510 | #if STAA_MULTISAMPLE_COUNT > 3 511 | float4 TransferJitterTexFourPS(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_Target 512 | { 513 | return STAA_Tex2D(JitterTex6, texcoord); 514 | } 515 | 516 | float4 TemporalBlendingFourPS(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_Target 517 | { 518 | float edges = STAA_Tex2D(EdgesTex, texcoord).r; 519 | float4 original = STAA_Tex2D(ReShade::BackBuffer, texcoord); 520 | if (!edges) return original; 521 | float blendweight = (1.0 - MinimumBlend) * sqrt(edges) + MinimumBlend; 522 | float4 jitter0 = STAA_Tex2D(JitterTex6, texcoord); 523 | float4 jitter1 = STAA_Tex2D(JitterTex7, texcoord); 524 | float4 temporaljitter = lerp(jitter0, jitter1, TemporalWeight); 525 | return lerp(original, temporaljitter, blendweight); 526 | } 527 | #endif 528 | 529 | float3 QXAAPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 530 | { 531 | float3 original = STAA_Tex2D(ReShade::BackBuffer, texcoord).rgb; 532 | float edges = STAA_Tex2D(EdgesTex, texcoord).r; 533 | if (!edges) return original; 534 | 535 | float3 middle = original; 536 | float maxchannel = STAAmax3(middle.r, middle.g, middle.b); 537 | float3 ref; 538 | if (middle.g == maxchannel) ref = __STAA_GREEN_LUMA; 539 | else if (middle.r == maxchannel) ref = __STAA_RED_LUMA; 540 | else ref = __STAA_BLUE_LUMA; 541 | float lumaM = dot(middle, ref); 542 | float2 lengthSign = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); 543 | 544 | float lumaS = dot(STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(0.0, lengthSign.y)).rgb, ref); 545 | float lumaE = dot(STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(lengthSign.x, 0.0)).rgb, ref); 546 | float lumaN = dot(STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(0.0, -lengthSign.y)).rgb, ref); 547 | float lumaW = dot(STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(-lengthSign.x, 0.0)).rgb, ref); 548 | float4 crossdelta = abs(lumaM - float4(lumaS, lumaE, lumaN, lumaW)); 549 | float2 weightsHV = float2(crossdelta.x + crossdelta.z, crossdelta.y + crossdelta.w); 550 | 551 | // pattern 552 | // * z * 553 | // w * y 554 | // * x * 555 | 556 | float2 diagstep = lengthSign * __STAA_CONST_HALFROOT2; 557 | float lumaNW = dot(STAA_Tex2D(ReShade::BackBuffer, texcoord - diagstep).rgb, ref); 558 | float lumaSE = dot(STAA_Tex2D(ReShade::BackBuffer, texcoord + diagstep).rgb, ref); 559 | float lumaNE = dot(STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(diagstep.x, -diagstep.y)).rgb, ref); 560 | float lumaSW = dot(STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(-diagstep.x, diagstep.y)).rgb, ref); 561 | float4 diagdelta = abs(lumaM - float4(lumaNW, lumaSE, lumaNE, lumaSW)); 562 | float2 weightsDI = float2(diagdelta.w + diagdelta.z, diagdelta.x + diagdelta.y); 563 | 564 | // pattern 565 | // x * z 566 | // * * * 567 | // w * y 568 | 569 | float4 crosscheck = max(crossdelta, diagdelta); 570 | float2 stepcheck = max(crosscheck.xy, crosscheck.zw); 571 | float range = max(stepcheck.x, stepcheck.y); 572 | 573 | if (range < EdgeThreshold) return original; 574 | 575 | bool diagSpan = max(weightsDI.x, weightsDI.y) * float(bool(lxor(weightsDI.x, weightsDI.y))) > max(weightsHV.x, weightsHV.y); 576 | bool inverseDiag = diagSpan && (weightsDI.y > weightsDI.x); 577 | bool horzSpan = weightsHV.x > weightsHV.y; 578 | 579 | float2 lumaNP = float2(lumaN, lumaS); 580 | STAAMovc(!horzSpan.xx, lumaNP, float2(lumaW, lumaE)); 581 | STAAMovc(diagSpan.xx, lumaNP, float2(lumaNW, lumaSE)); 582 | STAAMovc((diagSpan && inverseDiag).xx, lumaNP, float2(lumaSW, lumaNE)); 583 | float gradientN = abs(lumaNP.x - lumaM); 584 | float gradientP = abs(lumaNP.y - lumaM); 585 | float lumaNN = lumaNP.x + lumaM; 586 | if (gradientN >= gradientP && !diagSpan) lengthSign = -lengthSign; 587 | if (diagSpan && inverseDiag) lengthSign.y = -lengthSign.y; 588 | if (gradientP > gradientN) lumaNN = lumaNP.y + lumaM; 589 | float gradientScaled = max(gradientN, gradientP) * 0.25; 590 | bool lumaMLTZero = mad(0.5, -lumaNN, lumaM) < 0.0; 591 | 592 | float2 posB = texcoord; 593 | float texelsize = clamp(2. * (0.5 - JitterOffset), 0.25, 1.0); 594 | float2 offNP = float2(0.0, BUFFER_RCP_HEIGHT * texelsize); 595 | STAAMovc(bool(horzSpan).xx, offNP, float2(BUFFER_RCP_WIDTH * texelsize, 0.0)); 596 | STAAMovc(bool(diagSpan).xx, offNP, float2(BUFFER_RCP_WIDTH * texelsize, BUFFER_RCP_HEIGHT * texelsize)); 597 | if (diagSpan && inverseDiag) offNP.y = -offNP.y; 598 | 599 | STAAMovc(bool2(!horzSpan || diagSpan, horzSpan || diagSpan), posB, float2(posB.x + lengthSign.x * 0.333333, posB.y + lengthSign.y * 0.333333)); 600 | 601 | float2 posN = posB - offNP; 602 | float2 posP = posB + offNP; 603 | float lumaEndN = dot(STAA_Tex2D(ReShade::BackBuffer, posN).rgb, ref); 604 | float lumaEndP = dot(STAA_Tex2D(ReShade::BackBuffer, posP).rgb, ref); 605 | lumaNN *= 0.5; 606 | lumaEndN -= lumaNN; 607 | lumaEndP -= lumaNN; 608 | bool doneN = abs(lumaEndN) >= gradientScaled; 609 | bool doneP = abs(lumaEndP) >= gradientScaled; 610 | 611 | uint iterations = 0; 612 | uint maxiterations = round(8. / texelsize); 613 | [loop] while (iterations < maxiterations) 614 | { 615 | if (doneN && doneP) break; 616 | if (!doneN) 617 | { 618 | posN -= offNP; 619 | lumaEndN = dot(STAA_Tex2D(ReShade::BackBuffer, posN).rgb, ref); 620 | lumaEndN -= lumaNN; 621 | doneN = abs(lumaEndN) >= gradientScaled; 622 | } 623 | if (!doneP) 624 | { 625 | posP += offNP; 626 | lumaEndP = dot(STAA_Tex2D(ReShade::BackBuffer, posP).rgb, ref); 627 | lumaEndP -= lumaNN; 628 | doneP = abs(lumaEndP) >= gradientScaled; 629 | } 630 | iterations++; 631 | } 632 | 633 | float2 dstNP = float2(texcoord.y - posN.y, posP.y - texcoord.y); 634 | STAAMovc(bool(horzSpan).xx, dstNP, float2(texcoord.x - posN.x, posP.x - texcoord.x)); 635 | STAAMovc(bool(diagSpan).xx, dstNP, float2(sqrt(pow(abs(texcoord.y - posN.y), 2.0) + pow(abs(texcoord.x - posN.x), 2.0)), sqrt(pow(abs(posP.y - texcoord.y), 2.0) + pow(abs(posP.x - texcoord.x), 2.0)))); 636 | 637 | //perform span check 638 | float endluma = (dstNP.x < dstNP.y) ? lumaEndN : lumaEndP; 639 | bool goodSpan = endluma < 0.0 != lumaMLTZero; 640 | 641 | //calculate offset from origin 642 | float pixelOffset = abs(mad(-rcp(dstNP.y + dstNP.x), min(dstNP.x, dstNP.y), 0.5)); 643 | 644 | //calculate offset weight 645 | float subpixOut = 1.0; 646 | if (!goodSpan) // bad span 647 | { 648 | subpixOut = mad(mad(2.0, lumaS + lumaE + lumaN + lumaW, lumaNW + lumaSE + lumaNE + lumaSW), 0.083333, -lumaM) * rcp(range); //ABC 649 | subpixOut = pow(saturate(mad(-2.0, subpixOut, 3.0) * (subpixOut * subpixOut)), 2.0); // DEFGH 650 | } 651 | subpixOut *= pixelOffset; 652 | 653 | //generate final sampling coordinates 654 | float2 posM = texcoord; 655 | STAAMovc(bool2(!horzSpan || diagSpan, horzSpan || diagSpan), posM, float2(posM.x + lengthSign.x * subpixOut, posM.y + lengthSign.y * subpixOut)); 656 | 657 | //fart result 658 | return STAA_Tex2D(ReShade::BackBuffer, posM).rgb; 659 | } 660 | 661 | float3 CASPS(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target 662 | { 663 | float edges = STAA_Tex2D(EdgesTex, texcoord).r; 664 | float3 e = STAA_Tex2D(ReShade::BackBuffer, texcoord).rgb; 665 | if (!edges) return e; 666 | 667 | #if STAA_MULTISAMPLE_COUNT > 3 668 | float SharpeningStrength = saturate(pow(abs(edges), 0.25)); 669 | float SharpeningContrast = saturate(sqrt(edges)); 670 | #elif STAA_MULTISAMPLE_COUNT > 2 671 | float SharpeningStrength = saturate(pow(abs(edges), 0.333333)); 672 | float SharpeningContrast = saturate(pow(abs(edges), 0.75)); 673 | #elif STAA_MULTISAMPLE_COUNT > 1 674 | float SharpeningStrength = saturate(sqrt(edges)); 675 | float SharpeningContrast = saturate(edges); 676 | #else 677 | float SharpeningStrength = saturate(edges); 678 | float SharpeningContrast = 0.0; 679 | #endif 680 | 681 | float offset = saturate(0.6 + JitterOffset); 682 | float2 bstep = offset * float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); 683 | float2 diagstep = (sqrt(2.)/2.) * bstep; 684 | 685 | float3 a = STAA_Tex2D(ReShade::BackBuffer, texcoord - diagstep).rgb; 686 | float3 b = STAA_Tex2D(ReShade::BackBuffer, texcoord - float2(0., bstep.y)).rgb; 687 | float3 c = STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(diagstep.x, -diagstep.y)).rgb; 688 | float3 d = STAA_Tex2D(ReShade::BackBuffer, texcoord - float2(bstep.x, 0.)).rgb; 689 | float3 g = STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(-diagstep.x, diagstep.y)).rgb; 690 | float3 f = STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(bstep.x, 0.)).rgb; 691 | float3 h = STAA_Tex2D(ReShade::BackBuffer, texcoord + float2(0., bstep.y)).rgb; 692 | float3 i = STAA_Tex2D(ReShade::BackBuffer, texcoord + diagstep).rgb; 693 | 694 | float3 mnRGB = min(min(min(d, e), min(f, b)), h); 695 | float3 mnRGB2 = min(mnRGB, min(min(a, c), min(g, i))); 696 | mnRGB += mnRGB2; 697 | 698 | float3 mxRGB = max(max(max(d, e), max(f, b)), h); 699 | float3 mxRGB2 = max(mxRGB, max(max(a, c), max(g, i))); 700 | mxRGB += mxRGB2; 701 | 702 | float3 rcpMRGB = rcp(mxRGB); 703 | float3 ampRGB = saturate(min(mnRGB, 2.0 - mxRGB) * rcpMRGB); 704 | 705 | ampRGB = rsqrt(ampRGB); 706 | 707 | float peak = -3.0 * SharpeningContrast + 8.0; 708 | float3 wRGB = -rcp(ampRGB * peak); 709 | 710 | float3 rcpWeightRGB = rcp(4.0 * wRGB + 1.0); 711 | 712 | float3 window = (b + d) + (f + h); 713 | float3 outColor = saturate((window * wRGB + e) * rcpWeightRGB); 714 | 715 | return lerp(e, outColor, SharpeningStrength); 716 | } 717 | 718 | /*****************************************************************************************************************************************/ 719 | /************************************************************* SHADER CODE END ***********************************************************/ 720 | /*****************************************************************************************************************************************/ 721 | 722 | // pass ordering: 723 | // frame start 724 | // relevant pre-processing here (single pass QXAA to pre-smooth) 725 | // Generate jitter of current buffer to textures 726 | // buffer blending pass 727 | // transfer this frame's jitters to n-1 textures 728 | // relevant post-processing here (sharpening) 729 | // frame end 730 | 731 | technique STAA 732 | { 733 | pass EdgeDetection 734 | { 735 | VertexShader = PostProcessVS; 736 | PixelShader = EdgeDetectionPS; 737 | RenderTarget = StaaEdgesTex; 738 | ClearRenderTargets = true; 739 | } 740 | pass QXAA 741 | { 742 | VertexShader = PostProcessVS; 743 | PixelShader = QXAAPS; 744 | } 745 | pass EdgeDetection 746 | { 747 | VertexShader = PostProcessVS; 748 | PixelShader = EdgeDetectionPS; 749 | RenderTarget = StaaEdgesTex; 750 | ClearRenderTargets = true; 751 | } 752 | pass FreshJitter 753 | { 754 | VertexShader = PostProcessVS; 755 | PixelShader = GenerateBufferJitterPS; 756 | RenderTarget = StaaJitterTex0; 757 | ClearRenderTargets = true; 758 | } 759 | pass TemporalBlending 760 | { 761 | VertexShader = PostProcessVS; 762 | PixelShader = TemporalBlendingPS; 763 | } 764 | pass FrameTransfer 765 | { 766 | VertexShader = PostProcessVS; 767 | PixelShader = TransferJitterTexPS; 768 | RenderTarget = StaaJitterTex1; 769 | ClearRenderTargets = true; 770 | } 771 | #if STAA_MULTISAMPLE_COUNT > 1 772 | pass EdgeDetection 773 | { 774 | VertexShader = PostProcessVS; 775 | PixelShader = EdgeDetectionPS; 776 | RenderTarget = StaaEdgesTex; 777 | ClearRenderTargets = true; 778 | } 779 | pass FreshJitterTwo 780 | { 781 | VertexShader = PostProcessVS; 782 | PixelShader = GenerateBufferJitterPS; 783 | RenderTarget = StaaJitterTex2; 784 | ClearRenderTargets = true; 785 | } 786 | pass TemporalBlendingTwo 787 | { 788 | VertexShader = PostProcessVS; 789 | PixelShader = TemporalBlendingTwoPS; 790 | } 791 | pass FrameTransferTwo 792 | { 793 | VertexShader = PostProcessVS; 794 | PixelShader = TransferJitterTexTwoPS; 795 | RenderTarget = StaaJitterTex3; 796 | ClearRenderTargets = true; 797 | } 798 | #endif 799 | #if STAA_MULTISAMPLE_COUNT > 2 800 | pass EdgeDetection 801 | { 802 | VertexShader = PostProcessVS; 803 | PixelShader = EdgeDetectionPS; 804 | RenderTarget = StaaEdgesTex; 805 | ClearRenderTargets = true; 806 | } 807 | pass FreshJitterThree 808 | { 809 | VertexShader = PostProcessVS; 810 | PixelShader = GenerateBufferJitterPS; 811 | RenderTarget = StaaJitterTex4; 812 | ClearRenderTargets = true; 813 | } 814 | pass TemporalBlendingThree 815 | { 816 | VertexShader = PostProcessVS; 817 | PixelShader = TemporalBlendingThreePS; 818 | } 819 | pass FrameTransferThree 820 | { 821 | VertexShader = PostProcessVS; 822 | PixelShader = TransferJitterTexThreePS; 823 | RenderTarget = StaaJitterTex5; 824 | ClearRenderTargets = true; 825 | } 826 | #endif 827 | #if STAA_MULTISAMPLE_COUNT > 3 828 | pass EdgeDetection 829 | { 830 | VertexShader = PostProcessVS; 831 | PixelShader = EdgeDetectionPS; 832 | RenderTarget = StaaEdgesTex; 833 | ClearRenderTargets = true; 834 | } 835 | pass FreshJitterFour 836 | { 837 | VertexShader = PostProcessVS; 838 | PixelShader = GenerateBufferJitterPS; 839 | RenderTarget = StaaJitterTex6; 840 | ClearRenderTargets = true; 841 | } 842 | pass TemporalBlendingFour 843 | { 844 | VertexShader = PostProcessVS; 845 | PixelShader = TemporalBlendingFourPS; 846 | } 847 | pass FrameTransferFour 848 | { 849 | VertexShader = PostProcessVS; 850 | PixelShader = TransferJitterTexFourPS; 851 | RenderTarget = StaaJitterTex7; 852 | ClearRenderTargets = true; 853 | } 854 | #endif 855 | pass EdgeDetection 856 | { 857 | VertexShader = PostProcessVS; 858 | PixelShader = EdgeDetectionPS; 859 | RenderTarget = StaaEdgesTex; 860 | ClearRenderTargets = true; 861 | } 862 | pass Sharpening 863 | { 864 | VertexShader = PostProcessVS; 865 | PixelShader = CASPS; 866 | } 867 | } 868 | -------------------------------------------------------------------------------- /Shaders/SmartBrightnessBooster.fx: -------------------------------------------------------------------------------- 1 | /* Smart Brightness Booster 2 | * 3 | * by lordbean 4 | * 5 | * (c) 2022 Derek Brush aka lordbean 6 | * derekbrush@gmail.com 7 | */ 8 | 9 | /** 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * this software and associated documentation files (the "Software"), to deal in 12 | * the Software without restriction, including without limitation the rights to 13 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 14 | * of the Software, and to permit persons to whom the Software is furnished to 15 | * do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. As clarification, there 19 | * is no requirement that the copyright notice and permission be included in 20 | * binary distributions of the Software. 21 | **/ 22 | 23 | /*------------------------------------------------------------------------------ 24 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 | * SOFTWARE. 31 | *-------------------------------------------------------------------------------*/ 32 | 33 | 34 | /*****************************************************************************************************************************************/ 35 | /*********************************************************** UI SETUP START **************************************************************/ 36 | /*****************************************************************************************************************************************/ 37 | 38 | #include "ReShadeUI.fxh" 39 | 40 | uniform int BrightnessIntro < 41 | ui_spacing = 3; 42 | ui_type = "radio"; 43 | ui_label = "Version: 1.1.282"; 44 | ui_text = "--------------------------------------------------------------------------------\n" 45 | " Smart Brightness Booster, a shader by lordbean\n" 46 | " https://github.com/lordbean-git/reshade-shaders/\n" 47 | "--------------------------------------------------------------------------------\n\n" 48 | "Logarithmically adjusts the brightness of the scene, then normalizes the\n" 49 | "contrast ratio by computing the delta in the 'black' signal floor. Can also\n" 50 | "optionally adjust the vibrance and/or saturation of the scene.\n\n" 51 | 52 | "Note: This shader is only designed for SDR color format. It will not produce\n" 53 | "useful output in any HDR mode.\n\n" 54 | 55 | "--------------------------------------------------------------------------------"; 56 | ui_category = "About"; 57 | ui_category_closed = true; 58 | >; 59 | 60 | uniform int BrightnessIntroEOF < 61 | ui_type = "radio"; 62 | ui_label = " "; 63 | ui_text = "\n--------------------------------------------------------------------------------"; 64 | >; 65 | 66 | uniform float BrightnessGainStrength < 67 | ui_type = "slider"; 68 | ui_min = 0.00; ui_max = 0.75; ui_step = 0.001; 69 | ui_label = "Boost"; 70 | > = 0.333333; 71 | 72 | uniform float VibranceStrength < 73 | ui_type = "slider"; 74 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 75 | ui_label = "Vibrance"; 76 | ui_spacing = 3; 77 | > = 0.5; 78 | 79 | uniform float SaturationStrength < 80 | ui_type = "slider"; 81 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 82 | ui_label = "Saturation"; 83 | > = 0.5; 84 | 85 | uniform int BrightnessOptionsEOF < 86 | ui_type = "radio"; 87 | ui_label = " "; 88 | ui_text = "\n--------------------------------------------------------------------------------"; 89 | >; 90 | 91 | /*****************************************************************************************************************************************/ 92 | /*********************************************************** UI SETUP END ****************************************************************/ 93 | /*****************************************************************************************************************************************/ 94 | 95 | /*****************************************************************************************************************************************/ 96 | /******************************************************** SUPPORT CODE START *************************************************************/ 97 | /*****************************************************************************************************************************************/ 98 | 99 | float3 RGBtoYUV(float3 input) 100 | { 101 | float3 argb = saturate(input); // value must be between [0,1] 102 | float3 yuv; 103 | 104 | yuv.x = saturate((0.299 * argb.r) + (0.587 * argb.g) + (0.114 * argb.b)); 105 | yuv.y = clamp(0.713 * (argb.r - yuv.x), -0.5, 0.5); 106 | yuv.z = clamp(0.564 * (argb.b - yuv.x), -0.5, 0.5); 107 | 108 | return yuv; 109 | } 110 | float4 RGBtoYUV(float4 input) 111 | { 112 | return float4(RGBtoYUV(input.rgb), input.a); 113 | } 114 | 115 | float3 YUVtoRGB(float3 yuv) 116 | { 117 | yuv.x = saturate(yuv.x); 118 | yuv.yz = clamp(yuv.yz, -0.5, 0.5); 119 | 120 | float3 argb; 121 | 122 | argb.r = (1.402525 * yuv.y) + yuv.x; 123 | argb.b = (1.77305 * yuv.z) + yuv.x; 124 | argb.g = (1.703578 * yuv.x) - (0.50937 * argb.r) - (0.194208 * argb.b); 125 | 126 | return argb; 127 | } 128 | float4 YUVtoRGB(float4 yuv) 129 | { 130 | return float4(YUVtoRGB(yuv.xyz), yuv.a); 131 | } 132 | 133 | 134 | float intpow(float x, float y) 135 | { 136 | float result = x; 137 | uint basepower = 1; 138 | uint raisepower = round(abs(y)); 139 | if (raisepower == 0) return 1.0; 140 | else if (raisepower == 2) return x * x; 141 | while (basepower < raisepower) 142 | { 143 | result *= x; 144 | basepower++; 145 | } 146 | return result; 147 | } 148 | float2 intpow(float2 x, float y) 149 | { 150 | float2 result = x; 151 | uint basepower = 1; 152 | uint raisepower = round(abs(y)); 153 | if (raisepower == 0) return 1.0.xx; 154 | else if (raisepower == 2) return x * x; 155 | while (basepower < raisepower) 156 | { 157 | result *= x; 158 | basepower++; 159 | } 160 | return result; 161 | } 162 | float3 intpow(float3 x, float y) 163 | { 164 | float3 result = x; 165 | uint basepower = 1; 166 | uint raisepower = round(abs(y)); 167 | if (raisepower == 0) return 1.0.xxx; 168 | else if (raisepower == 2) return x * x; 169 | while (basepower < raisepower) 170 | { 171 | result *= x; 172 | basepower++; 173 | } 174 | return result; 175 | } 176 | float4 intpow(float4 x, float y) 177 | { 178 | float4 result = x; 179 | uint basepower = 1; 180 | uint raisepower = round(abs(y)); 181 | if (raisepower == 0) return 1.0.xxxx; 182 | else if (raisepower == 2) return x * x; 183 | while (basepower < raisepower) 184 | { 185 | result *= x; 186 | basepower++; 187 | } 188 | return result; 189 | } 190 | 191 | 192 | float dotsat(float3 x) 193 | { 194 | float xl = dot(x, float3(0.2126, 0.7152, 0.0722)); 195 | return ((max(max(x.r, x.g), x.b) - min(min(x.r, x.g), x.b)) / (1.0 - (2.0 * xl - 1.0) + trunc(xl))); 196 | } 197 | float dotsat(float4 x) 198 | { 199 | return dotsat(x.rgb); 200 | } 201 | 202 | 203 | float3 AdjustSaturation(float3 input, float requestedadjustment) 204 | { 205 | float3 yuv = RGBtoYUV(input); 206 | float adjustment = 2.0 * (saturate(requestedadjustment) - 0.5); 207 | if (adjustment > 0.0) 208 | { 209 | float maxboost = rcp(max(abs(yuv.y), abs(yuv.z)) / 0.5); 210 | if (adjustment > maxboost) adjustment = maxboost; 211 | } 212 | yuv.y = yuv.y > 0.0 ? clamp(yuv.y + (adjustment * yuv.y), 0.0, 0.5) : clamp(yuv.y - (adjustment * abs(yuv.y)), -0.5, 0.0); 213 | yuv.z = yuv.z > 0.0 ? clamp(yuv.z + (adjustment * yuv.z), 0.0, 0.5) : clamp(yuv.z - (adjustment * abs(yuv.z)), -0.5, 0.0); 214 | return YUVtoRGB(yuv); 215 | } 216 | 217 | 218 | float3 AdjustVibrance(float3 pixel, float satadjust) 219 | { 220 | float3 outdot = pixel; 221 | float refsat = dotsat(pixel); 222 | float realadjustment = saturate(refsat + satadjust) - refsat; 223 | float2 highlow = float2(max(max(pixel.r, pixel.g), pixel.b), min(min(pixel.r, pixel.g), pixel.b)); 224 | float maxpositive = 1.0 - highlow.x; 225 | float maxnegative = -highlow.y; 226 | [branch] if (abs(realadjustment) > 0.0) 227 | { 228 | float mid = -1.0; 229 | float lowadjust = clamp(((highlow.y - highlow.x / 2.0) / highlow.x) * realadjustment, maxnegative, maxpositive); 230 | float highadjust = clamp(0.5 * realadjustment, maxnegative, maxpositive); 231 | if (pixel.r == highlow.x) outdot.r = pow(abs(1.0 + highadjust) * 2.0, log2(pixel.r)); 232 | else if (pixel.r == highlow.y) outdot.r = pow(abs(1.0 + lowadjust) * 2.0, log2(pixel.r)); 233 | else mid = pixel.r; 234 | if (pixel.g == highlow.x) outdot.g = pow(abs(1.0 + highadjust) * 2.0, log2(pixel.g)); 235 | else if (pixel.g == highlow.y) outdot.g = pow(abs(1.0 + lowadjust) * 2.0, log2(pixel.g)); 236 | else mid = pixel.g; 237 | if (pixel.b == highlow.x) outdot.b = pow(abs(1.0 + highadjust) * 2.0, log2(pixel.b)); 238 | else if (pixel.b == highlow.y) outdot.b = pow(abs(1.0 + lowadjust) * 2.0, log2(pixel.b)); 239 | else mid = pixel.b; 240 | if (mid > 0.0) 241 | { 242 | float midadjust = clamp(((mid - highlow.x / 2.0) / highlow.x) * realadjustment, maxnegative, maxpositive); 243 | if (pixel.r == mid) outdot.r = pow(abs(1.0 + midadjust) * 2.0, log2(pixel.r)); 244 | else if (pixel.g == mid) outdot.g = pow(abs(1.0 + midadjust) * 2.0, log2(pixel.g)); 245 | else if (pixel.b == mid) outdot.b = pow(abs(1.0 + midadjust) * 2.0, log2(pixel.b)); 246 | } 247 | } 248 | 249 | return outdot; 250 | } 251 | 252 | /***************************************************************************************************************************************/ 253 | /******************************************************** SUPPORT CODE END *************************************************************/ 254 | /***************************************************************************************************************************************/ 255 | 256 | /***************************************************************************************************************************************/ 257 | /*********************************************************** SHADER SETUP START ********************************************************/ 258 | /***************************************************************************************************************************************/ 259 | 260 | #include "ReShade.fxh" 261 | 262 | /***************************************************************************************************************************************/ 263 | /********************************************************** SHADER SETUP END ***********************************************************/ 264 | /***************************************************************************************************************************************/ 265 | 266 | /***************************************************************************************************************************************/ 267 | /********************************************************* PIXEL SHADER CODE START *****************************************************/ 268 | /***************************************************************************************************************************************/ 269 | 270 | float3 BrightnessBoosterPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 271 | { 272 | float3 pixel = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy).rgb; 273 | float3 outdot = pixel; 274 | if (BrightnessGainStrength > 0.0) 275 | { 276 | float presaturation = dotsat(outdot); 277 | float preluma = dot(outdot, float3(0.2126, 0.7152, 0.0722)); 278 | float colorgain = 2.0 - log2(BrightnessGainStrength + 1.0); 279 | float channelfloor = rcp(intpow(2, BUFFER_COLOR_BIT_DEPTH)); 280 | outdot = log2(clamp(outdot, channelfloor, 1.0 - channelfloor)); 281 | outdot = pow(abs(colorgain), outdot); 282 | channelfloor = pow(abs(colorgain), log2(channelfloor)); 283 | float contrastgain = log(rcp(dot(outdot, float3(0.2126, 0.7152, 0.0722)) - channelfloor)) * pow(2.718282, (1.0 + channelfloor) * 2.718282) * BrightnessGainStrength * BrightnessGainStrength; 284 | outdot = pow(abs(2.0 + contrastgain) * 5.0, log10(outdot)); 285 | float lumadelta = dot(outdot, float3(0.2126, 0.7152, 0.0722)) - preluma; 286 | outdot = RGBtoYUV(outdot); 287 | outdot.x = saturate(outdot.x - lumadelta * channelfloor); 288 | outdot = YUVtoRGB(outdot); 289 | float newsat = dotsat(outdot); 290 | float satadjust = abs(((newsat - presaturation) / 2.0) * (1.0 + BrightnessGainStrength)); // compute difference in before/after saturation 291 | if (satadjust != 0.0) outdot = AdjustSaturation(outdot, 0.5 + satadjust); 292 | } 293 | if (VibranceStrength != 0.5) 294 | { 295 | outdot = AdjustVibrance(outdot, -(VibranceStrength - 0.5)); 296 | } 297 | if (SaturationStrength != 0.5) 298 | { 299 | outdot = AdjustSaturation(outdot, SaturationStrength); 300 | } 301 | 302 | if (!any(outdot - pixel)) discard; 303 | else return outdot; 304 | } 305 | 306 | /***************************************************************************************************************************************/ 307 | /********************************************************** PIXEL SHADER CODE END ******************************************************/ 308 | /***************************************************************************************************************************************/ 309 | 310 | technique SmartBrightnessBooster < 311 | ui_label = "Smart Brightness Booster"; 312 | ui_tooltip = "Increases the brightness and normalizes contrast ratio\n" 313 | "to preserve detail. Intended as a quick fix for dark\n" 314 | "games or monitors."; 315 | > 316 | { 317 | pass OptionalEffects 318 | { 319 | VertexShader = PostProcessVS; 320 | PixelShader = BrightnessBoosterPS; 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /Shaders/TSMAA2.fx: -------------------------------------------------------------------------------- 1 | /* TSMAAv2 for ReShade 3.1.1+ 2 | * 3 | * (Temporal Subpixel Morphological Anti-Aliasing) 4 | * 5 | * 6 | * Uses previous-frame compositing to enhance SMAA effect 7 | * 8 | * with customizations designed to maximize edge detection and 9 | * 10 | * minimize blurring 11 | * 12 | * by lordbean 13 | * 14 | */ 15 | 16 | // This shader includes code adapted from: 17 | 18 | /** SUBPIXEL MORPHOLOGICAL ANTI-ALIASING (SMAA) 19 | * Copyright (C) 2013 Jorge Jimenez (jorge@iryoku.com) 20 | * Copyright (C) 2013 Jose I. Echevarria (joseignacioechevarria@gmail.com) 21 | * Copyright (C) 2013 Belen Masia (bmasia@unizar.es) 22 | * Copyright (C) 2013 Fernando Navarro (fernandn@microsoft.com) 23 | * Copyright (C) 2013 Diego Gutierrez (diegog@unizar.es) 24 | **/ 25 | 26 | // All original code not attributed to the above authors is copyright (c) Derek Brush aka "lordbean" (derekbrush@gmail.com) 27 | 28 | /** Permission is hereby granted, free of charge, to any person obtaining a copy 29 | * this software and associated documentation files (the "Software"), to deal in 30 | * the Software without restriction, including without limitation the rights to 31 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 32 | * of the Software, and to permit persons to whom the Software is furnished to 33 | * do so, subject to the following conditions: 34 | * 35 | * The above copyright notice and this permission notice shall be included in 36 | * all copies or substantial portions of the Software. As clarification, there 37 | * is no requirement that the copyright notice and permission be included in 38 | * binary distributions of the Software. 39 | **/ 40 | 41 | /*------------------------------------------------------------------------------ 42 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 48 | * SOFTWARE. 49 | *-------------------------------------------------------------------------------*/ 50 | 51 | 52 | /*****************************************************************************************************************************************/ 53 | /*********************************************************** UI SETUP START **************************************************************/ 54 | /*****************************************************************************************************************************************/ 55 | 56 | #include "ReShadeUI.fxh" 57 | 58 | /////////////////////////////////////////////////////// CONFIGURABLE TOGGLES ////////////////////////////////////////////////////////////// 59 | 60 | #ifndef TSM_ENABLE_DEBUG_PASS 61 | #define TSM_ENABLE_DEBUG_PASS 0 62 | #endif 63 | #if TSM_ENABLE_DEBUG_PASS > 1 || TSM_ENABLE_DEBUG_PASS < 0 64 | #undef TSM_ENABLE_DEBUG_PASS 65 | #define TSM_ENABLE_DEBUG_PASS 0 66 | #endif 67 | 68 | /////////////////////////////////////////////////////// GLOBAL SETUP OPTIONS ////////////////////////////////////////////////////////////// 69 | 70 | uniform int TSMAAintroduction < 71 | ui_spacing = 3; 72 | ui_type = "radio"; 73 | ui_label = "Version: 1.0\n\n"; 74 | ui_text = "--------------------------------------------------------------------------------\n" 75 | "Temporal Subpixel Morphological Anti-Aliasing, a shader by lordbean\n" 76 | "https://github.com/lordbean-git/reshade-shaders/\n" 77 | "--------------------------------------------------------------------------------" 78 | ""; 79 | ui_tooltip = "Experimental shader. YMMV."; 80 | ui_category = "About"; 81 | ui_category_closed = true; 82 | >; 83 | 84 | #if TSM_ENABLE_DEBUG_PASS 85 | /* 86 | uniform float DV1 < 87 | ui_type = "slider"; 88 | ui_category = "Debug"; 89 | ui_category_closed = true; 90 | ui_spacing = 3; 91 | ui_label = "Debug Value 1"; 92 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 93 | > = 0.5; 94 | 95 | uniform float DV2 < 96 | ui_type = "slider"; 97 | ui_category = "Debug"; 98 | ui_category_closed = true; 99 | ui_label = "Debug Value 2"; 100 | ui_min = 0.0; ui_max = 1.0; ui_step = 0.001; 101 | > = 0.5; 102 | */ 103 | uniform uint DebugMode < 104 | ui_type = "radio"; 105 | ui_category = "Debug"; 106 | ui_category_closed = true; 107 | ui_spacing = 3; 108 | ui_label = " \n\n"; 109 | ui_text = "Debug Mode:"; 110 | ui_items = "Off\n\n\0Detected Edges\0SMAA Blend Weights\n\n\0Temporal Composite Image\0\n\n"; 111 | > = 0; 112 | #endif 113 | 114 | uniform int AboutEOF < 115 | ui_type = "radio"; 116 | ui_label = " "; 117 | ui_text = "\n--------------------------------------------------------------------------------"; 118 | >; 119 | 120 | /*-------------------------------------------------------------------------------------------------*/ 121 | 122 | uniform float EdgeThreshold < 123 | ui_type = "slider"; 124 | ui_min = 0.02; ui_max = 1.0; 125 | ui_spacing = 3; 126 | ui_label = "Edge Detection Threshold"; 127 | ui_tooltip = "Local contrast required to be considered an edge.\n\n" 128 | "Recommended range: [0.05..0.125]"; 129 | ui_category = "SMAA"; 130 | ui_category_closed = true; 131 | > = 0.05; 132 | 133 | uniform float LowLumaThreshold < 134 | ui_type = "slider"; 135 | ui_min = 0.0; ui_max = 0.5; ui_step = 0.001; 136 | ui_label = "Low Luma Threshold"; 137 | ui_tooltip = "Luma level below which dynamic thresholding activates\n\n" 138 | "Recommended range: [0.05..0.2]"; 139 | ui_category = "SMAA"; 140 | ui_category_closed = true; 141 | > = 0.1; 142 | 143 | uniform float DynamicThreshold < 144 | ui_type = "slider"; 145 | ui_min = 0; ui_max = 100; ui_step = 1; 146 | ui_label = "% Dynamic Range"; 147 | ui_tooltip = "Maximum reduction of edge threshold (% base threshold)\n" 148 | "permitted when detecting low-brightness edges.\n" 149 | "Lower = faster, might miss low-luma edges\n" 150 | "Higher = slower, catches more edges in dark scenes\n\n" 151 | "Recommended range: [50..100]"; 152 | ui_category = "SMAA"; 153 | ui_category_closed = true; 154 | > = 60; 155 | 156 | uniform float ScanRadius < 157 | ui_type = "slider"; 158 | ui_min = 12; ui_max = 112; ui_step = 1; 159 | ui_label = "Scan Distance"; 160 | ui_tooltip = "Maximum radius from center dot\nto scan for aliasing.\n\n" 161 | "Recommended range: [64..112]"; 162 | ui_category = "SMAA"; 163 | ui_category_closed = true; 164 | > = 112; 165 | 166 | uniform bool DCBlending < 167 | ui_spacing = 3; 168 | ui_label = "Dual-Cardinal Blending"; 169 | ui_tooltip = "Whether to perform blending using both axes\n" 170 | "or just the dominant one when both horizontal\n" 171 | "and vertical edges are detected near the pixel.\n" 172 | "Normal SMAA uses the dominant one. The dual-\n" 173 | "cardinal system reduces the blending strength\n" 174 | "of diagonal edges slightly, but significantly\n" 175 | "increases temporal stability of the output.\n\n" 176 | "Recommended setting: enabled"; 177 | ui_category = "SMAA"; 178 | ui_category_closed = true; 179 | > = true; 180 | 181 | uniform bool CornerDetection < 182 | ui_label = "Perform Corner Detection"; 183 | ui_tooltip = "Indicates whether SMAA will detect patterns\n" 184 | "that look like corners in the edge data.\n" 185 | "Disabling corner detection is equivalent\n" 186 | "to setting corner rounding to 100%.\n\n" 187 | "Recommended setting: enabled"; 188 | ui_category = "SMAA"; 189 | ui_category_closed = true; 190 | > = true; 191 | 192 | uniform float CornerRounding < 193 | ui_spacing = 3; 194 | ui_type = "slider"; 195 | ui_min = 0; ui_max = 100; ui_step = 1; 196 | ui_label = "% Corner Rounding\n\n"; 197 | ui_tooltip = "Affects the amount of blending performed when SMAA\n" 198 | "detects corner patterns. Only works when corner\n" 199 | "detection is enabled. Be careful with this value\n" 200 | "as it can produce a large amount of blur in some\n" 201 | "games, particularly at low resolutions.\n\n" 202 | "Recommended range: [0..50]"; 203 | ui_category = "SMAA"; 204 | ui_category_closed = true; 205 | > = 50; 206 | 207 | /*-------------------------------------------------------------------------------------------------*/ 208 | 209 | uniform bool TemporalCompositing < 210 | ui_spacing = 3; 211 | ui_label = "Enable Temporal Compositing"; 212 | ui_tooltip = "Enable/Disable previous-frame blending"; 213 | ui_category = "Temporal Blending"; 214 | ui_category_closed = true; 215 | > = true; 216 | 217 | uniform float TemporalBlending < 218 | ui_spacing = 3; 219 | ui_label = "Previous Frame Interpolation\n\n"; 220 | ui_type = "slider"; 221 | ui_min = 0.1; ui_max = 0.5; ui_step = 0.001; 222 | ui_category = "Temporal Blending"; 223 | ui_category_closed = true; 224 | > = 0.3; 225 | 226 | /*-------------------------------------------------------------------------------------------------*/ 227 | 228 | #define __LUMA_REF float3(0.2126, 0.7152, 0.0722) 229 | #define __SCANRADIUS round(ScanRadius) 230 | #define __SCANRADIUSDIAG round(clamp(__SCANRADIUS * 0.2, 2.0, 20.0)) 231 | #define __BUFFERSIZE float4(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT, BUFFER_WIDTH, BUFFER_HEIGHT) 232 | #define __AREATEX_RANGE 16. 233 | #define __AREATEX_TEXEL rcp(float2(160., 560.)) 234 | #define __AREATEX_SUBTEXEL 0.142857 235 | #define __SEARCHTEX_SIZE float2(66.0, 33.0) 236 | #define __SEARCHTEX_SIZE_PACKED float2(64.0, 16.0) 237 | #define __8BIT_BY_7BIT 2.007874 238 | #define __EDGETHRESHOLD clamp(EdgeThreshold, 0.02, 1.00) 239 | #define __EDGE_FLOOR 0.008 240 | #define __THRESHOLD_REDUCTION saturate(DynamicThreshold * 0.01) 241 | #define __CORNER_ROUNDING saturate(CornerRounding * 0.01) 242 | 243 | #define TSM_Tex2D(tex, coord) tex2Dlod(tex, (coord).xyxy) 244 | 245 | /*****************************************************************************************************************************************/ 246 | /*********************************************************** UI SETUP END ****************************************************************/ 247 | /*****************************************************************************************************************************************/ 248 | 249 | /*****************************************************************************************************************************************/ 250 | /******************************************************** SUPPORT CODE START *************************************************************/ 251 | /*****************************************************************************************************************************************/ 252 | 253 | //////////////////////////////////////////////////////// HELPER FUNCTIONS //////////////////////////////////////////////////////////////// 254 | 255 | float dotsat(float3 x) 256 | { 257 | float xmax = max(max(x.r, x.g), x.b); 258 | float xmin = min(min(x.r, x.g), x.b); 259 | if (!xmax) return 0.0; 260 | float xmid = (x.r + x.g + x.b) - (xmax + xmin); 261 | float xbrightness = (xmax + xmid) * 0.5; 262 | return (xmax - xmin) * xbrightness; 263 | } 264 | float dotsat(float4 x) 265 | { 266 | return dotsat(x.rgb); 267 | } 268 | 269 | // color delta calculator 270 | float chromadelta(float3 pixel1, float3 pixel2) 271 | { 272 | float3 delta = abs(pixel1 - pixel2); 273 | return max(max(delta.r, delta.g), delta.b); 274 | } 275 | float chromadelta(float4 pixel1, float4 pixel2) 276 | { 277 | return chromadelta(pixel1.rgb, pixel2.rgb); 278 | } 279 | 280 | ///////////////////////////////////////////////////// SMAA HELPER FUNCTIONS /////////////////////////////////////////////////////////////// 281 | 282 | void TSMmovc(bool2 cond, inout float2 variable, float2 value) 283 | { 284 | [flatten] if (cond.x) variable.x = value.x; 285 | [flatten] if (cond.y) variable.y = value.y; 286 | } 287 | void TSMmovc(bool4 cond, inout float4 variable, float4 value) 288 | { 289 | TSMmovc(cond.xy, variable.xy, value.xy); 290 | TSMmovc(cond.zw, variable.zw, value.zw); 291 | } 292 | 293 | float2 TSMDecodeSubSample(float2 e) 294 | { 295 | e.r = e.r * abs(5.0 * e.r - 3.75); 296 | return round(e); 297 | } 298 | float4 TSMDecodeSubSample(float4 e) 299 | { 300 | e.rb = e.rb * abs(5.0 * e.rb - 3.75); 301 | return round(e); 302 | } 303 | 304 | float2 TSMScanD(sampler2D TSMedgeTEX, float2 texcoord, float2 dir, out float2 e) 305 | { 306 | float4 coord = float4(texcoord, -1.0, 1.0); 307 | float3 t = float3(__BUFFERSIZE.xy, 1.0); 308 | float range = __SCANRADIUSDIAG - 1.0; 309 | 310 | [loop] while (coord.z < range) 311 | { 312 | coord.xyz = mad(t, float3(dir, 1.0), coord.xyz); 313 | e = tex2Dlod(TSMedgeTEX, coord.xyxy).rg; 314 | coord.w = dot(e, 0.5); 315 | if (coord.w < 0.9) break; 316 | } 317 | 318 | return coord.zw; 319 | } 320 | float2 TSMScanD2(sampler2D edgesTex, float2 texcoord, float2 dir, out float2 e) 321 | { 322 | float4 coord = float4(texcoord, -1.0, 1.0); 323 | coord.x += 0.25 * __BUFFERSIZE.x; 324 | float3 t = float3(__BUFFERSIZE.xy, 1.0); 325 | float range = __SCANRADIUSDIAG - 1.0; 326 | 327 | [loop] while (coord.z < range) 328 | { 329 | coord.xyz = mad(t, float3(dir, 1.0), coord.xyz); 330 | 331 | e = tex2Dlod(edgesTex, coord.xyxy).rg; 332 | e = TSMDecodeSubSample(e); 333 | 334 | coord.w = dot(e, 0.5); 335 | if (coord.w < 0.9) break; 336 | } 337 | 338 | return coord.zw; 339 | } 340 | 341 | 342 | float2 TSMDiagArea(sampler2D TSMareaTEX, float2 dist, float2 e) 343 | { 344 | float2 texcoord = mad(float(__SCANRADIUSDIAG).xx, e, dist); 345 | 346 | texcoord = mad(__AREATEX_TEXEL, texcoord, 0.5 * __AREATEX_TEXEL); 347 | texcoord.x += 0.5; 348 | 349 | return tex2Dlod(TSMareaTEX, texcoord.xyxy).rg; 350 | } 351 | 352 | float2 TSMGetDiagWt(sampler2D TSMedgeTEX, sampler2D TSMareaTEX, float2 texcoord, float2 e) 353 | { 354 | float2 weights = 0; 355 | float2 end; 356 | float4 d; 357 | d.ywxz = float4(TSMScanD(TSMedgeTEX, texcoord, float2(1.0, -1.0), end), 0.0, 0.0); 358 | 359 | if (e.r > 0.0) 360 | { 361 | d.xz = TSMScanD(TSMedgeTEX, texcoord, float2(-1.0, 1.0), end); 362 | d.x += float(end.y > 0.9); 363 | } 364 | 365 | if ((d.x + d.y) > 2.0) 366 | { 367 | float4 coords = mad(float4(-d.x, d.x, d.y, -d.y), __BUFFERSIZE.xyxy, texcoord.xyxy); 368 | float4 c; 369 | c.x = tex2Dlodoffset(TSMedgeTEX, coords.xyxy, int2(-1, 0)).g; 370 | c.y = tex2Dlodoffset(TSMedgeTEX, coords.xyxy, int2( 0, 0)).r; 371 | c.z = tex2Dlodoffset(TSMedgeTEX, coords.zwzw, int2( 1, 0)).g; 372 | c.w = tex2Dlodoffset(TSMedgeTEX, coords.zwzw, int2( 1, -1)).r; 373 | 374 | float2 cc = mad(float(2.0).xx, c.xz, c.yw); 375 | 376 | TSMmovc(bool2(step(0.9, d.zw)), cc, 0.0); 377 | 378 | weights += TSMDiagArea(TSMareaTEX, d.xy, cc); 379 | } 380 | 381 | d.xz = TSMScanD2(TSMedgeTEX, texcoord, float2(-1.0, -1.0), end); 382 | d.yw = 0.0; 383 | 384 | if (TSM_Tex2D(TSMedgeTEX, texcoord + float2(BUFFER_RCP_WIDTH, 0)).r > 0.0) 385 | { 386 | d.yw = TSMScanD2(TSMedgeTEX, texcoord, 1.0, end); 387 | d.y += float(end.y > 0.9); 388 | } 389 | 390 | if ((d.x + d.y) > 2.0) 391 | { 392 | float4 coords = mad(float4(-d.x, -d.x, d.y, d.y), __BUFFERSIZE.xyxy, texcoord.xyxy); 393 | float4 c; 394 | c.x = tex2Dlodoffset(TSMedgeTEX, coords.xyxy, int2(-1, 0)).g; 395 | c.y = tex2Dlodoffset(TSMedgeTEX, coords.xyxy, int2( 0, -1)).r; 396 | c.zw = tex2Dlodoffset(TSMedgeTEX, coords.zwzw, int2( 1, 0)).gr; 397 | float2 cc = mad(2.0, c.xz, c.yw); 398 | 399 | TSMmovc(bool2(step(0.9, d.zw)), cc, 0.0); 400 | 401 | weights += TSMDiagArea(TSMareaTEX, d.xy, cc).gr; 402 | } 403 | 404 | return weights; 405 | } 406 | 407 | float TSMGetScanRef(sampler2D TSMsearchTEX, float2 e, float offset) 408 | { 409 | float2 scale = __SEARCHTEX_SIZE * float2(0.5, -1.0); 410 | float2 bias = __SEARCHTEX_SIZE * float2(offset, 1.0); 411 | 412 | scale += float2(-1.0, 1.0); 413 | bias += float2( 0.5, -0.5); 414 | 415 | scale *= rcp(__SEARCHTEX_SIZE_PACKED); 416 | bias *= rcp(__SEARCHTEX_SIZE_PACKED); 417 | 418 | return tex2Dlod(TSMsearchTEX, mad(scale, e, bias).xyxy).r; 419 | } 420 | 421 | float TSMScanXL(sampler2D TSMedgeTEX, sampler2D TSMsearchTEX, float2 texcoord, float end) 422 | { 423 | float2 e = float2(0.0, 1.0); 424 | 425 | [loop] while (texcoord.x > end) 426 | { 427 | e = tex2Dlod(TSMedgeTEX, texcoord.xyxy).rg; 428 | texcoord.x -= 2. * BUFFER_RCP_WIDTH; 429 | 430 | if (e.r || (e.g < 0.751)) break; 431 | } 432 | float offset = mad(-__8BIT_BY_7BIT, TSMGetScanRef(TSMsearchTEX, e, 0.0), 3.25); 433 | return mad(__BUFFERSIZE.x, offset, texcoord.x); 434 | } 435 | float TSMScanXR(sampler2D TSMedgeTEX, sampler2D TSMsearchTEX, float2 texcoord, float end) 436 | { 437 | float2 e = float2(0.0, 1.0); 438 | 439 | [loop] while (texcoord.x < end) 440 | { 441 | e = tex2Dlod(TSMedgeTEX, texcoord.xyxy).rg; 442 | texcoord.x += 2. * BUFFER_RCP_WIDTH; 443 | 444 | if (e.r || (e.g < 0.751)) break; 445 | } 446 | float offset = mad(-__8BIT_BY_7BIT, TSMGetScanRef(TSMsearchTEX, e, 0.5), 3.25); 447 | return mad(-__BUFFERSIZE.x, offset, texcoord.x); 448 | } 449 | float TSMScanYUp(sampler2D TSMedgeTEX, sampler2D TSMsearchTEX, float2 texcoord, float end) 450 | { 451 | float2 e = float2(1.0, 0.0); 452 | 453 | [loop] while (texcoord.y > end) 454 | { 455 | e = tex2Dlod(TSMedgeTEX, texcoord.xyxy).rg; 456 | texcoord.y -= 2. * BUFFER_RCP_HEIGHT; 457 | 458 | if (e.g || (e.r < 0.874)) break; 459 | } 460 | float offset = mad(-__8BIT_BY_7BIT, TSMGetScanRef(TSMsearchTEX, e.gr, 0.0), 3.25); 461 | return mad(__BUFFERSIZE.y, offset, texcoord.y); 462 | } 463 | float TSMScanYDn(sampler2D TSMedgeTEX, sampler2D TSMsearchTEX, float2 texcoord, float end) 464 | { 465 | float2 e = float2(1.0, 0.0); 466 | 467 | [loop] while (texcoord.y < end) 468 | { 469 | e = tex2Dlod(TSMedgeTEX, texcoord.xyxy).rg; 470 | texcoord.y += 2. * BUFFER_RCP_HEIGHT; 471 | 472 | if (e.g || (e.r < 0.874)) break; 473 | } 474 | float offset = mad(-__8BIT_BY_7BIT, TSMGetScanRef(TSMsearchTEX, e.gr, 0.5), 3.25); 475 | return mad(-__BUFFERSIZE.y, offset, texcoord.y); 476 | } 477 | 478 | float2 TSMGetAreaRef(sampler2D TSMareaTEX, float2 dist, float e1, float e2) 479 | { 480 | float2 texcoord = mad(__AREATEX_RANGE, 4.0 * float2(e1, e2), dist); 481 | 482 | texcoord = mad(__AREATEX_TEXEL, texcoord, 0.5 * __AREATEX_TEXEL); 483 | 484 | return tex2Dlod(TSMareaTEX, texcoord.xyxy).rg; 485 | } 486 | 487 | void TSMFindCornersX(sampler2D TSMedgeTEX, inout float2 weights, float4 texcoord, float2 d) 488 | { 489 | float2 leftRight = step(d.xy, d.yx); 490 | float2 rounding = (1.0 - __CORNER_ROUNDING) * leftRight; 491 | float2 tcs = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); 492 | 493 | float2 factor = float(1.0).xx; 494 | factor.x -= rounding.x * tex2Dlod(TSMedgeTEX, texcoord.xyxy + float4(0, tcs.y, 0, 0)).r; 495 | factor.x -= rounding.y * tex2Dlod(TSMedgeTEX, texcoord.zwzw + float4(tcs, 0, 0)).r; 496 | factor.y -= rounding.x * tex2Dlod(TSMedgeTEX, texcoord.xyxy + float4(0, -3.0 * tcs.y, 0, 0)).r; 497 | factor.y -= rounding.y * tex2Dlod(TSMedgeTEX, texcoord.zwzw + float4(tcs.x, -3.0 * tcs.y, 0, 0)).r; 498 | 499 | weights *= saturate(factor); 500 | } 501 | void TSMFindCornersY(sampler2D TSMedgeTEX, inout float2 weights, float4 texcoord, float2 d) 502 | { 503 | float2 leftRight = step(d.xy, d.yx); 504 | float2 rounding = (1.0 - __CORNER_ROUNDING) * leftRight; 505 | float2 tcs = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); 506 | 507 | float2 factor = float(1.0).xx; 508 | factor.x -= rounding.x * tex2Dlod(TSMedgeTEX, texcoord.xyxy + float4(tcs.x, 0, 0, 0)).g; 509 | factor.x -= rounding.y * tex2Dlod(TSMedgeTEX, texcoord.zwzw + float4(tcs, 0, 0)).g; 510 | factor.y -= rounding.x * tex2Dlod(TSMedgeTEX, texcoord.xyxy + float4(-3.0 * tcs.x, 0, 0, 0)).g; 511 | factor.y -= rounding.y * tex2Dlod(TSMedgeTEX, texcoord.zwzw + float4(-3.0 * tcs.x, tcs.y, 0, 0)).g; 512 | 513 | weights *= saturate(factor); 514 | } 515 | 516 | /***************************************************************************************************************************************/ 517 | /******************************************************** SUPPORT CODE END *************************************************************/ 518 | /***************************************************************************************************************************************/ 519 | 520 | /***************************************************************************************************************************************/ 521 | /******************************************************* SHADER SETUP START ************************************************************/ 522 | /***************************************************************************************************************************************/ 523 | 524 | #include "ReShade.fxh" 525 | 526 | //////////////////////////////////////////////////////////// TEXTURES /////////////////////////////////////////////////////////////////// 527 | 528 | texture TSMedgeTEX 529 | #if __RESHADE__ >= 50000 530 | < pooled = true; > 531 | #endif 532 | { 533 | Width = BUFFER_WIDTH; 534 | Height = BUFFER_HEIGHT; 535 | Format = RG16F; 536 | }; 537 | sampler TSMedges {Texture = TSMedgeTEX;}; 538 | 539 | texture TSMdataTEX 540 | #if __RESHADE__ >= 50000 541 | < pooled = true; > 542 | #endif 543 | { 544 | Width = BUFFER_WIDTH; 545 | Height = BUFFER_HEIGHT; 546 | Format = RGBA16F; 547 | }; 548 | sampler TSMdata {Texture = TSMdataTEX;}; 549 | 550 | texture TSMareaTEX < source = "AreaTex.png"; > 551 | { 552 | Width = 160; 553 | Height = 560; 554 | Format = RG8; 555 | }; 556 | sampler TSMareaREF {Texture = TSMareaTEX;}; 557 | 558 | 559 | texture TSMsearchTEX < source = "SearchTex.png"; > 560 | { 561 | Width = 64; 562 | Height = 16; 563 | Format = R8; 564 | }; 565 | sampler TSMsearchREF {Texture = TSMsearchTEX;}; 566 | 567 | #if TSM_ENABLE_DEBUG_PASS 568 | texture TSMdebugTEX 569 | { 570 | Width = BUFFER_WIDTH; 571 | Height = BUFFER_HEIGHT; 572 | Format = RGBA16F; 573 | }; 574 | sampler TSMdebug {Texture = TSMdebugTEX;}; 575 | #endif 576 | 577 | //////////////////////////////////////////////////////////// VERTEX SHADERS ///////////////////////////////////////////////////////////// 578 | 579 | void TSMEdgeScanVS(float2 texcoord, 580 | out float4 offset[3]) { 581 | offset[0] = mad(__BUFFERSIZE.xyxy, float4(-1.0, 0.0, 0.0, -1.0), texcoord.xyxy); 582 | offset[1] = mad(__BUFFERSIZE.xyxy, float4( 1.0, 0.0, 0.0, 1.0), texcoord.xyxy); 583 | offset[2] = mad(__BUFFERSIZE.xyxy, float4(-2.0, 0.0, 0.0, -2.0), texcoord.xyxy); 584 | } 585 | void TSMEdgeScanWrapVS( 586 | in uint id : SV_VertexID, 587 | out float4 position : SV_Position, 588 | out float2 texcoord : TEXCOORD0, 589 | out float4 offset[3] : TEXCOORD1) 590 | { 591 | PostProcessVS(id, position, texcoord); 592 | TSMEdgeScanVS(texcoord, offset); 593 | } 594 | 595 | void TSMBlendCalcVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD0, out float2 pixcoord : TEXCOORD1, out float4 offset[3] : TEXCOORD2) 596 | { 597 | texcoord.x = (id == 2) ? 2.0 : 0.0; 598 | texcoord.y = (id == 1) ? 2.0 : 0.0; 599 | position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); 600 | pixcoord = texcoord * __BUFFERSIZE.zw; 601 | 602 | offset[0] = mad(__BUFFERSIZE.xyxy, float4(-0.25, -0.125, 1.25, -0.125), texcoord.xyxy); 603 | offset[1] = mad(__BUFFERSIZE.xyxy, float4(-0.125, -0.25, -0.125, 1.25), texcoord.xyxy); 604 | 605 | float searchrange = __SCANRADIUS; 606 | 607 | offset[2] = mad(__BUFFERSIZE.xxyy, 608 | float2(-2.0, 2.0).xyxy * searchrange, 609 | float4(offset[0].xz, offset[1].yw)); 610 | } 611 | 612 | void TSMBlendingVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD0, out float4 offset : TEXCOORD1) 613 | { 614 | texcoord.x = (id == 2) ? 2.0 : 0.0; 615 | texcoord.y = (id == 1) ? 2.0 : 0.0; 616 | position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); 617 | offset = mad(__BUFFERSIZE.xyxy, float4( 1.0, 0.0, 0.0, 1.0), texcoord.xyxy); 618 | } 619 | 620 | /*****************************************************************************************************************************************/ 621 | /*********************************************************** SHADER SETUP END ************************************************************/ 622 | /*****************************************************************************************************************************************/ 623 | 624 | /*****************************************************************************************************************************************/ 625 | /********************************************************** SMAA SHADER CODE START *******************************************************/ 626 | /*****************************************************************************************************************************************/ 627 | 628 | float2 TSMEdgeScanPS(float4 position : SV_Position, float2 texcoord : TEXCOORD0, float4 offset[3] : TEXCOORD1) : SV_Target 629 | { 630 | float3 middle = TSM_Tex2D(ReShade::BackBuffer, texcoord).rgb; 631 | float3 ref = __LUMA_REF; 632 | 633 | float L = dot(middle, ref); 634 | float3 top = TSM_Tex2D(ReShade::BackBuffer, offset[0].zw).rgb; 635 | float Dtop = chromadelta(middle, top); 636 | float Ltop = dot(top, ref); 637 | float3 left = TSM_Tex2D(ReShade::BackBuffer, offset[0].xy).rgb; 638 | float Dleft = chromadelta(middle, left); 639 | float Lleft = dot(left, ref); 640 | float Lavg = (L + Ltop + Lleft) * 0.333333; 641 | 642 | float rangemult = LowLumaThreshold ? saturate(1.0 - clamp(Lavg, 0.0, LowLumaThreshold) * rcp(LowLumaThreshold)) : 0.0; 643 | 644 | float edgethreshold = __EDGETHRESHOLD; 645 | 646 | edgethreshold = clamp(mad(rangemult, -(__THRESHOLD_REDUCTION * edgethreshold), edgethreshold), __EDGE_FLOOR, 1.00); 647 | 648 | float2 edges = step(edgethreshold, float2(Dleft, Dtop)); 649 | if (!any(edges)) return 0.0; 650 | 651 | float3 right = TSM_Tex2D(ReShade::BackBuffer, offset[1].xy).rgb; 652 | float Dright = chromadelta(middle, right); 653 | float3 bottom = TSM_Tex2D(ReShade::BackBuffer, offset[1].zw).rgb; 654 | float Dbottom = chromadelta(middle, bottom); 655 | 656 | float2 maxdelta = float2(max(Dleft, Dright), max(Dtop, Dbottom)); 657 | 658 | float Dleftleft = chromadelta(left, TSM_Tex2D(ReShade::BackBuffer, offset[2].xy).rgb); 659 | float Dtoptop = chromadelta(top, TSM_Tex2D(ReShade::BackBuffer, offset[2].zw).rgb); 660 | 661 | maxdelta = max(maxdelta, float2(Dleftleft, Dtoptop)); 662 | float largestdelta = max(maxdelta.x, maxdelta.y); 663 | 664 | float3 localcontrast = (middle + left + top + right + bottom) * 0.2; 665 | float LCsat = dotsat(localcontrast); 666 | float LCL = dot(localcontrast, ref); 667 | float LCmult = length(float2(LCsat, LCL)); 668 | float contrastadaptation = 2.0 + (localcontrast.r + localcontrast.g + localcontrast.b) * LCmult; 669 | edges *= step(largestdelta, contrastadaptation * float2(Dleft, Dtop)); 670 | 671 | return edges; 672 | } 673 | 674 | float4 TSMBlendCalcPS(float4 position : SV_Position, float2 texcoord : TEXCOORD0, float2 pixcoord : TEXCOORD1, float4 offset[3] : TEXCOORD2) : SV_Target 675 | { 676 | float4 weights = 0; 677 | float2 e = TSM_Tex2D(TSMedges, texcoord).rg; 678 | 679 | [branch] if (e.g) 680 | { 681 | float2 diagweights = TSMGetDiagWt(TSMedges, TSMareaREF, texcoord, e); 682 | if (any(diagweights)) {weights.xy = diagweights; e.r = DCBlending ? e.r : 0.0;} 683 | else 684 | { 685 | float3 coords = float3(TSMScanXL(TSMedges, TSMsearchREF, offset[0].xy, offset[2].x), offset[1].y, TSMScanXR(TSMedges, TSMsearchREF, offset[0].zw, offset[2].y)); 686 | float e1 = TSM_Tex2D(TSMedges, coords.xy).r; 687 | float2 d = coords.xz; 688 | d = abs((mad(__BUFFERSIZE.zz, d, -pixcoord.xx))); 689 | float e2 = TSM_Tex2D(TSMedges, coords.zy + float2(BUFFER_RCP_WIDTH, 0)).r; 690 | weights.rg = TSMGetAreaRef(TSMareaREF, sqrt(d), e1, e2); 691 | coords.y = texcoord.y; 692 | if (CornerDetection) TSMFindCornersX(TSMedges, weights.rg, coords.xyzy, d); 693 | } 694 | } 695 | 696 | if (!e.r) return weights; 697 | 698 | float3 coords = float3(offset[0].x, TSMScanYUp(TSMedges, TSMsearchREF, offset[1].xy, offset[2].z), TSMScanYDn(TSMedges, TSMsearchREF, offset[1].zw, offset[2].w)); 699 | float e1 = TSM_Tex2D(TSMedges, coords.xy).g; 700 | float2 d = coords.yz; 701 | d = abs((mad(__BUFFERSIZE.ww, d, -pixcoord.yy))); 702 | float e2 = TSM_Tex2D(TSMedges, coords.xz + float2(0, BUFFER_RCP_HEIGHT)).g; 703 | weights.ba = TSMGetAreaRef(TSMareaREF, sqrt(d), e1, e2); 704 | coords.x = texcoord.x; 705 | if (CornerDetection) TSMFindCornersY(TSMedges, weights.ba, coords.xyxz, d); 706 | 707 | return weights; 708 | } 709 | 710 | float3 TSMNBlendingPS(float4 position : SV_Position, float2 texcoord : TEXCOORD0, float4 offset : TEXCOORD1) : SV_Target 711 | { 712 | float3 resultAA = TSM_Tex2D(ReShade::BackBuffer, texcoord).rgb; 713 | float4 m = float4(TSM_Tex2D(TSMdata, offset.xy).a, TSM_Tex2D(TSMdata, offset.zw).g, TSM_Tex2D(TSMdata, texcoord).zx); 714 | 715 | [branch] if (any(m)) 716 | { 717 | float maxweight = max(m.x + m.z, m.y + m.w); 718 | float minweight = min(m.x + m.z, m.y + m.w); 719 | float maxratio = maxweight * rcp(minweight + maxweight); 720 | float minratio = minweight * rcp(minweight + maxweight); 721 | 722 | bool horiz = (abs(m.x) + abs(m.z)) > (abs(m.y) + abs(m.w)); 723 | 724 | float4 blendingOffset = 0.0.xxxx; 725 | float2 blendingWeight; 726 | 727 | TSMmovc(bool4(horiz, !horiz, horiz, !horiz), blendingOffset, float4(m.x, m.y, m.z, m.w)); 728 | TSMmovc(bool(horiz).xx, blendingWeight, m.xz); 729 | TSMmovc(bool(!horiz).xx, blendingWeight, m.yw); 730 | blendingWeight *= rcp(dot(blendingWeight, float(1.0).xx)); 731 | float4 blendingCoord = mad(blendingOffset, float4(__BUFFERSIZE.xy, -__BUFFERSIZE.xy), texcoord.xyxy); 732 | resultAA = (DCBlending ? maxratio : 1.0) * blendingWeight.x * TSM_Tex2D(ReShade::BackBuffer, blendingCoord.xy).rgb; 733 | resultAA += (DCBlending ? maxratio : 1.0) * blendingWeight.y * TSM_Tex2D(ReShade::BackBuffer, blendingCoord.zw).rgb; 734 | 735 | 736 | [branch] if (DCBlending && minratio != 0.0) 737 | { 738 | blendingOffset = 0.0.xxxx; 739 | TSMmovc(bool4(!horiz, horiz, !horiz, horiz), blendingOffset, float4(m.x, m.y, m.z, m.w)); 740 | TSMmovc(bool(!horiz).xx, blendingWeight, m.xz); 741 | TSMmovc(bool(horiz).xx, blendingWeight, m.yw); 742 | blendingWeight *= rcp(dot(blendingWeight, float(1.0).xx)); 743 | blendingCoord = mad(blendingOffset, float4(__BUFFERSIZE.xy, -__BUFFERSIZE.xy), texcoord.xyxy); 744 | resultAA += minratio * blendingWeight.x * TSM_Tex2D(ReShade::BackBuffer, blendingCoord.xy).rgb; 745 | resultAA += minratio * blendingWeight.y * TSM_Tex2D(ReShade::BackBuffer, blendingCoord.zw).rgb; 746 | } 747 | } 748 | 749 | return resultAA; 750 | } 751 | 752 | /***************************************************************************************************************************************/ 753 | /********************************************************** SMAA SHADER CODE END *******************************************************/ 754 | /***************************************************************************************************************************************/ 755 | 756 | /***************************************************************************************************************************************/ 757 | /**************************************************** TEMPORAL COMPOSITING CODE START **************************************************/ 758 | /***************************************************************************************************************************************/ 759 | 760 | float4 TSMCompositingPS(float4 position : SV_POSITION, float2 texcoord : TEXCOORD) : SV_TARGET 761 | { 762 | float4 framecurr = tex2Dlod(ReShade::BackBuffer, texcoord.xyxy); 763 | float4 frameprev = tex2Dlod(TSMdata, texcoord.xyxy); 764 | float4 outframe = lerp(framecurr, frameprev, TemporalBlending); 765 | return (TemporalCompositing ? outframe : framecurr); 766 | } 767 | 768 | float4 TSMFramecopyPS(float4 position : SV_POSITION, float2 texcoord : TEXCOORD) : SV_TARGET 769 | { 770 | return tex2Dlod(ReShade::BackBuffer, texcoord.xyxy); 771 | } 772 | 773 | /***************************************************************************************************************************************/ 774 | /**************************************************** TEMPORAL COMPOSITING CODE -END- **************************************************/ 775 | /***************************************************************************************************************************************/ 776 | 777 | #if TSM_ENABLE_DEBUG_PASS 778 | float4 TSMDebugCopyPS(float4 position : SV_POSITION, float2 texcoord : TEXCOORD) : SV_TARGET 779 | { 780 | if (DebugMode == 2) return tex2Dlod(TSMdata, texcoord.xyxy); 781 | if (DebugMode == 3) return tex2Dlod(ReShade::BackBuffer, texcoord.xyxy); 782 | return 0.0; 783 | } 784 | 785 | float4 TSMDebugDisplayPS(float4 position : SV_POSITION, float2 texcoord : TEXCOORD) : SV_TARGET 786 | { 787 | if (DebugMode == 0) return tex2Dlod(ReShade::BackBuffer, texcoord.xyxy); 788 | if (DebugMode == 1) return tex2Dlod(TSMedges, texcoord.xyxy); 789 | return tex2Dlod(TSMdebug, texcoord.xyxy); 790 | } 791 | #endif 792 | 793 | technique TSMAA2 794 | { 795 | pass TemporalCompositing 796 | { 797 | VertexShader = PostProcessVS; 798 | PixelShader = TSMCompositingPS; 799 | } 800 | 801 | pass EdgeScan 802 | { 803 | VertexShader = TSMEdgeScanWrapVS; 804 | PixelShader = TSMEdgeScanPS; 805 | RenderTarget = TSMedgeTEX; 806 | ClearRenderTargets = true; 807 | } 808 | 809 | pass WeightCalculation 810 | { 811 | VertexShader = TSMBlendCalcVS; 812 | PixelShader = TSMBlendCalcPS; 813 | RenderTarget = TSMdataTEX; 814 | ClearRenderTargets = true; 815 | } 816 | 817 | #if TSM_ENABLE_DEBUG_PASS 818 | pass SaveDebugInfo 819 | { 820 | VertexShader = PostProcessVS; 821 | PixelShader = TSMDebugCopyPS; 822 | RenderTarget = TSMdebugTEX; 823 | ClearRenderTargets = true; 824 | } 825 | #endif 826 | 827 | pass NeighborhoodBlending 828 | { 829 | VertexShader = TSMBlendingVS; 830 | PixelShader = TSMNBlendingPS; 831 | } 832 | 833 | pass SaveFramebuffer 834 | { 835 | VertexShader = PostProcessVS; 836 | PixelShader = TSMFramecopyPS; 837 | RenderTarget = TSMdataTEX; 838 | ClearRenderTargets = true; 839 | } 840 | 841 | #if TSM_ENABLE_DEBUG_PASS 842 | pass DebugOutput 843 | { 844 | VertexShader = PostProcessVS; 845 | PixelShader = TSMDebugDisplayPS; 846 | } 847 | #endif 848 | } 849 | -------------------------------------------------------------------------------- /Shaders/deprecated/HQAA1.7.fx: -------------------------------------------------------------------------------- 1 | /** 2 | * HQAA for ReShade 3.1.1+ 3 | * 4 | * Smooshes FXAA and SMAA together as a single shader 5 | * 6 | * v1.7 release 7 | * 8 | * by lordbean 9 | * 10 | */ 11 | 12 | 13 | //------------------------------- UI setup ----------------------------------------------- 14 | 15 | #include "ReShadeUI.fxh" 16 | 17 | uniform float EdgeThreshold < __UNIFORM_SLIDER_FLOAT1 18 | ui_min = 0.0; ui_max = 1.0; 19 | ui_label = "Edge Detection Threshold"; 20 | ui_tooltip = "Local contrast required to run shader"; 21 | ui_category = "Normal Usage"; 22 | > = 0.075; 23 | 24 | uniform float Subpix < __UNIFORM_SLIDER_FLOAT1 25 | ui_min = 0.0; ui_max = 1.0; 26 | ui_label = "Subpixel Effects Strength"; 27 | ui_tooltip = "Lower = sharper image, Higher = more AA effect"; 28 | ui_category = "Normal Usage"; 29 | > = 0.375; 30 | 31 | uniform int PmodeWarning < 32 | ui_type = "radio"; 33 | ui_label = " "; 34 | ui_text ="\n>>>> WARNING <<<<\n\nVirtual Photography mode allows HQAA to exceed its normal\nlimits when processing subpixel aliasing and will probably\nresult in too much blurring for everyday usage.\n\nIt is only intended for virtual photography purposes where\nthe game's UI is typically not present on the screen."; 35 | ui_category = "Virtual Photography"; 36 | >; 37 | 38 | uniform bool Overdrive < 39 | ui_label = "Enable Virtual Photography Mode"; 40 | ui_category = "Virtual Photography"; 41 | > = false; 42 | 43 | uniform float SubpixBoost < __UNIFORM_SLIDER_FLOAT1 44 | ui_min = 0.0; ui_max = 1.0; 45 | ui_label = "Extra Subpixel Effects Strength"; 46 | ui_tooltip = "Additional boost to subpixel aliasing processing"; 47 | ui_category = "Virtual Photography"; 48 | > = 0.00; 49 | 50 | //------------------------------ Shader Setup ------------------------------------------- 51 | 52 | /****** COMPATIBILITY DEFINES (hopefully) *******************/ 53 | #ifdef FXAA_QUALITY_PRESET 54 | #undef FXAA_QUALITY_PRESET 55 | #endif 56 | #ifdef FXAA_GREEN_AS_LUMA 57 | #undef FXAA_GREEN_AS_LUMA 58 | #endif 59 | #ifdef FXAA_LINEAR_LIGHT 60 | #undef FXAA_LINEAR_LIGHT 61 | #endif 62 | #ifdef FXAA_PC 63 | #undef FXAA_PC 64 | #endif 65 | #ifdef FXAA_HLSL_3 66 | #undef FXAA_HLSL_3 67 | #endif 68 | #ifdef FXAA_GATHER4_ALPHA 69 | #undef FXAA_GATHER4_ALPHA 70 | #endif 71 | #ifdef FxaaTexAlpha4 72 | #undef FxaaTexAlpha4 73 | #endif 74 | #ifdef FxaaTexOffAlpha4 75 | #undef FxaaTexOffAlpha4 76 | #endif 77 | #ifdef FxaaTexGreen4 78 | #undef FxaaTexGreen4 79 | #endif 80 | #ifdef FxaaTexOffGreen4 81 | #undef FxaaTexOffGreen4 82 | #endif 83 | 84 | #ifdef SMAA_PRESET_LOW 85 | #undef SMAA_PRESET_LOW 86 | #endif 87 | #ifdef SMAA_PRESET_MEDIUM 88 | #undef SMAA_PRESET_MEDIUM 89 | #endif 90 | #ifdef SMAA_PRESET_HIGH 91 | #undef SMAA_PRESET_HIGH 92 | #endif 93 | #ifdef SMAA_PRESET_ULTRA 94 | #undef SMAA_PRESET_ULTRA 95 | #endif 96 | #ifdef SMAA_PRESET_CUSTOM 97 | #undef SMAA_PRESET_CUSTOM 98 | #endif 99 | #ifdef SMAA_THRESHOLD 100 | #undef SMAA_THRESHOLD 101 | #endif 102 | #ifdef SMAA_MAX_SEARCH_STEPS 103 | #undef SMAA_MAX_SEARCH_STEPS 104 | #endif 105 | #ifdef SMAA_MAX_SEARCH_STEPS_DIAG 106 | #undef SMAA_MAX_SEARCH_STEPS_DIAG 107 | #endif 108 | #ifdef SMAA_CORNER_ROUNDING 109 | #undef SMAA_CORNER_ROUNDING 110 | #endif 111 | #ifdef SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 112 | #undef SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 113 | #endif 114 | #ifdef SMAA_RT_METRICS 115 | #undef SMAA_RT_METRICS 116 | #endif 117 | #ifdef SMAA_CUSTOM_SL 118 | #undef SMAA_CUSTOM_SL 119 | #endif 120 | #ifdef SMAATexture2D 121 | #undef SMAATexture2D 122 | #endif 123 | #ifdef SMAATexturePass2D 124 | #undef SMAATexturePass2D 125 | #endif 126 | #ifdef SMAASampleLevelZero 127 | #undef SMAASampleLevelZero 128 | #endif 129 | #ifdef SMAASampleLevelZeroPoint 130 | #undef SMAASampleLevelZeroPoint 131 | #endif 132 | #ifdef SMAASampleLevelZeroOffset 133 | #undef SMAASampleLevelZeroOffset 134 | #endif 135 | #ifdef SMAASample 136 | #undef SMAASample 137 | #endif 138 | #ifdef SMAASamplePoint 139 | #undef SMAASamplePoint 140 | #endif 141 | #ifdef SMAASampleOffset 142 | #undef SMAASampleOffset 143 | #endif 144 | #ifdef SMAA_BRANCH 145 | #undef SMAA_BRANCH 146 | #endif 147 | #ifdef SMAA_FLATTEN 148 | #undef SMAA_FLATTEN 149 | #endif 150 | #ifdef SMAAGather 151 | #undef SMAAGather 152 | #endif 153 | #ifdef SMAA_DISABLE_DIAG_DETECTION 154 | #undef SMAA_DISABLE_DIAG_DETECTION 155 | #endif 156 | #ifdef SMAA_PREDICATION 157 | #undef SMAA_PREDICATION 158 | #endif 159 | #ifdef SMAA_REPROJECTION 160 | #undef SMAA_REPROJECTION 161 | #endif 162 | /************************************************************/ 163 | 164 | #define FXAA_GREEN_AS_LUMA 1 // Seems to play nicer with SMAA, less aliasing artifacts 165 | #define SMAA_PRESET_CUSTOM 166 | #define SMAA_THRESHOLD max(0.05, EdgeThreshold) 167 | #define SMAA_MAX_SEARCH_STEPS 112 168 | #define SMAA_CORNER_ROUNDING 0 169 | #define SMAA_MAX_SEARCH_STEPS_DIAG 20 170 | #define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR (1.1 + (0.65 * Subpix)) // Range 1.1 to 1.75 171 | #define FXAA_QUALITY__PRESET 39 172 | #define FXAA_PC 1 173 | #define FXAA_HLSL_3 1 174 | #define SMAA_RT_METRICS float4(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT, BUFFER_WIDTH, BUFFER_HEIGHT) 175 | #define SMAA_CUSTOM_SL 1 176 | #define SMAATexture2D(tex) sampler tex 177 | #define SMAATexturePass2D(tex) tex 178 | #define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, coord)) 179 | #define SMAASampleLevelZeroPoint(tex, coord) SMAASampleLevelZero(tex, coord) 180 | #define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlodoffset(tex, float4(coord, coord), offset) 181 | #define SMAASample(tex, coord) tex2D(tex, coord) 182 | #define SMAASamplePoint(tex, coord) SMAASample(tex, coord) 183 | #define SMAASampleOffset(tex, coord, offset) tex2Doffset(tex, coord, offset) 184 | #define SMAA_BRANCH [branch] 185 | #define SMAA_FLATTEN [flatten] 186 | 187 | #if (__RENDERER__ == 0xb000 || __RENDERER__ == 0xb100) 188 | #define SMAAGather(tex, coord) tex2Dgather(tex, coord, 0) 189 | #define FXAA_GATHER4_ALPHA 1 190 | #define FxaaTexAlpha4(t, p) tex2Dgather(t, p, 3) 191 | #define FxaaTexOffAlpha4(t, p, o) tex2Dgatheroffset(t, p, o, 3) 192 | #define FxaaTexGreen4(t, p) tex2Dgather(t, p, 1) 193 | #define FxaaTexOffGreen4(t, p, o) tex2Dgatheroffset(t, p, o, 1) 194 | #endif 195 | 196 | #include "SMAA.fxh" 197 | #include "FXAA.fxh" 198 | #include "ReShade.fxh" 199 | 200 | #undef FXAA_QUALITY__PS 201 | #undef FXAA_QUALITY__P0 202 | #undef FXAA_QUALITY__P1 203 | #undef FXAA_QUALITY__P2 204 | #undef FXAA_QUALITY__P3 205 | #undef FXAA_QUALITY__P4 206 | #undef FXAA_QUALITY__P5 207 | #undef FXAA_QUALITY__P6 208 | #undef FXAA_QUALITY__P7 209 | #undef FXAA_QUALITY__P8 210 | #undef FXAA_QUALITY__P9 211 | #undef FXAA_QUALITY__P10 212 | #undef FXAA_QUALITY__P11 213 | #define FXAA_QUALITY__PS 13 214 | #define FXAA_QUALITY__P0 0.25 215 | #define FXAA_QUALITY__P1 0.25 216 | #define FXAA_QUALITY__P2 0.25 217 | #define FXAA_QUALITY__P3 0.25 218 | #define FXAA_QUALITY__P4 0.25 219 | #define FXAA_QUALITY__P5 0.25 220 | #define FXAA_QUALITY__P6 0.25 221 | #define FXAA_QUALITY__P7 0.25 222 | #define FXAA_QUALITY__P8 0.25 223 | #define FXAA_QUALITY__P9 0.25 224 | #define FXAA_QUALITY__P10 0.25 225 | #define FXAA_QUALITY__P11 0.25 226 | #define FXAA_QUALITY__P12 0.25 227 | 228 | //------------------------------------- Textures ------------------------------------------- 229 | 230 | texture edgesTex < pooled = true; > 231 | { 232 | Width = BUFFER_WIDTH; 233 | Height = BUFFER_HEIGHT; 234 | Format = RG8; 235 | }; 236 | texture blendTex < pooled = true; > 237 | { 238 | Width = BUFFER_WIDTH; 239 | Height = BUFFER_HEIGHT; 240 | Format = RGBA8; 241 | }; 242 | 243 | texture areaTex < source = "AreaTex.png"; > 244 | { 245 | Width = 160; 246 | Height = 560; 247 | Format = RG8; 248 | }; 249 | texture searchTex < source = "SearchTex.png"; > 250 | { 251 | Width = 64; 252 | Height = 16; 253 | Format = R8; 254 | }; 255 | 256 | // -------------------------------- Samplers ----------------------------------------------- 257 | 258 | sampler colorGammaSampler 259 | { 260 | Texture = ReShade::BackBufferTex; 261 | AddressU = Clamp; AddressV = Clamp; 262 | MipFilter = Point; MinFilter = Linear; MagFilter = Linear; 263 | SRGBTexture = false; 264 | }; 265 | sampler colorLinearSampler 266 | { 267 | Texture = ReShade::BackBufferTex; 268 | AddressU = Clamp; AddressV = Clamp; 269 | MipFilter = Point; MinFilter = Linear; MagFilter = Linear; 270 | SRGBTexture = true; 271 | }; 272 | sampler edgesSampler 273 | { 274 | Texture = edgesTex; 275 | AddressU = Clamp; AddressV = Clamp; 276 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 277 | SRGBTexture = false; 278 | }; 279 | sampler blendSampler 280 | { 281 | Texture = blendTex; 282 | AddressU = Clamp; AddressV = Clamp; 283 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 284 | SRGBTexture = false; 285 | }; 286 | sampler areaSampler 287 | { 288 | Texture = areaTex; 289 | AddressU = Clamp; AddressV = Clamp; AddressW = Clamp; 290 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 291 | SRGBTexture = false; 292 | }; 293 | sampler searchSampler 294 | { 295 | Texture = searchTex; 296 | AddressU = Clamp; AddressV = Clamp; AddressW = Clamp; 297 | MipFilter = Point; MinFilter = Point; MagFilter = Point; 298 | SRGBTexture = false; 299 | }; 300 | sampler FXAATexture 301 | { 302 | Texture = ReShade::BackBufferTex; 303 | MinFilter = Linear; MagFilter = Linear; 304 | }; 305 | 306 | //----------------------------------- Vertex Shaders --------------------------------------- 307 | 308 | void SMAAEdgeDetectionWrapVS( 309 | in uint id : SV_VertexID, 310 | out float4 position : SV_Position, 311 | out float2 texcoord : TEXCOORD0, 312 | out float4 offset[3] : TEXCOORD1) 313 | { 314 | PostProcessVS(id, position, texcoord); 315 | SMAAEdgeDetectionVS(texcoord, offset); 316 | } 317 | void SMAABlendingWeightCalculationWrapVS( 318 | in uint id : SV_VertexID, 319 | out float4 position : SV_Position, 320 | out float2 texcoord : TEXCOORD0, 321 | out float2 pixcoord : TEXCOORD1, 322 | out float4 offset[3] : TEXCOORD2) 323 | { 324 | PostProcessVS(id, position, texcoord); 325 | SMAABlendingWeightCalculationVS(texcoord, pixcoord, offset); 326 | } 327 | void SMAANeighborhoodBlendingWrapVS( 328 | in uint id : SV_VertexID, 329 | out float4 position : SV_Position, 330 | out float2 texcoord : TEXCOORD0, 331 | out float4 offset : TEXCOORD1) 332 | { 333 | PostProcessVS(id, position, texcoord); 334 | SMAANeighborhoodBlendingVS(texcoord, offset); 335 | } 336 | 337 | // -------------------------------- Pixel shaders ------------------------------------------ 338 | // SMAA detection method is using ASSMAA "Both, biasing Clarity" to minimize blurring 339 | 340 | float2 SMAAEdgeDetectionWrapPS( 341 | float4 position : SV_Position, 342 | float2 texcoord : TEXCOORD0, 343 | float4 offset[3] : TEXCOORD1) : SV_Target 344 | { 345 | float2 color = SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaSampler); 346 | float2 luma = SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaSampler); 347 | float2 result = float2(sqrt(color.r * luma.r), sqrt(color.g * luma.g)); 348 | return result; 349 | } 350 | float4 SMAABlendingWeightCalculationWrapPS( 351 | float4 position : SV_Position, 352 | float2 texcoord : TEXCOORD0, 353 | float2 pixcoord : TEXCOORD1, 354 | float4 offset[3] : TEXCOORD2) : SV_Target 355 | { 356 | return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesSampler, areaSampler, searchSampler, 0.0); 357 | } 358 | float3 SMAANeighborhoodBlendingWrapPS( 359 | float4 position : SV_Position, 360 | float2 texcoord : TEXCOORD0, 361 | float4 offset : TEXCOORD1) : SV_Target 362 | { 363 | return SMAANeighborhoodBlendingPS(texcoord, offset, colorLinearSampler, blendSampler).rgb; 364 | } 365 | 366 | float4 FXAAPixelShaderCoarse(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 367 | { 368 | float TotalSubpix = 0.0; 369 | if (Overdrive) 370 | { 371 | TotalSubpix += SubpixBoost; 372 | TotalSubpix = TotalSubpix * 0.4; 373 | } 374 | TotalSubpix += Subpix * 0.1; 375 | float4 output = FxaaPixelShader(texcoord,0,FXAATexture,FXAATexture,FXAATexture,BUFFER_PIXEL_SIZE,0,0,0,TotalSubpix,0.875 - (Subpix * 0.375),0.012,0,0,0,0); // Range 0.875 to 0.5 376 | return saturate(output); 377 | } 378 | 379 | float4 FXAAPixelShaderFine(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 380 | { 381 | float TotalSubpix = 0.0; 382 | if (Overdrive) 383 | { 384 | TotalSubpix += SubpixBoost; 385 | TotalSubpix = TotalSubpix * 0.625; 386 | } 387 | TotalSubpix += Subpix * 0.375; 388 | float4 output = FxaaPixelShader(texcoord,0,FXAATexture,FXAATexture,FXAATexture,BUFFER_PIXEL_SIZE,0,0,0,TotalSubpix,max(0.05,0.5 * EdgeThreshold),0.004,0,0,0,0); // Cap maximum sensitivity level for blur control 389 | return saturate(output); 390 | } 391 | 392 | // -------------------------------- Rendering passes ---------------------------------------- 393 | 394 | technique HQAA < 395 | ui_tooltip = "Hybrid high-Quality AA combines techniques of both SMAA and FXAA to\n" 396 | "produce best possible image quality from using both."; 397 | > 398 | { 399 | pass SMAAEdgeDetection 400 | { 401 | VertexShader = SMAAEdgeDetectionWrapVS; 402 | PixelShader = SMAAEdgeDetectionWrapPS; 403 | RenderTarget = edgesTex; 404 | ClearRenderTargets = true; 405 | StencilEnable = true; 406 | StencilPass = REPLACE; 407 | StencilRef = 1; 408 | } 409 | pass SMAABlendWeightCalculation 410 | { 411 | VertexShader = SMAABlendingWeightCalculationWrapVS; 412 | PixelShader = SMAABlendingWeightCalculationWrapPS; 413 | RenderTarget = blendTex; 414 | ClearRenderTargets = true; 415 | StencilEnable = true; 416 | StencilPass = KEEP; 417 | StencilFunc = EQUAL; 418 | StencilRef = 1; 419 | } 420 | pass SMAANeighborhoodBlending 421 | { 422 | VertexShader = SMAANeighborhoodBlendingWrapVS; 423 | PixelShader = SMAANeighborhoodBlendingWrapPS; 424 | StencilEnable = false; 425 | SRGBWriteEnable = true; 426 | } 427 | pass FXAA1 428 | { 429 | VertexShader = PostProcessVS; 430 | PixelShader = FXAAPixelShaderCoarse; 431 | } 432 | pass FXAA2 433 | { 434 | VertexShader = PostProcessVS; 435 | PixelShader = FXAAPixelShaderFine; 436 | } 437 | } 438 | -------------------------------------------------------------------------------- /Shaders/deprecated/XHQAA.fx: -------------------------------------------------------------------------------- 1 | /** 2 | * XHQAA for ReShade 3.1.1+ 3 | * 4 | * (eXtended Hybrid high-Quality Anti-Aliasing) 5 | * 6 | * Smooshes FXAA and SMAA together as a single shader 7 | * 8 | * v1.32 release 9 | * 10 | * by lordbean 11 | * 12 | */ 13 | 14 | 15 | //------------------------------- UI setup ----------------------------------------------- 16 | 17 | #include "ReShadeUI.fxh" 18 | 19 | uniform float EdgeThreshold < __UNIFORM_SLIDER_FLOAT1 20 | ui_min = 0.0; ui_max = 1.0; 21 | ui_label = "Edge Detection Threshold"; 22 | ui_tooltip = "Local contrast required to run shader"; 23 | ui_category = "Normal Usage"; 24 | > = 0.075; 25 | 26 | uniform float Subpix < __UNIFORM_SLIDER_FLOAT1 27 | ui_min = 0.0; ui_max = 1.0; 28 | ui_label = "Subpixel Effects Strength"; 29 | ui_tooltip = "Lower = sharper image, Higher = more AA effect"; 30 | ui_category = "Normal Usage"; 31 | > = 0.375; 32 | 33 | uniform int PmodeWarning < 34 | ui_type = "radio"; 35 | ui_label = " "; 36 | ui_text ="\n>>>> WARNING <<<<\n\nVirtual Photography mode allows HQAA to exceed its normal\nlimits when processing subpixel aliasing and will probably\nresult in too much blurring for everyday usage.\n\nIt is only intended for virtual photography purposes where\nthe game's UI is typically not present on the screen."; 37 | ui_category = "Virtual Photography"; 38 | >; 39 | 40 | uniform bool Overdrive < 41 | ui_label = "Enable Virtual Photography Mode"; 42 | ui_category = "Virtual Photography"; 43 | > = false; 44 | 45 | uniform float SubpixBoost < __UNIFORM_SLIDER_FLOAT1 46 | ui_min = 0.0; ui_max = 1.0; 47 | ui_label = "Extra Subpixel Effects Strength"; 48 | ui_tooltip = "Additional boost to subpixel aliasing processing"; 49 | ui_category = "Virtual Photography"; 50 | > = 0.00; 51 | 52 | //------------------------------ Shader Setup ------------------------------------------- 53 | 54 | /****** COMPATIBILITY DEFINES (hopefully) *******************/ 55 | #ifdef FXAA_QUALITY_PRESET 56 | #undef FXAA_QUALITY_PRESET 57 | #endif 58 | #ifdef FXAA_GREEN_AS_LUMA 59 | #undef FXAA_GREEN_AS_LUMA 60 | #endif 61 | #ifdef FXAA_LINEAR_LIGHT 62 | #undef FXAA_LINEAR_LIGHT 63 | #endif 64 | #ifdef FXAA_PC 65 | #undef FXAA_PC 66 | #endif 67 | #ifdef FXAA_HLSL_3 68 | #undef FXAA_HLSL_3 69 | #endif 70 | #ifdef FXAA_GATHER4_ALPHA 71 | #undef FXAA_GATHER4_ALPHA 72 | #endif 73 | #ifdef FxaaTexAlpha4 74 | #undef FxaaTexAlpha4 75 | #endif 76 | #ifdef FxaaTexOffAlpha4 77 | #undef FxaaTexOffAlpha4 78 | #endif 79 | #ifdef FxaaTexGreen4 80 | #undef FxaaTexGreen4 81 | #endif 82 | #ifdef FxaaTexOffGreen4 83 | #undef FxaaTexOffGreen4 84 | #endif 85 | 86 | #ifdef SMAA_PRESET_LOW 87 | #undef SMAA_PRESET_LOW 88 | #endif 89 | #ifdef SMAA_PRESET_MEDIUM 90 | #undef SMAA_PRESET_MEDIUM 91 | #endif 92 | #ifdef SMAA_PRESET_HIGH 93 | #undef SMAA_PRESET_HIGH 94 | #endif 95 | #ifdef SMAA_PRESET_ULTRA 96 | #undef SMAA_PRESET_ULTRA 97 | #endif 98 | #ifdef SMAA_PRESET_CUSTOM 99 | #undef SMAA_PRESET_CUSTOM 100 | #endif 101 | #ifdef SMAA_THRESHOLD 102 | #undef SMAA_THRESHOLD 103 | #endif 104 | #ifdef SMAA_MAX_SEARCH_STEPS 105 | #undef SMAA_MAX_SEARCH_STEPS 106 | #endif 107 | #ifdef SMAA_MAX_SEARCH_STEPS_DIAG 108 | #undef SMAA_MAX_SEARCH_STEPS_DIAG 109 | #endif 110 | #ifdef SMAA_CORNER_ROUNDING 111 | #undef SMAA_CORNER_ROUNDING 112 | #endif 113 | #ifdef SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 114 | #undef SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 115 | #endif 116 | #ifdef SMAA_RT_METRICS 117 | #undef SMAA_RT_METRICS 118 | #endif 119 | #ifdef SMAA_CUSTOM_SL 120 | #undef SMAA_CUSTOM_SL 121 | #endif 122 | #ifdef SMAATexture2D 123 | #undef SMAATexture2D 124 | #endif 125 | #ifdef SMAATexturePass2D 126 | #undef SMAATexturePass2D 127 | #endif 128 | #ifdef SMAASampleLevelZero 129 | #undef SMAASampleLevelZero 130 | #endif 131 | #ifdef SMAASampleLevelZeroPoint 132 | #undef SMAASampleLevelZeroPoint 133 | #endif 134 | #ifdef SMAASampleLevelZeroOffset 135 | #undef SMAASampleLevelZeroOffset 136 | #endif 137 | #ifdef SMAASample 138 | #undef SMAASample 139 | #endif 140 | #ifdef SMAASamplePoint 141 | #undef SMAASamplePoint 142 | #endif 143 | #ifdef SMAASampleOffset 144 | #undef SMAASampleOffset 145 | #endif 146 | #ifdef SMAA_BRANCH 147 | #undef SMAA_BRANCH 148 | #endif 149 | #ifdef SMAA_FLATTEN 150 | #undef SMAA_FLATTEN 151 | #endif 152 | #ifdef SMAAGather 153 | #undef SMAAGather 154 | #endif 155 | #ifdef SMAA_DISABLE_DIAG_DETECTION 156 | #undef SMAA_DISABLE_DIAG_DETECTION 157 | #endif 158 | #ifdef SMAA_PREDICATION 159 | #undef SMAA_PREDICATION 160 | #endif 161 | #ifdef SMAA_REPROJECTION 162 | #undef SMAA_REPROJECTION 163 | #endif 164 | /************************************************************/ 165 | 166 | #define FXAA_GREEN_AS_LUMA 1 // Seems to play nicer with SMAA, less aliasing artifacts 167 | #define SMAA_PRESET_CUSTOM 168 | #define SMAA_THRESHOLD max(0.05, EdgeThreshold) 169 | #define SMAA_MAX_SEARCH_STEPS 112 170 | #define SMAA_CORNER_ROUNDING 0 171 | #define SMAA_MAX_SEARCH_STEPS_DIAG 20 172 | #define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR (1.1 + (0.65 * Subpix)) // Range 1.1 to 1.75 173 | #define FXAA_QUALITY__PRESET 39 174 | #define FXAA_PC 1 175 | #define FXAA_HLSL_3 1 176 | #define SMAA_RT_METRICS float4(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT, BUFFER_WIDTH, BUFFER_HEIGHT) 177 | #define SMAA_CUSTOM_SL 1 178 | #define SMAATexture2D(tex) sampler tex 179 | #define SMAATexturePass2D(tex) tex 180 | #define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, coord)) 181 | #define SMAASampleLevelZeroPoint(tex, coord) SMAASampleLevelZero(tex, coord) 182 | #define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlodoffset(tex, float4(coord, coord), offset) 183 | #define SMAASample(tex, coord) tex2D(tex, coord) 184 | #define SMAASamplePoint(tex, coord) SMAASample(tex, coord) 185 | #define SMAASampleOffset(tex, coord, offset) tex2Doffset(tex, coord, offset) 186 | #define SMAA_BRANCH [branch] 187 | #define SMAA_FLATTEN [flatten] 188 | 189 | #if (__RENDERER__ == 0xb000 || __RENDERER__ == 0xb100) 190 | #define SMAAGather(tex, coord) tex2Dgather(tex, coord, 0) 191 | #define FXAA_GATHER4_ALPHA 1 192 | #define FxaaTexAlpha4(t, p) tex2Dgather(t, p, 3) 193 | #define FxaaTexOffAlpha4(t, p, o) tex2Dgatheroffset(t, p, o, 3) 194 | #define FxaaTexGreen4(t, p) tex2Dgather(t, p, 1) 195 | #define FxaaTexOffGreen4(t, p, o) tex2Dgatheroffset(t, p, o, 1) 196 | #endif 197 | 198 | #include "SMAA.fxh" 199 | #include "FXAA.fxh" 200 | #include "ReShade.fxh" 201 | 202 | #undef FXAA_QUALITY__PS 203 | #undef FXAA_QUALITY__P0 204 | #undef FXAA_QUALITY__P1 205 | #undef FXAA_QUALITY__P2 206 | #undef FXAA_QUALITY__P3 207 | #undef FXAA_QUALITY__P4 208 | #undef FXAA_QUALITY__P5 209 | #undef FXAA_QUALITY__P6 210 | #undef FXAA_QUALITY__P7 211 | #undef FXAA_QUALITY__P8 212 | #undef FXAA_QUALITY__P9 213 | #undef FXAA_QUALITY__P10 214 | #undef FXAA_QUALITY__P11 215 | #define FXAA_QUALITY__PS 3 216 | #define FXAA_QUALITY__P0 0.25 217 | #define FXAA_QUALITY__P1 0.25 218 | #define FXAA_QUALITY__P2 0.25 219 | #define FXAA_QUALITY__P3 0.25 220 | #define FXAA_QUALITY__P4 0.25 221 | #define FXAA_QUALITY__P5 0.25 222 | #define FXAA_QUALITY__P6 0.25 223 | #define FXAA_QUALITY__P7 0.25 224 | #define FXAA_QUALITY__P8 0.25 225 | #define FXAA_QUALITY__P9 0.25 226 | #define FXAA_QUALITY__P10 0.25 227 | #define FXAA_QUALITY__P11 0.25 228 | #define FXAA_QUALITY__P12 0.25 229 | 230 | //------------------------------------- Textures ------------------------------------------- 231 | 232 | texture edgesTex < pooled = true; > 233 | { 234 | Width = BUFFER_WIDTH; 235 | Height = BUFFER_HEIGHT; 236 | Format = RG8; 237 | }; 238 | texture blendTex < pooled = true; > 239 | { 240 | Width = BUFFER_WIDTH; 241 | Height = BUFFER_HEIGHT; 242 | Format = RGBA8; 243 | }; 244 | 245 | texture areaTex < source = "AreaTex.png"; > 246 | { 247 | Width = 160; 248 | Height = 560; 249 | Format = RG8; 250 | }; 251 | texture searchTex < source = "SearchTex.png"; > 252 | { 253 | Width = 64; 254 | Height = 16; 255 | Format = R8; 256 | }; 257 | 258 | // -------------------------------- Samplers ----------------------------------------------- 259 | 260 | sampler colorGammaSampler 261 | { 262 | Texture = ReShade::BackBufferTex; 263 | AddressU = Clamp; AddressV = Clamp; 264 | MipFilter = Point; MinFilter = Linear; MagFilter = Linear; 265 | SRGBTexture = false; 266 | }; 267 | sampler colorLinearSampler 268 | { 269 | Texture = ReShade::BackBufferTex; 270 | AddressU = Clamp; AddressV = Clamp; 271 | MipFilter = Point; MinFilter = Linear; MagFilter = Linear; 272 | SRGBTexture = true; 273 | }; 274 | sampler edgesSampler 275 | { 276 | Texture = edgesTex; 277 | AddressU = Clamp; AddressV = Clamp; 278 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 279 | SRGBTexture = false; 280 | }; 281 | sampler blendSampler 282 | { 283 | Texture = blendTex; 284 | AddressU = Clamp; AddressV = Clamp; 285 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 286 | SRGBTexture = false; 287 | }; 288 | sampler areaSampler 289 | { 290 | Texture = areaTex; 291 | AddressU = Clamp; AddressV = Clamp; AddressW = Clamp; 292 | MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; 293 | SRGBTexture = false; 294 | }; 295 | sampler searchSampler 296 | { 297 | Texture = searchTex; 298 | AddressU = Clamp; AddressV = Clamp; AddressW = Clamp; 299 | MipFilter = Point; MinFilter = Point; MagFilter = Point; 300 | SRGBTexture = false; 301 | }; 302 | sampler FXAATexture 303 | { 304 | Texture = ReShade::BackBufferTex; 305 | MinFilter = Linear; MagFilter = Linear; 306 | }; 307 | 308 | //----------------------------------- Vertex Shaders --------------------------------------- 309 | 310 | void SMAAEdgeDetectionWrapVS( 311 | in uint id : SV_VertexID, 312 | out float4 position : SV_Position, 313 | out float2 texcoord : TEXCOORD0, 314 | out float4 offset[3] : TEXCOORD1) 315 | { 316 | PostProcessVS(id, position, texcoord); 317 | SMAAEdgeDetectionVS(texcoord, offset); 318 | } 319 | void SMAABlendingWeightCalculationWrapVS( 320 | in uint id : SV_VertexID, 321 | out float4 position : SV_Position, 322 | out float2 texcoord : TEXCOORD0, 323 | out float2 pixcoord : TEXCOORD1, 324 | out float4 offset[3] : TEXCOORD2) 325 | { 326 | PostProcessVS(id, position, texcoord); 327 | SMAABlendingWeightCalculationVS(texcoord, pixcoord, offset); 328 | } 329 | void SMAANeighborhoodBlendingWrapVS( 330 | in uint id : SV_VertexID, 331 | out float4 position : SV_Position, 332 | out float2 texcoord : TEXCOORD0, 333 | out float4 offset : TEXCOORD1) 334 | { 335 | PostProcessVS(id, position, texcoord); 336 | SMAANeighborhoodBlendingVS(texcoord, offset); 337 | } 338 | 339 | // -------------------------------- Pixel shaders ------------------------------------------ 340 | // SMAA detection method is using ASSMAA "Both, biasing Clarity" to minimize blurring 341 | 342 | float2 SMAAEdgeDetectionWrapPS( 343 | float4 position : SV_Position, 344 | float2 texcoord : TEXCOORD0, 345 | float4 offset[3] : TEXCOORD1) : SV_Target 346 | { 347 | float2 color = SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaSampler); 348 | float2 luma = SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaSampler); 349 | float2 result = float2(sqrt(color.r * luma.r), sqrt(color.g * luma.g)); 350 | return result; 351 | } 352 | float4 SMAABlendingWeightCalculationWrapPS( 353 | float4 position : SV_Position, 354 | float2 texcoord : TEXCOORD0, 355 | float2 pixcoord : TEXCOORD1, 356 | float4 offset[3] : TEXCOORD2) : SV_Target 357 | { 358 | return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesSampler, areaSampler, searchSampler, 0.0); 359 | } 360 | float3 SMAANeighborhoodBlendingWrapPS( 361 | float4 position : SV_Position, 362 | float2 texcoord : TEXCOORD0, 363 | float4 offset : TEXCOORD1) : SV_Target 364 | { 365 | return SMAANeighborhoodBlendingPS(texcoord, offset, colorLinearSampler, blendSampler).rgb; 366 | } 367 | 368 | float4 FXAAPixelShaderVeryLow(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 369 | { 370 | float TotalSubpix = 0.0; 371 | if (Overdrive) 372 | { 373 | TotalSubpix += SubpixBoost; 374 | TotalSubpix = TotalSubpix * 0.4; 375 | } 376 | TotalSubpix += Subpix * 0.1; 377 | float4 output = FxaaPixelShader(texcoord,0,FXAATexture,FXAATexture,FXAATexture,BUFFER_PIXEL_SIZE,0,0,0,TotalSubpix,0.9 - (Subpix * 0.15),0.012,0,0,0,0); // Range 0.9 to 0.75 378 | return saturate(output); 379 | } 380 | 381 | float4 FXAAPixelShaderLow(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 382 | { 383 | float TotalSubpix = 0.0; 384 | if (Overdrive) 385 | { 386 | TotalSubpix += SubpixBoost; 387 | TotalSubpix = TotalSubpix * 0.4; 388 | } 389 | TotalSubpix += Subpix * 0.1; 390 | float4 output = FxaaPixelShader(texcoord,0,FXAATexture,FXAATexture,FXAATexture,BUFFER_PIXEL_SIZE,0,0,0,TotalSubpix,0.75 - (Subpix * 0.15),0.012,0,0,0,0); // Range 0.75 to 0.6 391 | return saturate(output); 392 | } 393 | 394 | float4 FXAAPixelShaderMid(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 395 | { 396 | float TotalSubpix = 0.0; 397 | if (Overdrive) 398 | { 399 | TotalSubpix += SubpixBoost; 400 | TotalSubpix = TotalSubpix * 0.4; 401 | } 402 | TotalSubpix += Subpix * 0.1; 403 | float4 output = FxaaPixelShader(texcoord,0,FXAATexture,FXAATexture,FXAATexture,BUFFER_PIXEL_SIZE,0,0,0,TotalSubpix,0.6 - (Subpix * 0.15),0.012,0,0,0,0); // Range 0.6 to 0.45 404 | return saturate(output); 405 | } 406 | 407 | float4 FXAAPixelShaderHigh(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 408 | { 409 | float TotalSubpix = 0.0; 410 | if (Overdrive) 411 | { 412 | TotalSubpix += SubpixBoost; 413 | TotalSubpix = TotalSubpix * 0.4; 414 | } 415 | TotalSubpix += Subpix * 0.1; 416 | float4 output = FxaaPixelShader(texcoord,0,FXAATexture,FXAATexture,FXAATexture,BUFFER_PIXEL_SIZE,0,0,0,TotalSubpix,0.45 - (Subpix * 0.15),0.012,0,0,0,0); // Range 0.45 to 0.3 417 | return saturate(output); 418 | } 419 | 420 | float4 FXAAPixelShaderFine(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target 421 | { 422 | float TotalSubpix = 0.0; 423 | if (Overdrive) 424 | { 425 | TotalSubpix += SubpixBoost; 426 | TotalSubpix = TotalSubpix * 0.750; 427 | } 428 | TotalSubpix += Subpix * 0.250; 429 | float4 output = FxaaPixelShader(texcoord,0,FXAATexture,FXAATexture,FXAATexture,BUFFER_PIXEL_SIZE,0,0,0,TotalSubpix,max(0.05,0.3 * EdgeThreshold),0.004,0,0,0,0); // Cap maximum sensitivity level for blur control 430 | return saturate(output); 431 | } 432 | 433 | // -------------------------------- Rendering passes ---------------------------------------- 434 | 435 | technique HQAA < 436 | ui_tooltip = "eXtended Hybrid high-Quality AA combines techniques of\n" 437 | "SMAA and FXAA and subdivides the correction tasks further\n" 438 | "than HQAA to extract maximum possible image quality at the\n" 439 | "expense of total disregard for the shader's performance.\n\n" 440 | "XHQAA WILL CAUSE A VISIBLE DROP IN YOUR FRAME-RATE."; 441 | > 442 | { 443 | pass SMAAEdgeDetection 444 | { 445 | VertexShader = SMAAEdgeDetectionWrapVS; 446 | PixelShader = SMAAEdgeDetectionWrapPS; 447 | RenderTarget = edgesTex; 448 | ClearRenderTargets = true; 449 | StencilEnable = true; 450 | StencilPass = REPLACE; 451 | StencilRef = 1; 452 | } 453 | pass SMAABlendWeightCalculation 454 | { 455 | VertexShader = SMAABlendingWeightCalculationWrapVS; 456 | PixelShader = SMAABlendingWeightCalculationWrapPS; 457 | RenderTarget = blendTex; 458 | ClearRenderTargets = true; 459 | StencilEnable = true; 460 | StencilPass = KEEP; 461 | StencilFunc = EQUAL; 462 | StencilRef = 1; 463 | } 464 | pass SMAANeighborhoodBlending 465 | { 466 | VertexShader = SMAANeighborhoodBlendingWrapVS; 467 | PixelShader = SMAANeighborhoodBlendingWrapPS; 468 | StencilEnable = false; 469 | SRGBWriteEnable = true; 470 | } 471 | pass FXAA 472 | { 473 | VertexShader = PostProcessVS; 474 | PixelShader = FXAAPixelShaderVeryLow; 475 | } 476 | pass FXAA 477 | { 478 | VertexShader = PostProcessVS; 479 | PixelShader = FXAAPixelShaderLow; 480 | } 481 | pass FXAA 482 | { 483 | VertexShader = PostProcessVS; 484 | PixelShader = FXAAPixelShaderMid; 485 | } 486 | pass FXAA 487 | { 488 | VertexShader = PostProcessVS; 489 | PixelShader = FXAAPixelShaderHigh; 490 | } 491 | pass FXAA 492 | { 493 | VertexShader = PostProcessVS; 494 | PixelShader = FXAAPixelShaderFine; 495 | } 496 | } 497 | -------------------------------------------------------------------------------- /Shaders/deprecated/readme.md: -------------------------------------------------------------------------------- 1 | This folder contains old shaders which are now mostly representative of my learning process and kept for posterity. 2 | -------------------------------------------------------------------------------- /Shaders/readme.md: -------------------------------------------------------------------------------- 1 | PLEASE NOTE: 2 | 3 | ASSMAA.fx and FSMAA.fx require you to install the SweetFX effects package when you install ReShade to your game. They WILL NOT COMPILE if you skip this step. 4 | 5 | 6 | 7 | If you have previously used SMAA with your game and you run into errors compiling ASSMAA or FSMAA, try uninstalling ReShade from the game and then re-installing it (or, you can just delete the profile.ini file being used with the game). 8 | 9 | HQAA.fx now integrates the required code within the .fx file and only requires the SMAA search textures. These can be obtained by installing the SweetFX package as above or from the textures directory of this repository. 10 | -------------------------------------------------------------------------------- /download/main.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lordbean-git/reshade-shaders/4c113d29576a47ab9062357a7d2912718d226934/download/main.zip -------------------------------------------------------------------------------- /textures/AreaTex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lordbean-git/reshade-shaders/4c113d29576a47ab9062357a7d2912718d226934/textures/AreaTex.png -------------------------------------------------------------------------------- /textures/SearchTex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lordbean-git/reshade-shaders/4c113d29576a47ab9062357a7d2912718d226934/textures/SearchTex.png -------------------------------------------------------------------------------- /textures/readme.md: -------------------------------------------------------------------------------- 1 | Supporting textures for shaders. 2 | --------------------------------------------------------------------------------