/
PatternShading.fx
128 lines (116 loc) · 1.79 KB
/
PatternShading.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "ReShade.fxh"
#include "ReShadeUI.fxh"
uniform float threshold < __UNIFORM_SLIDER_FLOAT1
ui_label = "Brightness";
ui_min = 0.0; ui_max = 1.0;
> = 0.1;
uniform int steps <
ui_label = "Amount of Shades";
ui_type = "combo";
ui_items = " 2\0 3\0 4\0 5\0";
> = 3;
uniform bool test <
> = false;
float3 patternShading(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
int pattern, pattern1, pattern2, pattern3;
float luma = dot(tex2D(ReShade::BackBuffer, texcoord).rgb, 1.0 / 3.0);
if(test)
{
luma = lerp(0.0, 1.0, texcoord.x);
}
if(pos.x % 2 <= 1 && pos.y % 2 <= 1)
{
pattern = 0;
}
else
{
pattern = 1;
}
if((pos.x + 1) % 2 <= 1 && (pos.y - 1) % 2 <= 1)
{
pattern1 = 1;
}
else
{
pattern1 = 0;
}
if(pos.x % 2 <= 1 && (pos.y - 1) % 2 <= 1)
{
pattern2 = 1;
}
else
{
pattern2 = 0;
}
if(pos.x % 2 <= 1 && pos.y % 2 <= 1 || (pos.x + 1) % 2 <= 1 && (pos.y + 1) % 2 <= 1)
{
pattern3 = 0;
}
else
{
pattern3 = 1;
}
if(steps == 0)
{
pattern = ceil(1.0 - step(luma, threshold));
}
else if(steps == 1)
{
if(luma <= threshold)
{
pattern = 0;
}
else if(luma <= threshold * 2)
{
pattern = pattern3;
}
else if(luma > threshold * 2)
{
pattern = 1;
}
}
else if(steps == 2)
{
if(luma <= threshold)
{
pattern = 0;
}
else if(luma <= threshold * 2)
{
pattern = pattern1;
}
else if(luma > threshold * 3)
{
pattern = 1;
}
}
else
{
if(luma <= threshold)
{
pattern = 0;
}
else if(luma <= threshold * 2)
{
pattern = pattern2;
}
else if(luma <= threshold * 3)
{
pattern = pattern3;
}
else if(luma > threshold * 4)
{
pattern = 1;
}
}
return pattern;
}
technique PatternShading
{
pass pass0
{
VertexShader = PostProcessVS;
PixelShader = patternShading;
}
}