forked from crosire/reshade-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Border.fx
59 lines (51 loc) · 2.1 KB
/
Border.fx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Border version 1.4
*
* -- Version 1.0 by Oomek --
* Fixes light, one pixel thick border in some games when forcing MSAA like i.e. Dishonored
* -- Version 1.1 by CeeJay.dk --
* Optimized the shader. It still does the same but now it runs faster.
* -- Version 1.2 by CeeJay.dk --
* Added border_width and border_color features
* -- Version 1.3 by CeeJay.dk --
* Optimized the performance further
* -- Version 1.4 by CeeJay.dk --
* Added the border_ratio feature
*/
uniform float2 border_width <
ui_type = "input";
ui_label = "Size";
ui_tooltip = "Measured in pixels. If this is set to zero then the ratio will be used instead.";
> = float2(0, 1);
uniform float border_ratio <
ui_type = "input";
ui_label = "Size Ratio";
ui_tooltip = "Set the desired ratio for the visible area. You MUST use floating point. Integers do not work right.\nExamples that work: (1680.0 / 1050.0), (16.0 / 10.0), (1.6)\nExamples that does NOT work right: (1680 / 1050), (16 / 10)";
> = 2.35;
uniform float3 border_color <
ui_type = "color";
ui_label = "Border Color";
> = float3(0.7, 0.0, 0.0);
#include "ReShade.fxh"
float3 BorderPass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float3 color = tex2D(ReShade::BackBuffer, texcoord).rgb;
// -- calculate the right border_width for a given border_ratio --
float2 border_width_variable = border_width;
if (border_width.x == -border_width.y) // If width is not used
if (ReShade::AspectRatio < border_ratio)
border_width_variable = float2(0.0, (ReShade::ScreenSize.y - (ReShade::ScreenSize.x / border_ratio)) * 0.5);
else
border_width_variable = float2((ReShade::ScreenSize.x - (ReShade::ScreenSize.y * border_ratio)) * 0.5, 0.0);
float2 border = (ReShade::PixelSize * border_width_variable); // Translate integer pixel width to floating point
float2 within_border = saturate((-texcoord * texcoord + texcoord) - (-border * border + border)); // Becomes positive when inside the border and zero when outside
return all(within_border) ? color : border_color;
}
technique Border
{
pass
{
VertexShader = PostProcessVS;
PixelShader = BorderPass;
}
}