-
Notifications
You must be signed in to change notification settings - Fork 0
/
EdgeDetect.fx
75 lines (58 loc) · 1.9 KB
/
EdgeDetect.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Laura's edge detect shader
// Copyright © 2023 coalaura
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "ReShade.fxh"
uniform float EdgeStrength <
ui_type = "slider";
ui_label = "Edge Strentgh";
ui_tooltip = "Adjusts the how high the difference between pixels should be to be considered an edge.";
ui_min = 0.1;
ui_max = 15.0;
ui_step = 0.1;
> = 1.0;
uniform int SampleSize <
ui_type = "slider";
ui_label = "Sample Size";
ui_tooltip = "How much of the area should be sampled.";
ui_min = 1;
ui_max = 10;
ui_step = 1;
> = 1;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void EdgeDetectPS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 res : SV_Target0)
{
float depth = tex2Dlod(ReShade::DepthBuffer, float4(texcoord, 0, 0)).x;
float diff = 0.0;
for (int x = -SampleSize; x <= SampleSize; x++) {
for (int y = -SampleSize; y <= SampleSize; y++) {
if (x == 0 && y == 0) continue;
float d = tex2Dlod(ReShade::DepthBuffer, float4(texcoord + float2(BUFFER_RCP_WIDTH * x, BUFFER_RCP_HEIGHT * y), 0, 0)).x;
diff += abs(depth - d);
}
}
diff = diff / (SampleSize * SampleSize);
float4 color = tex2D(ReShade::BackBuffer, texcoord);
float edge = EdgeStrength / 1000.0;
if (diff >= edge) {
float strength = 1.0 + (diff / edge);
color.x = clamp(color.x * strength, 0, 1);
color.y = clamp(color.y * strength, 0, 1);
color.z = clamp(color.z * strength, 0, 1);
}
res.xyz = color.xyz;
res.w = 1.0;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
technique EdgeDetect
{
pass EdgeDetect_Apply
{
VertexShader = PostProcessVS;
PixelShader = EdgeDetectPS;
}
}