CAS with Depth
- elpollonegro
- Topic Author
Less
More
Hello. Could a good gentleman add depth detection in the port of AMD contrast adaptive sharpen so that the sharpening effect starts fading or getting less intense at further distances ?
CAS for me is the best sharpening filters out there but unfortunately further away textures become too jagged and rough when sharpened. So adding depth to CAS would make it perfect, sort of like what smart sharp does.
Thank you in advance!
CAS for me is the best sharpening filters out there but unfortunately further away textures become too jagged and rough when sharpened. So adding depth to CAS would make it perfect, sort of like what smart sharp does.
Thank you in advance!
Please Log in or Create an account to join the conversation.
- YF
Less
More
Warning: Spoiler!
uniform float Sharpening <
ui_type = "slider";
ui_label = "NearSharpen";
ui_tooltip = "Adjusts sharpening intensity by averaging the original pixels to the sharpened result. 0.0 is the unmodified default.";
ui_min = 0.0; ui_max = 1.0;ui_step = 0.01;
> = 0.0;
uniform float depthStart <
ui_type = "slider";
ui_label = "Change Depth Start Plane";
ui_tooltip = "Change Depth Start Plane";
ui_category = "Depth";
ui_min = 0.000f;
ui_max = 1.000f;
ui_step = 0.01;
> = 0;
uniform float depthEnd <
ui_type = "slider";
ui_label = "Change Depth End Plane";
ui_tooltip = "Change Depth End Plane";
ui_category = "Depth";
ui_min = 0.0f;
ui_max = 1.0f;
ui_step = 0.01;
> = 0.5;
uniform float depthCurve <
ui_label = "Depth Curve Adjustment";
ui_tooltip = "Depth Curve Adjustment";
ui_category = "Depth";
ui_type = "slider";
ui_min = 0.05;
ui_max = 8.0;
ui_step = 0.01;
> = 8.0;
uniform bool display_depth <
ui_label = "Show depth texture.\nThe below adjustments only apply to white areas.\0Make sure you have your depth texture setup correctly.";
ui_category = "Depth";
> = false;
uniform float FarSharpening <
ui_type = "slider";
ui_label = "FarSharpen";
ui_tooltip = "Adjusts sharpening intensity by averaging the original pixels to the sharpened result. 0.0 is the unmodified default.";
ui_min = 0.0; ui_max = 1.0;ui_step = 0.01;
> = 0.0;
#include "ReShade.fxh"
#define pixel float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT)
texture TexColor : COLOR;
sampler sTexColor {Texture = TexColor; SRGBTexture = true;};
float3 CASPass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
// fetch a 3x3 neighborhood around the pixel 'e',
// a b c
// d(e)f
// g h i
float3 b = tex2Doffset(sTexColor, texcoord, int2(0, -1)).rgb;
float3 d = tex2Doffset(sTexColor, texcoord, int2(-1, 0)).rgb;
float3 e = tex2D(sTexColor, texcoord).rgb;
float3 res;
float3 Dres;
float3 f = tex2Doffset(sTexColor, texcoord, int2(1, 0)).rgb;
float3 h = tex2Doffset(sTexColor, texcoord, int2(0, 1)).rgb;
float3 i = tex2Doffset(sTexColor, texcoord, int2(1, 1)).rgb;
float3 g = tex2Doffset(sTexColor, texcoord, int2(-1, 1)).rgb;
float3 a = tex2Doffset(sTexColor, texcoord, int2(-1, -1)).rgb;
float3 c = tex2Doffset(sTexColor, texcoord, int2(1, -1)).rgb;
// Soft min and max.
// a b c b
// d e f * 0.5 + d e f * 0.5
// g h i h
// These are 2.0x bigger (factored out the extra multiply).
float3 mnRGB = min(min(min(d, e), min(f, b)), h);
float3 mnRGB2 = min(mnRGB, min(min(a, c), min(g, i)));
mnRGB += mnRGB2;
float3 mxRGB = max(max(max(d, e), max(f, b)), h);
float3 mxRGB2 = max(mxRGB, max(max(a, c), max(g, i)));
mxRGB += mxRGB2;
// Smooth minimum distance to signal limit divided by smooth max.
float3 rcpMRGB = rcp(mxRGB);
float3 ampRGB = saturate(min(mnRGB, 2.0 - mxRGB) * rcpMRGB);
// Shaping amount of sharpening.
ampRGB = rsqrt(ampRGB);
float peak = -3.0 * 0.0 + 8.0; //contrast 0.0
float3 wRGB = -rcp(ampRGB * peak);
float3 rcpWeightRGB = rcp(4.0 * wRGB + 1.0);
// 0 w 0
// Filter shape: w 1 w
// 0 w 0
float3 window = (b + d) + (f + h);
float depth = ReShade::GetLinearizedDepth( texcoord ).x;
depth = smoothstep( depthStart, depthEnd, depth );
depth = pow( depth, depthCurve );
depth = saturate( depth );
float3 outColor = saturate((window * wRGB + e) * rcpWeightRGB);
res = lerp(e, outColor, 1.0+Sharpening);
Dres = lerp(e, outColor, 1.0+FarSharpening);
res = lerp( res, Dres, depth );
res = lerp( res, depth.xxx, display_depth );
return res;
}
technique CAS_Depth
{
pass
{
VertexShader = PostProcessVS;
PixelShader = CASPass;
SRGBWriteEnable = true;
}
}
Last edit: 2 years 2 months ago by YF.
The following user(s) said Thank You: elpollonegro, RdenBlaauwen
Please Log in or Create an account to join the conversation.
- elpollonegro
- Topic Author
Less
More
Perfect. Flawless. Thank you so much for taking the time ! You are a hero, kind sir !
Please Log in or Create an account to join the conversation.