#line 1 "unknown"

#line 1 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\Chromakey.fx"
#line 1 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\ReShade.fxh"
#line 50
namespace ReShade
{
#line 61
static const float AspectRatio = 1280 * (1.0 / 720);
static const float2 PixelSize = float2((1.0 / 1280), (1.0 / 720));
static const float2 ScreenSize = float2(1280, 720);
#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 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\Chromakey.fx"
#line 1 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\ReShadeUI.fxh"
#line 11 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\Chromakey.fx"
#line 18
uniform float Threshold <      ui_type = "slider"; 
ui_min = 0.0; ui_max = 0.999; ui_step = 0.001;
ui_category = "Distance adjustment";
> = 0.5;
#line 23
uniform bool RadialX <
ui_label = "Horizontally radial depth";
ui_category = "Radial distance";
> = false;
uniform bool RadialY <
ui_label = "Vertically radial depth";
ui_category = "Radial distance";
> = false;
#line 32
uniform int FOV <        ui_type = "slider"; 
ui_label = "FOV (horizontal)";
ui_tooltip = "Field of view in degrees";
#line 38
ui_min = 0; ui_max = 170;
ui_category = "Radial distance";
> = 90;
#line 42
uniform int Pass <        ui_type = "radio"; 
ui_label = "Keying type";
ui_items = "Background key\0Foreground key\0";
ui_category = "Direction adjustment";
> = 0;
#line 48
uniform int Color <        ui_type = "radio"; 
ui_label = "Keying color";
ui_tooltip = "Ultimatte(tm) Super Blue and Green are industry standard colors for chromakey";
ui_items = "Super Blue Ultimatte(tm)\0Green Ultimatte(tm)\0Custom\0";
ui_category = "Color settings";
> = 1;
#line 55
uniform float3 CustomColor <      ui_type = "color"; 
ui_label = "Custom color";
ui_category = "Color settings";
> = float3(1.0, 0.0, 0.0);
#line 60
uniform bool AntiAliased <
ui_label = "Anti-aliased mask";
ui_tooltip = "Disabling this option will reduce masking gaps";
ui_category = "Color settings";
> = true;
#line 71
float MaskAA(float2 texcoord)
{
#line 74
float Depth = ReShade::GetLinearizedDepth(texcoord);
#line 77
float2 Size;
Size.x = tan(radians(FOV*0.5));
Size.y = Size.x /  (1280 * (1.0 / 720));
if(RadialX) Depth *= length(float2((texcoord.x-0.5)*Size.x, 1.0));
if(RadialY) Depth *= length(float2((texcoord.y-0.5)*Size.y, 1.0));
#line 84
if(!AntiAliased) return step(Threshold, Depth);
#line 87
float hPixel = fwidth(Depth)*0.5;
#line 89
return smoothstep(Threshold-hPixel, Threshold+hPixel, Depth);
}
#line 97
float3 ChromakeyPS(float4 vois : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
#line 100
float3 Screen;
switch(Color)
{
case 0:{ Screen = float3(0.07, 0.18, 0.72); break; } 
case 1:{ Screen = float3(0.29, 0.84, 0.36); break; } 
case 2:{ Screen = CustomColor;              break; } 
}
#line 109
float DepthMask = MaskAA(texcoord);
if(bool(Pass)) DepthMask = 1.0-DepthMask;
#line 112
return lerp(tex2D(ReShade::BackBuffer, texcoord).rgb, Screen, DepthMask);
}
#line 120
technique Chromakey < ui_tooltip = "Generate green-screen wall based of depth"; >
{
pass
{
VertexShader = PostProcessVS;
PixelShader = ChromakeyPS;
}
}

