Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * _______ ___ ___ ___ ___
- * / || \/ | / \ / \
- * | (---- | \ / | / ^ \ / ^ \
- * \ \ | |\/| | / /_\ \ / /_\ \
- * ----) | | | | | / _____ \ / _____ \
- * |_______/ |__| |__| /__/ \__\ /__/ \__\
- *
- * E N H A N C E D
- * 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
- *
- * for ReShade 3.0+
- */
- //------------------- Preprocessor Settings -------------------
- #ifndef SMAA_PREDICATION
- #define SMAA_PREDICATION 0 // Disable predication by default
- #endif
- #if !defined(SMAA_PRESET_LOW) && !defined(SMAA_PRESET_MEDIUM) && !defined(SMAA_PRESET_HIGH) && !defined(SMAA_PRESET_ULTRA)
- #define SMAA_PRESET_CUSTOM // Do not use a quality preset by default
- #endif
- //----------------------- UI Variables ------------------------
- #include "ReShadeUI.fxh"
- uniform int EdgeDetectionType <
- ui_type = "combo";
- ui_items = "Luminance edge detection\0Color edge detection\0Depth edge detection\0";
- ui_label = "Edge Detection Type";
- > = 1;
- #ifdef SMAA_PRESET_CUSTOM
- uniform float EdgeDetectionThreshold <
- ui_type = "drag";
- ui_min = 0.05; ui_max = 0.20; ui_step = 0.01;
- ui_tooltip = "Edge detection threshold. If SMAA misses some edges try lowering this slightly.";
- ui_label = "Edge Detection Threshold";
- > = 0.10;
- uniform int MaxSearchSteps < __UNIFORM_SLIDER_INT1
- ui_min = 0; ui_max = 112;
- ui_label = "Max Search Steps";
- ui_tooltip = "Determines the radius SMAA will search for aliased edges.";
- > = 32;
- uniform int MaxSearchStepsDiagonal < __UNIFORM_SLIDER_INT1
- ui_min = 0; ui_max = 20;
- ui_label = "Max Search Steps Diagonal";
- ui_tooltip = "Determines the radius SMAA will search for diagonal aliased edges";
- > = 16;
- uniform int CornerRounding < __UNIFORM_SLIDER_INT1
- ui_min = 0; ui_max = 100;
- ui_label = "Corner Rounding";
- ui_tooltip = "Determines the percent of anti-aliasing to apply to corners.";
- > = 25;
- #if SMAA_PREDICATION
- uniform float PredicationThreshold <
- ui_type = "drag";
- ui_min = 0.005; ui_max = 1.00; ui_step = 0.01;
- ui_tooltip = "Threshold to be used in the additional predication buffer.";
- ui_label = "Predication Threshold";
- > = 0.01;
- uniform float PredicationScale < __UNIFORM_SLIDER_FLOAT1
- ui_min = 1; ui_max = 5;
- ui_tooltip = "How much to scale the global threshold used for luma or color edge.";
- ui_label = "Predication Scale";
- > = 2.0;
- uniform float PredicationStrength < __UNIFORM_SLIDER_FLOAT1
- ui_min = 0; ui_max = 1;
- ui_tooltip = "How much to locally decrease the threshold.";
- ui_label = "Predication Strength";
- > = 0.4;
- #endif
- #endif
- uniform int DebugOutput <
- ui_type = "combo";
- ui_items = "None\0View edges\0View weights\0";
- ui_label = "Debug Output";
- > = false;
- #ifdef SMAA_PRESET_CUSTOM
- #define SMAA_THRESHOLD EdgeDetectionThreshold
- #define SMAA_MAX_SEARCH_STEPS MaxSearchSteps
- #define SMAA_MAX_SEARCH_STEPS_DIAG MaxSearchStepsDiagonal
- #define SMAA_CORNER_ROUNDING CornerRounding
- #if SMAA_PREDICATION
- #define SMAA_PREDICATION_THRESHOLD PredicationThreshold
- #define SMAA_PREDICATION_SCALE PredicationScale
- #define SMAA_PREDICATION_STRENGTH PredicationStrength
- #endif
- #endif
- #define SMAA_RT_METRICS float4(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT, BUFFER_WIDTH, BUFFER_HEIGHT)
- #define SMAA_CUSTOM_SL 1
- #define predicationSampler depthLinearSampler
- #define SMAATexture2D(tex) sampler tex
- #define SMAATexturePass2D(tex) tex
- #define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, coord))
- #define SMAASampleLevelZeroPoint(tex, coord) SMAASampleLevelZero(tex, coord)
- #define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlodoffset(tex, float4(coord, coord), offset)
- #define SMAASample(tex, coord) tex2D(tex, coord)
- #define SMAASamplePoint(tex, coord) SMAASample(tex, coord)
- #define SMAASampleOffset(tex, coord, offset) tex2Doffset(tex, coord, offset)
- #define SMAA_BRANCH [branch]
- #define SMAA_FLATTEN [flatten]
- #if (__RENDERER__ == 0xb000 || __RENDERER__ == 0xb100)
- #define SMAAGather(tex, coord) tex2Dgather(tex, coord, 0)
- #endif
- #include "SMAA.fxh"
- #include "ReShade.fxh"
- // Textures
- texture depthTex
- {
- Width = BUFFER_WIDTH;
- Height = BUFFER_HEIGHT;
- Format = R16F;
- };
- texture edgesTex
- {
- Width = BUFFER_WIDTH;
- Height = BUFFER_HEIGHT;
- Format = RG8;
- };
- texture blendTex
- {
- Width = BUFFER_WIDTH;
- Height = BUFFER_HEIGHT;
- Format = RGBA8;
- };
- texture areaTex < source = "AreaTex.dds"; >
- {
- Width = 160;
- Height = 560;
- Format = RG8;
- };
- texture searchTex < source = "SearchTex.dds"; >
- {
- Width = 64;
- Height = 16;
- Format = R8;
- };
- // Samplers
- sampler depthLinearSampler
- {
- Texture = depthTex;
- AddressU = Clamp; AddressV = Clamp;
- MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
- SRGBTexture = false;
- };
- sampler colorGammaSampler
- {
- Texture = ReShade::BackBufferTex;
- AddressU = Clamp; AddressV = Clamp;
- MipFilter = Point; MinFilter = Linear; MagFilter = Linear;
- SRGBTexture = false;
- };
- sampler colorLinearSampler
- {
- Texture = ReShade::BackBufferTex;
- AddressU = Clamp; AddressV = Clamp;
- MipFilter = Point; MinFilter = Linear; MagFilter = Linear;
- SRGBTexture = true;
- };
- sampler edgesSampler
- {
- Texture = edgesTex;
- AddressU = Clamp; AddressV = Clamp;
- MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
- SRGBTexture = false;
- };
- sampler blendSampler
- {
- Texture = blendTex;
- AddressU = Clamp; AddressV = Clamp;
- MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
- SRGBTexture = false;
- };
- sampler areaSampler
- {
- Texture = areaTex;
- AddressU = Clamp; AddressV = Clamp; AddressW = Clamp;
- MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
- SRGBTexture = false;
- };
- sampler searchSampler
- {
- Texture = searchTex;
- AddressU = Clamp; AddressV = Clamp; AddressW = Clamp;
- MipFilter = Point; MinFilter = Point; MagFilter = Point;
- SRGBTexture = false;
- };
- // Vertex shaders
- void SMAAEdgeDetectionWrapVS(
- in uint id : SV_VertexID,
- out float4 position : SV_Position,
- out float2 texcoord : TEXCOORD0,
- out float4 offset[3] : TEXCOORD1)
- {
- PostProcessVS(id, position, texcoord);
- SMAAEdgeDetectionVS(texcoord, offset);
- }
- void SMAABlendingWeightCalculationWrapVS(
- in uint id : SV_VertexID,
- out float4 position : SV_Position,
- out float2 texcoord : TEXCOORD0,
- out float2 pixcoord : TEXCOORD1,
- out float4 offset[3] : TEXCOORD2)
- {
- PostProcessVS(id, position, texcoord);
- SMAABlendingWeightCalculationVS(texcoord, pixcoord, offset);
- }
- void SMAANeighborhoodBlendingWrapVS(
- in uint id : SV_VertexID,
- out float4 position : SV_Position,
- out float2 texcoord : TEXCOORD0,
- out float4 offset : TEXCOORD1)
- {
- PostProcessVS(id, position, texcoord);
- SMAANeighborhoodBlendingVS(texcoord, offset);
- }
- // Pixel shaders
- float SMAADepthLinearizationPS(
- float4 position : SV_Position,
- float2 texcoord : TEXCOORD0) : SV_Target
- {
- return ReShade::GetLinearizedDepth(texcoord.xy);
- }
- float2 SMAAEdgeDetectionWrapPS(
- float4 position : SV_Position,
- float2 texcoord : TEXCOORD0,
- float4 offset[3] : TEXCOORD1) : SV_Target
- {
- if (EdgeDetectionType == 0)
- return SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaSampler
- #if SMAA_PREDICATION
- , predicationSampler
- #endif
- );
- if (EdgeDetectionType == 2)
- return SMAADepthEdgeDetectionPS(texcoord, offset, depthLinearSampler);
- return SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaSampler
- #if SMAA_PREDICATION
- , predicationSampler
- #endif
- );
- }
- float4 SMAABlendingWeightCalculationWrapPS(
- float4 position : SV_Position,
- float2 texcoord : TEXCOORD0,
- float2 pixcoord : TEXCOORD1,
- float4 offset[3] : TEXCOORD2) : SV_Target
- {
- return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesSampler, areaSampler, searchSampler, 0.0);
- }
- float3 SMAANeighborhoodBlendingWrapPS(
- float4 position : SV_Position,
- float2 texcoord : TEXCOORD0,
- float4 offset : TEXCOORD1) : SV_Target
- {
- if (DebugOutput == 1)
- return tex2D(edgesSampler, texcoord).rgb;
- if (DebugOutput == 2)
- return tex2D(blendSampler, texcoord).rgb;
- return SMAANeighborhoodBlendingPS(texcoord, offset, colorLinearSampler, blendSampler).rgb;
- }
- // Rendering passes
- technique SMAA
- {
- pass LinearizeDepthPass
- {
- VertexShader = PostProcessVS;
- PixelShader = SMAADepthLinearizationPS;
- RenderTarget = depthTex;
- }
- pass EdgeDetectionPass
- {
- VertexShader = SMAAEdgeDetectionWrapVS;
- PixelShader = SMAAEdgeDetectionWrapPS;
- RenderTarget = edgesTex;
- ClearRenderTargets = true;
- StencilEnable = true;
- StencilPass = REPLACE;
- StencilRef = 1;
- }
- pass BlendWeightCalculationPass
- {
- VertexShader = SMAABlendingWeightCalculationWrapVS;
- PixelShader = SMAABlendingWeightCalculationWrapPS;
- RenderTarget = blendTex;
- ClearRenderTargets = true;
- StencilEnable = true;
- StencilPass = KEEP;
- StencilFunc = EQUAL;
- StencilRef = 1;
- }
- pass NeighborhoodBlendingPass
- {
- VertexShader = SMAANeighborhoodBlendingWrapVS;
- PixelShader = SMAANeighborhoodBlendingWrapPS;
- StencilEnable = false;
- SRGBWriteEnable = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement