#line 1 "unknown"

#line 1 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\SMAA.fx"
#line 1 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\ReShadeUI.fxh"
#line 23 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\SMAA.fx"
#line 25
uniform int EdgeDetectionType <        ui_type = "combo"; 
ui_items = "Luminance edge detection\0Color edge detection\0Depth edge detection\0";
ui_label = "Edge Detection Type";
> = 1;
#line 31
uniform float EdgeDetectionThreshold <      ui_type = "drag"; 
ui_min = 0.05; ui_max = 0.20; ui_step = 0.001;
ui_tooltip = "Edge detection threshold. If SMAA misses some edges try lowering this slightly.";
ui_label = "Edge Detection Threshold";
> = 0.10;
#line 37
uniform float DepthEdgeDetectionThreshold <      ui_type = "drag"; 
ui_min = 0.001; ui_max = 0.10; ui_step = 0.001;
ui_tooltip = "Depth Edge detection threshold. If SMAA misses some edges try lowering this slightly.";
ui_label = "Depth Edge Detection Threshold";
> = 0.01;
#line 43
uniform int MaxSearchSteps <        ui_type = "slider"; 
ui_min = 0; ui_max = 112;
ui_label = "Max Search Steps";
ui_tooltip = "Determines the radius SMAA will search for aliased edges.";
> = 32;
#line 49
uniform int MaxSearchStepsDiagonal <        ui_type = "slider"; 
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;
#line 55
uniform int CornerRounding <        ui_type = "slider"; 
ui_min = 0; ui_max = 100;
ui_label = "Corner Rounding";
ui_tooltip = "Determines the percent of anti-aliasing to apply to corners.";
> = 25;
#line 61
uniform bool PredicationEnabled <       ui_type = "input"; 
ui_label = "Enable Predicated Thresholding";
> = false;
#line 65
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;
#line 71
uniform float PredicationScale <      ui_type = "slider"; 
ui_min = 1; ui_max = 8;
ui_tooltip = "How much to scale the global threshold used for luma or color edge.";
ui_label = "Predication Scale";
> = 2.0;
#line 77
uniform float PredicationStrength <      ui_type = "slider"; 
ui_min = 0; ui_max = 4;
ui_tooltip = "How much to locally decrease the threshold.";
ui_label = "Predication Strength";
> = 0.4;
#line 84
uniform int DebugOutput <        ui_type = "combo"; 
ui_items = "None\0View edges\0View weights\0";
ui_label = "Debug Output";
> = false;
#line 1 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\SMAA.fxh"
#line 599
float3 SMAAGatherNeighbours(float2 texcoord,
float4 offset[3],
 sampler tex) {
#line 603
return    tex2DgatherR(tex, texcoord + float4((1.0 / 1360), (1.0 / 768), 1360, 768).xy * float2(-0.5, -0.5)).grb;
#line 610
}
#line 615
float2 SMAACalculatePredicatedThreshold(float2 texcoord,
float4 offset[3],
 sampler predicationTex) {
float3 neighbours = SMAAGatherNeighbours(texcoord, offset,  predicationTex);
float2 delta = abs(neighbours.xx - neighbours.yz);
float2 edges = step( PredicationThreshold, delta);
return  PredicationScale *  EdgeDetectionThreshold * (1.0 -  PredicationStrength * edges);
}
#line 627
void SMAAMovc(bool2 cond, inout float2 variable, float2 value) {
 [flatten] if (cond.x) variable.x = value.x;
 [flatten] if (cond.y) variable.y = value.y;
}
#line 632
void SMAAMovc(bool4 cond, inout float4 variable, float4 value) {
SMAAMovc(cond.xy, variable.xy, value.xy);
SMAAMovc(cond.zw, variable.zw, value.zw);
}
#line 645
void SMAAEdgeDetectionVS(float2 texcoord,
out float4 offset[3]) {
offset[0] = mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xyxy, float4(-1.0, 0.0, 0.0, -1.0), texcoord.xyxy);
offset[1] = mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xyxy, float4( 1.0, 0.0, 0.0,  1.0), texcoord.xyxy);
offset[2] = mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xyxy, float4(-2.0, 0.0, 0.0, -2.0), texcoord.xyxy);
}
#line 655
void SMAABlendingWeightCalculationVS(float2 texcoord,
out float2 pixcoord,
out float4 offset[3]) {
pixcoord = texcoord *  float4((1.0 / 1360), (1.0 / 768), 1360, 768).zw;
#line 661
offset[0] = mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xyxy, float4(-0.25, -0.125,  1.25, -0.125), texcoord.xyxy);
offset[1] = mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xyxy, float4(-0.125, -0.25, -0.125,  1.25), texcoord.xyxy);
#line 665
offset[2] = mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xxyy,
float4(-2.0, 2.0, -2.0, 2.0) * float( MaxSearchSteps),
float4(offset[0].xz, offset[1].yw));
}
#line 673
void SMAANeighborhoodBlendingVS(float2 texcoord,
out float4 offset) {
offset = mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xyxy, float4( 1.0, 0.0, 0.0,  1.0), texcoord.xyxy);
}
#line 689
float2 SMAALumaEdgeDetectionPS(float2 texcoord,
float4 offset[3],
 sampler colorTex
) {
#line 694
float2 threshold = float2( EdgeDetectionThreshold,  EdgeDetectionThreshold);
#line 697
float3 weights = float3(0.2126, 0.7152, 0.0722);
float L = dot(  tex2D(colorTex, texcoord).rgb, weights);
#line 700
float Lleft = dot(  tex2D(colorTex, offset[0].xy).rgb, weights);
float Ltop  = dot(  tex2D(colorTex, offset[0].zw).rgb, weights);
#line 704
float4 delta;
delta.xy = abs(L - float2(Lleft, Ltop));
float2 edges = step(threshold, delta.xy);
#line 709
if (dot(edges, float2(1.0, 1.0)) == 0.0)
discard;
#line 713
float Lright = dot(  tex2D(colorTex, offset[1].xy).rgb, weights);
float Lbottom  = dot(  tex2D(colorTex, offset[1].zw).rgb, weights);
delta.zw = abs(L - float2(Lright, Lbottom));
#line 718
float2 maxDelta = max(delta.xy, delta.zw);
#line 721
float Lleftleft = dot(  tex2D(colorTex, offset[2].xy).rgb, weights);
float Ltoptop = dot(  tex2D(colorTex, offset[2].zw).rgb, weights);
delta.zw = abs(float2(Lleft, Ltop) - float2(Lleftleft, Ltoptop));
#line 726
maxDelta = max(maxDelta.xy, delta.zw);
float finalDelta = max(maxDelta.x, maxDelta.y);
#line 730
edges.xy *= step(finalDelta,  2.0 * delta.xy);
#line 732
return edges;
}
#line 735
float2 SMAALumaEdgePredicationDetectionPS(float2 texcoord,
float4 offset[3],
 sampler colorTex
,  sampler predicationTex
) {
#line 741
float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset,  predicationTex);
#line 744
float3 weights = float3(0.2126, 0.7152, 0.0722);
float L = dot(  tex2D(colorTex, texcoord).rgb, weights);
#line 747
float Lleft = dot(  tex2D(colorTex, offset[0].xy).rgb, weights);
float Ltop  = dot(  tex2D(colorTex, offset[0].zw).rgb, weights);
#line 751
float4 delta;
delta.xy = abs(L - float2(Lleft, Ltop));
float2 edges = step(threshold, delta.xy);
#line 756
if (dot(edges, float2(1.0, 1.0)) == 0.0)
discard;
#line 760
float Lright = dot(  tex2D(colorTex, offset[1].xy).rgb, weights);
float Lbottom  = dot(  tex2D(colorTex, offset[1].zw).rgb, weights);
delta.zw = abs(L - float2(Lright, Lbottom));
#line 765
float2 maxDelta = max(delta.xy, delta.zw);
#line 768
float Lleftleft = dot(  tex2D(colorTex, offset[2].xy).rgb, weights);
float Ltoptop = dot(  tex2D(colorTex, offset[2].zw).rgb, weights);
delta.zw = abs(float2(Lleft, Ltop) - float2(Lleftleft, Ltoptop));
#line 773
maxDelta = max(maxDelta.xy, delta.zw);
float finalDelta = max(maxDelta.x, maxDelta.y);
#line 777
edges.xy *= step(finalDelta,  2.0 * delta.xy);
#line 779
return edges;
}
#line 788
float2 SMAAColorEdgeDetectionPS(float2 texcoord,
float4 offset[3],
 sampler colorTex
) {
#line 793
float2 threshold = float2( EdgeDetectionThreshold,  EdgeDetectionThreshold);
#line 796
float4 delta;
float3 C =   tex2D(colorTex, texcoord).rgb;
#line 799
float3 Cleft =   tex2D(colorTex, offset[0].xy).rgb;
float3 t = abs(C - Cleft);
delta.x = max(max(t.r, t.g), t.b);
#line 803
float3 Ctop  =   tex2D(colorTex, offset[0].zw).rgb;
t = abs(C - Ctop);
delta.y = max(max(t.r, t.g), t.b);
#line 808
float2 edges = step(threshold, delta.xy);
#line 811
if (dot(edges, float2(1.0, 1.0)) == 0.0)
discard;
#line 815
float3 Cright =   tex2D(colorTex, offset[1].xy).rgb;
t = abs(C - Cright);
delta.z = max(max(t.r, t.g), t.b);
#line 819
float3 Cbottom  =   tex2D(colorTex, offset[1].zw).rgb;
t = abs(C - Cbottom);
delta.w = max(max(t.r, t.g), t.b);
#line 824
float2 maxDelta = max(delta.xy, delta.zw);
#line 827
float3 Cleftleft  =   tex2D(colorTex, offset[2].xy).rgb;
t = abs(Cleft - Cleftleft);
delta.z = max(max(t.r, t.g), t.b);
#line 831
float3 Ctoptop =   tex2D(colorTex, offset[2].zw).rgb;
t = abs(Ctop - Ctoptop);
delta.w = max(max(t.r, t.g), t.b);
#line 836
maxDelta = max(maxDelta.xy, delta.zw);
float finalDelta = max(maxDelta.x, maxDelta.y);
#line 840
edges.xy *= step(finalDelta,  2.0 * delta.xy);
#line 842
return edges;
}
#line 845
float2 SMAAColorEdgePredicationDetectionPS(float2 texcoord,
float4 offset[3],
 sampler colorTex
,  sampler predicationTex
) {
#line 851
float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, predicationTex);
#line 854
float4 delta;
float3 C =   tex2D(colorTex, texcoord).rgb;
#line 857
float3 Cleft =   tex2D(colorTex, offset[0].xy).rgb;
float3 t = abs(C - Cleft);
delta.x = max(max(t.r, t.g), t.b);
#line 861
float3 Ctop  =   tex2D(colorTex, offset[0].zw).rgb;
t = abs(C - Ctop);
delta.y = max(max(t.r, t.g), t.b);
#line 866
float2 edges = step(threshold, delta.xy);
#line 869
if (dot(edges, float2(1.0, 1.0)) == 0.0)
discard;
#line 873
float3 Cright =   tex2D(colorTex, offset[1].xy).rgb;
t = abs(C - Cright);
delta.z = max(max(t.r, t.g), t.b);
#line 877
float3 Cbottom  =   tex2D(colorTex, offset[1].zw).rgb;
t = abs(C - Cbottom);
delta.w = max(max(t.r, t.g), t.b);
#line 882
float2 maxDelta = max(delta.xy, delta.zw);
#line 885
float3 Cleftleft  =   tex2D(colorTex, offset[2].xy).rgb;
t = abs(Cleft - Cleftleft);
delta.z = max(max(t.r, t.g), t.b);
#line 889
float3 Ctoptop =   tex2D(colorTex, offset[2].zw).rgb;
t = abs(Ctop - Ctoptop);
delta.w = max(max(t.r, t.g), t.b);
#line 894
maxDelta = max(maxDelta.xy, delta.zw);
float finalDelta = max(maxDelta.x, maxDelta.y);
#line 898
edges.xy *= step(finalDelta,  2.0 * delta.xy);
#line 900
return edges;
}
#line 906
float2 SMAADepthEdgeDetectionPS(float2 texcoord,
float4 offset[3],
 sampler depthTex) {
float3 neighbours = SMAAGatherNeighbours(texcoord, offset,  depthTex);
float2 delta = abs(neighbours.xx - float2(neighbours.y, neighbours.z));
float2 edges = step( DepthEdgeDetectionThreshold, delta);
#line 913
if (dot(edges, float2(1.0, 1.0)) == 0.0)
discard;
#line 916
return edges;
}
#line 927
float2 SMAADecodeDiagBilinearAccess(float2 e) {
#line 941
e.r = e.r * abs(5.0 * e.r - 5.0 * 0.75);
return round(e);
}
#line 945
float4 SMAADecodeDiagBilinearAccess(float4 e) {
e.rb = e.rb * abs(5.0 * e.rb - 5.0 * 0.75);
return round(e);
}
#line 953
float2 SMAASearchDiag1( sampler edgesTex, float2 texcoord, float2 dir, out float2 e) {
float4 coord = float4(texcoord, -1.0, 1.0);
float3 t = float3( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xy, 1.0);
while (coord.z < float( MaxSearchStepsDiagonal - 1) &&
coord.w > 0.9) {
coord.xyz = mad(t, float3(dir, 1.0), coord.xyz);
e =  tex2Dlod(edgesTex, float4(coord.xy, coord.xy)).rg;
coord.w = dot(e, float2(0.5, 0.5));
}
return coord.zw;
}
#line 965
float2 SMAASearchDiag2( sampler edgesTex, float2 texcoord, float2 dir, out float2 e) {
float4 coord = float4(texcoord, -1.0, 1.0);
coord.x += 0.25 *  float4((1.0 / 1360), (1.0 / 768), 1360, 768).x; 
float3 t = float3( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xy, 1.0);
while (coord.z < float( MaxSearchStepsDiagonal - 1) &&
coord.w > 0.9) {
coord.xyz = mad(t, float3(dir, 1.0), coord.xyz);
#line 975
e =  tex2Dlod(edgesTex, float4(coord.xy, coord.xy)).rg;
e = SMAADecodeDiagBilinearAccess(e);
#line 982
coord.w = dot(e, float2(0.5, 0.5));
}
return coord.zw;
}
#line 991
float2 SMAAAreaDiag( sampler areaTex, float2 dist, float2 e, float offset) {
float2 texcoord = mad(float2( 20,  20), e, dist);
#line 995
texcoord = mad( (1.0 / float2(160.0, 560.0)), texcoord, 0.5 *  (1.0 / float2(160.0, 560.0)));
#line 998
texcoord.x += 0.5;
#line 1001
texcoord.y +=  (1.0 / 7.0) * offset;
#line 1004
return   tex2Dlod(areaTex, float4(texcoord, texcoord)).rg;
}
#line 1010
float2 SMAACalculateDiagWeights( sampler edgesTex,  sampler areaTex, float2 texcoord, float2 e, float4 subsampleIndices) {
float2 weights = float2(0.0, 0.0);
#line 1014
float4 d;
float2 end;
if (e.r > 0.0) {
d.xz = SMAASearchDiag1( edgesTex, texcoord, float2(-1.0,  1.0), end);
d.x += float(end.y > 0.9);
} else
d.xz = float2(0.0, 0.0);
d.yw = SMAASearchDiag1( edgesTex, texcoord, float2(1.0, -1.0), end);
#line 1023
 [branch]
if (d.x + d.y > 2.0) { 
#line 1026
float4 coords = mad(float4(-d.x + 0.25, d.x, d.y, -d.y - 0.25),  float4((1.0 / 1360), (1.0 / 768), 1360, 768).xyxy, texcoord.xyxy);
float4 c;
c.xy =   tex2Dlod(edgesTex, float4(coords.xy, coords.xy), int2(-1, 0)).rg;
c.zw =   tex2Dlod(edgesTex, float4(coords.zw, coords.zw), int2( 1, 0)).rg;
c.yxwz = SMAADecodeDiagBilinearAccess(c.xyzw);
#line 1041
float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw);
#line 1044
SMAAMovc(bool2(step(0.9, d.zw)), cc, float2(0.0, 0.0));
#line 1047
weights += SMAAAreaDiag( areaTex, d.xy, cc, subsampleIndices.z);
}
#line 1051
d.xz = SMAASearchDiag2( edgesTex, texcoord, float2(-1.0, -1.0), end);
if (  tex2Dlod(edgesTex, float4(texcoord, texcoord), int2(1, 0)).r > 0.0) {
d.yw = SMAASearchDiag2( edgesTex, texcoord, float2(1.0, 1.0), end);
d.y += float(end.y > 0.9);
} else
d.yw = float2(0.0, 0.0);
#line 1058
 [branch]
