#line 1 "unknown"

#line 1 "D:\The.Elder.Scrolls.V.Skyrim.VR.v1.4.0.15.8\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\Denoise.fx"
#line 1 "D:\The.Elder.Scrolls.V.Skyrim.VR.v1.4.0.15.8\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\ReShadeUI.fxh"
#line 95 "D:\The.Elder.Scrolls.V.Skyrim.VR.v1.4.0.15.8\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\Denoise.fx"
#line 97
uniform float NoiseLevel <      ui_type = "slider"; 
ui_min = 0.01; ui_max = 1.00;
ui_label = "Noise Level";
ui_tooltip = "Approximate level of noise in the image.";
> = 0.15;
#line 103
uniform float LerpCoefficeint <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 1.00;
ui_label = "Lerp Coefficient";
ui_tooltip = "Amount of blending between the original and the processed image.";
> = 0.8;
#line 109
uniform float WeightThreshold <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 1.0;
ui_label = "Weight Threshold";
> = 0.03;
#line 114
uniform float CounterThreshold <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 1.0;
ui_label = "Counter Threshold";
> = 0.05;
#line 119
uniform float GaussianSigma <      ui_type = "slider"; 
ui_min = 1.0; ui_max = 100.0;
ui_label = "Gaussian Sigma";
ui_tooltip = "Controls the additional amount of gaussian blur on the image.";
> = 50.0;
#line 1 "D:\The.Elder.Scrolls.V.Skyrim.VR.v1.4.0.15.8\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\ReShade.fxh"
#line 50
namespace ReShade
{
#line 61
static const float AspectRatio = 2464 * (1.0 / 1468);
static const float2 PixelSize = float2((1.0 / 2464), (1.0 / 1468));
static const float2 ScreenSize = float2(2464, 1468);
#line 67
texture BackBufferTex : COLOR;
texture DepthBufferTex : DEPTH;
#line 70
sampler BackBuffer { Texture = BackBufferTex; };
sampler DepthBuffer { Texture = DepthBufferTex; };
#line 74
float GetLinearizedDepth(float2 texcoord)
{
#line 79
texcoord.x /=  1;
texcoord.y /=  1;
#line 84
texcoord.x -=  0 / 2.000000001;
#line 89
texcoord.y +=  0 / 2.000000001;
#line 91
float depth = tex2Dlod(DepthBuffer, float4(texcoord, 0, 0)).x *  1;
#line 100
const float N = 1.0;
depth /= 1000.0 - depth * (1000.0 - N);
#line 103
return depth;
}
}
#line 108
void PostProcessVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD)
{
texcoord.x = (id == 2) ? 2.0 : 0.0;
texcoord.y = (id == 1) ? 2.0 : 0.0;
position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}
#line 139 "D:\The.Elder.Scrolls.V.Skyrim.VR.v1.4.0.15.8\The Elder Scrolls V Skyrim VR\reshade-shaders\Shaders\Denoise.fx"
#line 141
float3 PS_Denoise_KNN(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_TARGET {
float3 orig = tex2D(ReShade::BackBuffer, texcoord).rgb;
float3 texIJ;
float weight;
float3 result = 0.0;
float counter = 0.0;
float sum = 0.0;
#line 149
float iWindowArea = 2.0 *  3	 + 1.0;
iWindowArea *= iWindowArea;
#line 152
for (int i = - 3	; i <=  3	; i++) {
for (int j = - 3	; j <=  3	; j++) {
texIJ = tex2D(ReShade::BackBuffer, texcoord +  float2((1.0 / 2464), (1.0 / 1468)) * float2(i, j)).rgb;
weight = dot(orig - texIJ, orig - texIJ);
#line 157
weight = exp(-(weight * rcp(NoiseLevel) + (i * i + j * j) * rcp(GaussianSigma)));
counter += weight > WeightThreshold;
#line 160
sum += weight;
#line 162
result.rgb += texIJ * weight;
}
}
#line 166
result /= sum;
float lerpQ = (counter > (CounterThreshold * iWindowArea)) ? 1.0 - LerpCoefficeint : LerpCoefficeint;
result = lerp(result, orig, lerpQ);
#line 170
return result;
}
#line 173
float3 PS_Denoise_NLM(float4 vpos : SV_POSITION, float2 texcoord : TEXCOORD) : SV_TARGET {
float3 result = 0.0;
float3 texIJb;
float3 texIJc;
float counter = 0.0;
float weight;
float sum = 0.0;
#line 181
float invBlockArea = 2.0 *  2	 + 1.0;
invBlockArea = rcp(invBlockArea * invBlockArea);
#line 184
for (int i = - 3	; i <=  3	; i++) {
for (int j = - 3	; j <=  3	; j++) {
#line 187
weight = 0.0;
#line 189
for (int n = - 2	; n <=  2	; n++) {
for (int m = - 2	; m <=  2	; m++) {
texIJb = tex2D(ReShade::BackBuffer, texcoord +  float2((1.0 / 2464), (1.0 / 1468)) * float2(i + n, j + m)).rgb;
texIJc = tex2D(ReShade::BackBuffer, texcoord +  float2((1.0 / 2464), (1.0 / 1468)) * float2(    n,     m)).rgb;
weight = dot(texIJb - texIJc, texIJb - texIJc) + weight;
}
}
texIJc = tex2D(ReShade::BackBuffer, texcoord +  float2((1.0 / 2464), (1.0 / 1468)) * float2(i, j)).rgb;
#line 198
weight *= invBlockArea;
weight = exp(-(weight * rcp(NoiseLevel) + (i * i + j * j) * rcp(GaussianSigma)));
#line 201
counter += weight > WeightThreshold;
#line 203
sum += weight;
#line 205
result += texIJc * weight;
}
}
#line 209
float iWindowArea = 2.0 *  3	 + 1.0;
iWindowArea *= iWindowArea;
#line 212
float3 orig = tex2D(ReShade::BackBuffer, texcoord).rgb;
#line 214
result /= sum;
float lerpQ = (counter > (CounterThreshold * iWindowArea)) ? 1.0 - LerpCoefficeint : LerpCoefficeint;
result = lerp(result, orig, lerpQ);
#line 218
return result;
}
#line 221
technique KNearestNeighbors
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_Denoise_KNN;
}
}
#line 230
technique NonLocalMeans
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_Denoise_NLM;
}
}

