#line 1 "unknown"

#line 1 "D:\Games\Kenshi\reshade-shaders\Shaders\EyeAdaption.fx"
#line 1 "D:\Games\Kenshi\reshade-shaders\Shaders\ReShade.fxh"
#line 50
namespace ReShade
{
#line 61
static const float AspectRatio = 1360 * (1.0 / 768);
static const float2 PixelSize = float2((1.0 / 1360), (1.0 / 768));
static const float2 ScreenSize = float2(1360, 768);
#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 10 "D:\Games\Kenshi\reshade-shaders\Shaders\EyeAdaption.fx"
#line 1 "D:\Games\Kenshi\reshade-shaders\Shaders\ReShadeUI.fxh"
#line 11 "D:\Games\Kenshi\reshade-shaders\Shaders\EyeAdaption.fx"
#line 14
uniform float fAdp_Delay <
ui_label = "Adaption Delay";
ui_tooltip = "How fast the image adapts to brightness changes.\n"
"0 = instantanous adaption\n"
"2 = very slow adaption";
ui_category = "General settings";
ui_type = "drag";
ui_min = 0.0;
ui_max = 2.0;
> = 1.6;
#line 25
uniform float fAdp_TriggerRadius <
ui_label = "Adaption TriggerRadius";
ui_tooltip = "Screen area, whose average brightness triggers adaption.\n"
"1 = only the center of the image is used\n"
"7 = the whole image is used";
ui_category = "General settings";
ui_type = "drag";
ui_min = 1.0;
ui_max = 7.0;
ui_step = 0.1;
> = 6.0;
#line 37
uniform float fAdp_YAxisFocalPoint <
ui_label = "Y Axis Focal Point";
ui_tooltip = "Where along the Y Axis the Adaption TriggerRadius applies.\n"
"0 = Top of the screen\n"
"1 = Bottom of the screen";
ui_category = "General settings";
ui_type = "drag";
ui_min = 0.0;
ui_max = 1.0;
> = 0.5;
#line 48
uniform float fAdp_Equilibrium <
ui_label = "Adaption Equilibrium";
ui_tooltip = "The value of image brightness for which there is no brightness adaption.\n"
"0 = late brightening, early darkening\n"
"1 = early brightening, late darkening";
ui_category = "General settings";
ui_type = "drag";
ui_min = 0.0;
ui_max = 1.0;
> = 0.5;
#line 59
uniform float fAdp_Strength <
ui_label = "Adaption Strength";
ui_tooltip = "Base strength of brightness adaption.\n";
ui_category = "General settings";
ui_type = "drag";
ui_min = 0.0;
ui_max = 2.0;
> = 1.0;
#line 68
uniform float fAdp_BrightenHighlights <
ui_label = "Brighten Highlights";
ui_tooltip = "Brightening strength for highlights.";
ui_category = "Brightening";
ui_type = "drag";
ui_min = 0.0;
ui_max = 1.0;
> = 0.1;
#line 77
uniform float fAdp_BrightenMidtones <
ui_label = "Brighten Midtones";
ui_tooltip = "Brightening strength for midtones.";
ui_category = "Brightening";
ui_type = "drag";
ui_min = 0.0;
ui_max = 1.0;
> = 0.2;
#line 86
uniform float fAdp_BrightenShadows <
ui_label = "Brighten Shadows";
ui_tooltip = "Brightening strength for shadows.\n"
"Set this to 0 to preserve pure black.";
ui_category = "Brightening";
ui_type = "drag";
ui_min = 0.0;
ui_max = 1.0;
> = 0.1;
#line 96
uniform float fAdp_DarkenHighlights <
ui_label = "Darken Highlights";
ui_tooltip = "Darkening strength for highlights.\n"
"Set this to 0 to preserve pure white.";
ui_category = "Darkening";
ui_type = "drag";
ui_min = 0.0;
ui_max = 1.0;
> = 0.1;
#line 106
uniform float fAdp_DarkenMidtones <
ui_label = "Darken Midtones";
ui_tooltip = "Darkening strength for midtones.";
ui_category = "Darkening";
ui_type = "drag";
ui_min = 0.0;
ui_max = 1.0;
> = 0.2;
#line 115
uniform float fAdp_DarkenShadows <
ui_label = "Darken Shadows";
ui_tooltip = "Darkening strength for shadows.";
ui_category = "Darkening";
ui_type = "drag";
ui_min = 0.0;
ui_max = 1.0;
> = 0.1;
#line 127
uniform float Frametime < source = "frametime";>;
#line 130
texture2D TexLuma { Width = 256; Height = 256; Format = R8; MipLevels = 7; };
texture2D TexAvgLuma { Format = R16F; };
texture2D TexAvgLumaLast { Format = R16F; };
#line 134
sampler SamplerLuma { Texture = TexLuma; };
sampler SamplerAvgLuma { Texture = TexAvgLuma; };
sampler SamplerAvgLumaLast { Texture = TexAvgLumaLast; };
#line 139
float PS_Luma(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float4 color = tex2Dlod(ReShade::BackBuffer, float4(texcoord, 0, 0));
float luma = dot(color.xyz,  float3(0.212656, 0.715158, 0.072186));
return luma;
}
#line 146
float PS_AvgLuma(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float avgLumaCurrFrame = tex2Dlod(SamplerLuma, float4(fAdp_YAxisFocalPoint.xx, 0, fAdp_TriggerRadius)).x;
float avgLumaLastFrame = tex2Dlod(SamplerAvgLumaLast, float4(0.0.xx, 0, 0)).x;
float delay = sign(fAdp_Delay) * saturate(0.815 + fAdp_Delay / 10.0 - Frametime / 1000.0);
float avgLuma = lerp(avgLumaCurrFrame, avgLumaLastFrame, delay);
return avgLuma;
}
#line 155
float AdaptionDelta(float luma, float strengthMidtones, float strengthShadows, float strengthHighlights)
{
float midtones = (4.0 * strengthMidtones - strengthHighlights - strengthShadows) * luma * (1.0 - luma);
float shadows = strengthShadows * (1.0 - luma);
float highlights = strengthHighlights * luma;
float delta = midtones + shadows + highlights;
return delta;
}
#line 164
float4 PS_Adaption(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float4 color = tex2Dlod(ReShade::BackBuffer, float4(texcoord, 0, 0));
float avgLuma = tex2Dlod(SamplerAvgLuma, float4(0.0.xx, 0, 0)).x;
#line 169
color.xyz = pow(abs(color.xyz), 1.0/2.2);
float luma = dot(color.xyz,  float3(0.212656, 0.715158, 0.072186));
float3 chroma = color.xyz - luma;
#line 173
float avgLumaAdjusted = lerp (avgLuma, 1.4 * avgLuma / (0.4 + avgLuma), fAdp_Equilibrium);
float delta = 0;
#line 176
float curve = fAdp_Strength * 10.0 * pow(abs(avgLumaAdjusted - 0.5), 4.0);
if (avgLumaAdjusted < 0.5) {
delta = AdaptionDelta(luma, fAdp_BrightenMidtones, fAdp_BrightenShadows, fAdp_BrightenHighlights);
} else {
delta = -AdaptionDelta(luma, fAdp_DarkenMidtones, fAdp_DarkenShadows, fAdp_DarkenHighlights);
}
delta *= curve;
#line 184
luma += delta;
color.xyz = saturate(luma + chroma);
color.xyz = pow(abs(color.xyz), 2.2);
#line 188
return color;
}
#line 191
float PS_StoreAvgLuma(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float avgLuma = tex2Dlod(SamplerAvgLuma, float4(0.0.xx, 0, 0)).x;
return avgLuma;
}
#line 198
technique EyeAdaption {
#line 200
pass Luma
{
VertexShader = PostProcessVS;
PixelShader = PS_Luma;
RenderTarget = TexLuma;
}
#line 207
pass AvgLuma
{
VertexShader = PostProcessVS;
PixelShader = PS_AvgLuma;
RenderTarget = TexAvgLuma;
}
#line 214
pass Adaption
{
VertexShader = PostProcessVS;
PixelShader = PS_Adaption;
}
#line 220
pass StoreAvgLuma
{
VertexShader = PostProcessVS;
PixelShader = PS_StoreAvgLuma;
RenderTarget = TexAvgLumaLast;
}
}