if (d.x + d.y > 2.0) { 
#line 1061
float4 coords = mad(float4(-d.x, -d.x, d.y, d.y),  float4((1.0 / 1360), (1.0 / 768), 1360, 768).xyxy, texcoord.xyxy);
float4 c;
c.x  =   tex2Dlod(edgesTex, float4(coords.xy, coords.xy), int2(-1, 0)).g;
c.y  =   tex2Dlod(edgesTex, float4(coords.xy, coords.xy), int2( 0, -1)).r;
c.zw =   tex2Dlod(edgesTex, float4(coords.zw, coords.zw), int2( 1, 0)).gr;
float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw);
#line 1069
SMAAMovc(bool2(step(0.9, d.zw)), cc, float2(0.0, 0.0));
#line 1072
weights += SMAAAreaDiag( areaTex, d.xy, cc, subsampleIndices.w).gr;
}
#line 1075
return weights;
}
#line 1088
float SMAASearchLength( sampler searchTex, float2 e, float offset) {
#line 1091
float2 scale =  float2(66.0, 33.0) * float2(0.5, -1.0);
float2 bias =  float2(66.0, 33.0) * float2(offset, 1.0);
#line 1095
scale += float2(-1.0,  1.0);
bias  += float2( 0.5, -0.5);
#line 1100
scale *= 1.0 /  float2(64.0, 16.0);
bias *= 1.0 /  float2(64.0, 16.0);
#line 1104
return   tex2Dlod(searchTex, float4(mad(scale, e, bias), mad(scale, e, bias))).r;
}
#line 1110
float SMAASearchXLeft( sampler edgesTex,  sampler searchTex, float2 texcoord, float end) {
#line 1118
float2 e = float2(0.0, 1.0);
while (texcoord.x > end &&
e.g > 0.8281 && 
e.r == 0.0) { 
e =  tex2Dlod(edgesTex, float4(texcoord, texcoord)).rg;
texcoord = mad(-float2(2.0, 0.0),  float4((1.0 / 1360), (1.0 / 768), 1360, 768).xy, texcoord);
}
#line 1126
float offset = mad(-(255.0 / 127.0), SMAASearchLength( searchTex, e, 0.0), 3.25);
return mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).x, offset, texcoord.x);
#line 1140
}
#line 1142
float SMAASearchXRight( sampler edgesTex,  sampler searchTex, float2 texcoord, float end) {
float2 e = float2(0.0, 1.0);
while (texcoord.x < end &&
e.g > 0.8281 && 
e.r == 0.0) { 
e =  tex2Dlod(edgesTex, float4(texcoord, texcoord)).rg;
texcoord = mad(float2(2.0, 0.0),  float4((1.0 / 1360), (1.0 / 768), 1360, 768).xy, texcoord);
}
float offset = mad(-(255.0 / 127.0), SMAASearchLength( searchTex, e, 0.5), 3.25);
return mad(- float4((1.0 / 1360), (1.0 / 768), 1360, 768).x, offset, texcoord.x);
}
#line 1154
float SMAASearchYUp( sampler edgesTex,  sampler searchTex, float2 texcoord, float end) {
float2 e = float2(1.0, 0.0);
while (texcoord.y > end &&
e.r > 0.8281 && 
e.g == 0.0) { 
e =  tex2Dlod(edgesTex, float4(texcoord, texcoord)).rg;
texcoord = mad(-float2(0.0, 2.0),  float4((1.0 / 1360), (1.0 / 768), 1360, 768).xy, texcoord);
}
float offset = mad(-(255.0 / 127.0), SMAASearchLength( searchTex, e.gr, 0.0), 3.25);
return mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).y, offset, texcoord.y);
}
#line 1166
float SMAASearchYDown( sampler edgesTex,  sampler searchTex, float2 texcoord, float end) {
float2 e = float2(1.0, 0.0);
while (texcoord.y < end &&
e.r > 0.8281 && 
e.g == 0.0) { 
e =  tex2Dlod(edgesTex, float4(texcoord, texcoord)).rg;
texcoord = mad(float2(0.0, 2.0),  float4((1.0 / 1360), (1.0 / 768), 1360, 768).xy, texcoord);
}
float offset = mad(-(255.0 / 127.0), SMAASearchLength( searchTex, e.gr, 0.5), 3.25);
return mad(- float4((1.0 / 1360), (1.0 / 768), 1360, 768).y, offset, texcoord.y);
}
#line 1182
float2 SMAAArea( sampler areaTex, float2 dist, float e1, float e2, float offset) {
#line 1184
float2 texcoord = mad(float2( 16,  16), round(4.0 * float2(e1, e2)), dist);
#line 1187
texcoord = mad( (1.0 / float2(160.0, 560.0)), texcoord, 0.5 *  (1.0 / float2(160.0, 560.0)));
#line 1190
texcoord.y = mad( (1.0 / 7.0), offset, texcoord.y);
#line 1193
return   tex2Dlod(areaTex, float4(texcoord, texcoord)).rg;
}
#line 1199
void SMAADetectHorizontalCornerPattern( sampler edgesTex, inout float2 weights, float4 texcoord, float2 d) {
#line 1201
float2 leftRight = step(d.xy, d.yx);
float2 rounding = (1.0 -  (float( CornerRounding) / 100.0)) * leftRight;
#line 1204
rounding /= leftRight.x + leftRight.y; 
#line 1206
float2 factor = float2(1.0, 1.0);
factor.x -= rounding.x *   tex2Dlod(edgesTex, float4(texcoord.xy, texcoord.xy), int2(0, 1)).r;
factor.x -= rounding.y *   tex2Dlod(edgesTex, float4(texcoord.zw, texcoord.zw), int2(1, 1)).r;
factor.y -= rounding.x *   tex2Dlod(edgesTex, float4(texcoord.xy, texcoord.xy), int2(0, -2)).r;
factor.y -= rounding.y *   tex2Dlod(edgesTex, float4(texcoord.zw, texcoord.zw), int2(1, -2)).r;
#line 1212
weights *= saturate(factor);
#line 1214
}
#line 1216
void SMAADetectVerticalCornerPattern( sampler edgesTex, inout float2 weights, float4 texcoord, float2 d) {
#line 1218
float2 leftRight = step(d.xy, d.yx);
float2 rounding = (1.0 -  (float( CornerRounding) / 100.0)) * leftRight;
#line 1221
rounding /= leftRight.x + leftRight.y;
#line 1223
float2 factor = float2(1.0, 1.0);
factor.x -= rounding.x *   tex2Dlod(edgesTex, float4(texcoord.xy, texcoord.xy), int2( 1, 0)).g;
factor.x -= rounding.y *   tex2Dlod(edgesTex, float4(texcoord.zw, texcoord.zw), int2( 1, 1)).g;
factor.y -= rounding.x *   tex2Dlod(edgesTex, float4(texcoord.xy, texcoord.xy), int2(-2, 0)).g;
factor.y -= rounding.y *   tex2Dlod(edgesTex, float4(texcoord.zw, texcoord.zw), int2(-2, 1)).g;
#line 1229
weights *= saturate(factor);
#line 1231
}
#line 1236
float4 SMAABlendingWeightCalculationPS(float2 texcoord,
float2 pixcoord,
float4 offset[3],
 sampler edgesTex,
 sampler areaTex,
 sampler searchTex,
float4 subsampleIndices) { 
float4 weights = float4(0.0, 0.0, 0.0, 0.0);
#line 1245
float2 e =  tex2D(edgesTex, texcoord).rg;
#line 1247
 [branch]
if (e.g > 0.0) { 
#line 1252
weights.rg = SMAACalculateDiagWeights( edgesTex,  areaTex, texcoord, e, subsampleIndices);
#line 1256
 [branch]
if (weights.r == -weights.g) { 
#line 1260
float2 d;
#line 1263
float3 coords;
coords.x = SMAASearchXLeft( edgesTex,  searchTex, offset[0].xy, offset[2].x);
coords.y = offset[1].y; 
d.x = coords.x;
#line 1271
float e1 =  tex2Dlod(edgesTex, float4(coords.xy, coords.xy)).r;
#line 1274
coords.z = SMAASearchXRight( edgesTex,  searchTex, offset[0].zw, offset[2].y);
d.y = coords.z;
#line 1279
d = abs(round(mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).zz, d, -pixcoord.xx)));
#line 1283
float2 sqrt_d = sqrt(d);
#line 1286
float e2 =   tex2Dlod(edgesTex, float4(coords.zy, coords.zy), int2(1, 0)).r;
#line 1290
weights.rg = SMAAArea( areaTex, sqrt_d, e1, e2, subsampleIndices.y);
#line 1293
coords.y = texcoord.y;
SMAADetectHorizontalCornerPattern( edgesTex, weights.rg, coords.xyzy, d);
#line 1297
} else
e.r = 0.0; 
#line 1300
}
#line 1302
 [branch]
if (e.r > 0.0) { 
float2 d;
#line 1307
float3 coords;
coords.y = SMAASearchYUp( edgesTex,  searchTex, offset[1].xy, offset[2].z);
coords.x = offset[0].x; 
d.x = coords.y;
#line 1313
float e1 =  tex2Dlod(edgesTex, float4(coords.xy, coords.xy)).g;
#line 1316
coords.z = SMAASearchYDown( edgesTex,  searchTex, offset[1].zw, offset[2].w);
d.y = coords.z;
#line 1320
d = abs(round(mad( float4((1.0 / 1360), (1.0 / 768), 1360, 768).ww, d, -pixcoord.yy)));
#line 1324
float2 sqrt_d = sqrt(d);
#line 1327
float e2 =   tex2Dlod(edgesTex, float4(coords.xz, coords.xz), int2(0, 1)).g;
#line 1330
weights.ba = SMAAArea( areaTex, sqrt_d, e1, e2, subsampleIndices.x);
#line 1333
coords.x = texcoord.x;
SMAADetectVerticalCornerPattern( edgesTex, weights.ba, coords.xyxz, d);
}
#line 1337
return weights;
}
#line 1343
float4 SMAANeighborhoodBlendingPS(float2 texcoord,
float4 offset,
 sampler colorTex,
 sampler blendTex
#line 1350
) {
#line 1352
float4 a;
a.x =  tex2D(blendTex, offset.xy).a; 
a.y =  tex2D(blendTex, offset.zw).g; 
a.wz =  tex2D(blendTex, texcoord).xz; 
#line 1358
 [branch]
if (dot(a, float4(1.0, 1.0, 1.0, 1.0)) < 1e-5) {
float4 color =  tex2Dlod(colorTex, float4(texcoord, texcoord));
#line 1369
return color;
} else {
bool h = max(a.x, a.z) > max(a.y, a.w); 
#line 1374
float4 blendingOffset = float4(0.0, a.y, 0.0, a.w);
float2 blendingWeight = a.yw;
SMAAMovc(bool4(h, h, h, h), blendingOffset, float4(a.x, 0.0, a.z, 0.0));
SMAAMovc(bool2(h, h), blendingWeight, a.xz);
blendingWeight /= dot(blendingWeight, float2(1.0, 1.0));
#line 1381
float4 blendingCoord = mad(blendingOffset, float4( float4((1.0 / 1360), (1.0 / 768), 1360, 768).xy, - float4((1.0 / 1360), (1.0 / 768), 1360, 768).xy), texcoord.xyxy);
#line 1385
float4 color = blendingWeight.x *  tex2Dlod(colorTex, float4(blendingCoord.xy, blendingCoord.xy));
color += blendingWeight.y *  tex2Dlod(colorTex, float4(blendingCoord.zw, blendingCoord.zw));
#line 1397
return color;
}
}
#line 1404
float4 SMAAResolvePS(float2 texcoord,
 sampler currentColorTex,
 sampler previousColorTex
#line 1410
) {
#line 1430
float4 current =   tex2D(currentColorTex, texcoord);
float4 previous =   tex2D(previousColorTex, texcoord);
return lerp(current, previous, 0.5);
#line 1434
}
#line 119 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\SMAA.fx"
#line 1 "C:\GOG 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 120 "C:\GOG Games\Kenshi\reshade-shaders\Shaders\SMAA.fx"
#line 124
texture depthTex < pooled = true; >
{
Width = 1360;
Height = 768;
Format = R16F;
};
#line 131
texture edgesTex < pooled = true; >
{
Width = 1360;
Height = 768;
Format = RG8;
};
texture blendTex < pooled = true; >
{
Width = 1360;
Height = 768;
Format = RGBA8;
};
#line 144
texture areaTex < source = "AreaTex.png"; >
{
Width = 160;
Height = 560;
Format = RG8;
};
texture searchTex < source = "SearchTex.png"; >
{
Width = 64;
Height = 16;
Format = R8;
};
#line 159
sampler depthLinearSampler
{
Texture = depthTex;
};
#line 164
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;
};
#line 209
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);
}
#line 240
float SMAADepthLinearizationPS(
float4 position : SV_Position,
float2 texcoord : TEXCOORD) : SV_Target
{
return ReShade::GetLinearizedDepth(texcoord);
}
#line 247
float2 SMAAEdgeDetectionWrapPS(
float4 position : SV_Position,
float2 texcoord : TEXCOORD0,
float4 offset[3] : TEXCOORD1) : SV_Target
{
if (EdgeDetectionType == 0 &&  PredicationEnabled == true)
return SMAALumaEdgePredicationDetectionPS(texcoord, offset, colorGammaSampler, depthLinearSampler);
else if (EdgeDetectionType == 0)
return SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaSampler);
#line 257
if (EdgeDetectionType == 2)
return SMAADepthEdgeDetectionPS(texcoord, offset, depthLinearSampler);
#line 260
if ( PredicationEnabled)
return SMAAColorEdgePredicationDetectionPS(texcoord, offset, colorGammaSampler, depthLinearSampler);
else
return SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaSampler);
}
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);
}
#line 274
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;
#line 284
return SMAANeighborhoodBlendingPS(texcoord, offset, colorLinearSampler, blendSampler).rgb;
}
#line 289
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;
}
}

