-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBurnInDim.fx
248 lines (226 loc) · 7.58 KB
/
BurnInDim.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "Reshade.fxh"
#include "ReShadeUI.fxh"
uniform float frametime <source = "frametime";>;
uniform uint framecount < source = "framecount"; >;
// ReShadeUI ///////////////////////////////////////////////////////////////////////////////////////
#ifndef ADVANCED_UserScoringLenient
#define ADVANCED_UserScoringLenient 0
#endif
#if ADVANCED_UserScoringLenient == 0
uniform int UserScoringLenient <
ui_type = "combo";
ui_items = "Lenient\0Strict\0More Strict\0Extremely Strict\0Extremely Strict 2x\0Perfect Match (default)\0";
ui_label = "Static Pixel Leniency";
ui_tooltip = "How lenient should a pixel from past frame be considered as static.";
> = 5;
float getUserScoringLenient() {
switch (UserScoringLenient) {
case 0:
return 0.1;
case 1:
return 0.02;
case 2:
return 0.04;
case 3:
return 0.001;
case 4:
return 0.00005;
case 5:
return 0;
default:
return 0;
}
}
#else
uniform float UserScoringLenient <
ui_type = "slider";
ui_min = 0.0;
ui_max = 1.0;
ui_step = 0.005;
ui_label = "Static Pixel Leniency (Advanced)";
ui_tooltip = "How lenient should a pixel from past frame be considered as static. (0: perfect match, 1: will consider all as static)";
> = 0.02;
float getUserScoringLenient() {
return UserScoringLenient;
}
#endif
uniform int UserScoringDimAttack <
ui_type = "combo";
ui_items = "Slower\0Slow (default)\0Fast\0Extrememly Fast (debug)\0None (debug)\0";
ui_label = "Dimming Speed";
ui_tooltip = "Rate at which static pixels dims.";
> = 1;
float getUserScoringDimAttack() {
switch (UserScoringDimAttack) {
case 0:
return 0.000025;
case 1:
return 0.00005;
case 2:
return 0.0001;
case 3:
return 0.1;
case 4:
return 0;
default:
return 0.00005;
}
}
uniform int UserScoringDimDecay <
ui_type = "combo";
ui_items = "Instant (default)\0Fast\0Noticable\0Slow\0Never (debug)\0";
ui_label = "Dimming Decay Speed";
ui_tooltip = "Rate at which static pixels undims.";
> = 0;
float getUserScoringDimDecay() {
switch (UserScoringDimDecay) {
case 0:
return 1;
case 1:
return 0.8;
case 2:
return 0.5;
case 3:
return 0.1;
case 4:
return 0;
default:
return 1;
};
};
uniform float UserScoringDimThres <
ui_type = "slider";
ui_min = 0.0;
ui_max = 1.0;
ui_step = 0.05;
ui_label = "Dimming Threshold";
ui_tooltip = "A pixel has a score starting from 1, decreasing to 0 if static. How soon should dimming begin. (1:immediately, 0:when score reaches 0)";
> = 0.7;
uniform float UserScoringLightnessThres <
ui_type = "slider";
ui_min = 0.0;
ui_max = 1.0;
ui_step = 0.05;
ui_label = "Luma Lightness Threshold";
ui_tooltip = "Only pixels past this brightness level can be considered for scoring, used to isolate bright I elements.";
> = 0;
uniform float UserScoringMaxDim <
ui_type = "slider";
ui_min = 0.0;
ui_max = 1.0;
ui_step = 0.05;
ui_label = "Max Dimming";
ui_tooltip = "How dark the static pixel will get.";
> = 0.5;
uniform int UserFrameSkip <
ui_type = "slider";
ui_min = 0;
ui_max = 240;
ui_step = 1;
ui_label = "Frame Skipping";
ui_tooltip = "Skip this amount of frames before scoring again.";
> = 6;
float getUserFrameSkip() {
return UserFrameSkip + 1;
}
//uniform int UserBlur <
// ui_type = "slider";
// ui_min = 0;
// ui_max = 10;
// ui_step = 1;
// ui_label = "Mask Blur";
// ui_tooltip = "To expand the dimming mask to covered antialiased edges.";
//> = 0;
// Tex & Samplers //////////////////////////////////////////////////////////////////////////////////
texture texBurnScore{Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = R8;};
sampler2D samplerBurnInScore{Texture = texBurnScore;};
texture texBurnScoreC{Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = R8;};
sampler2D samplerBurnInScoreC{Texture = texBurnScoreC;};
texture texPrevFrame{Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA32F;};
sampler2D samplerPrevFrame{Texture = texPrevFrame;};
// Helpers /////////////////////////////////////////////////////////////////////////////////////////
float4 rgb4ToLuma(float4 rgbaIn4) {
return float4(rgbaIn4.r * 0.2126, rgbaIn4.g * 0.7152, rgbaIn4.b * 0.7152, rgbaIn4.a);
}
float rgb4ToLumaLightness(float4 rgbaIn4){
const float4 rgbaIn4Luma = rgb4ToLuma(rgbaIn4);
return max(max(rgbaIn4Luma.r, rgbaIn4Luma.g), rgbaIn4Luma.b);
}
bool isFrameskip() {
return framecount % getUserFrameSkip() != 0;
}
// PixelShader /////////////////////////////////////////////////////////////////////////////////////
//Score
#define SCORE_DECREASE max(prevScore - (frametime * getUserScoringDimAttack() * getUserFrameSkip()), 0);
#define SCORE_INCREASE min(prevScore + (frametime * getUserScoringDimDecay() * getUserFrameSkip()), 1);
float PS_BurnInScoring(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target {
if (isFrameskip()) discard;
//get pixels
const float4 orig4 = tex2D(ReShade::BackBuffer, texcoord);
const float4 prev4 = tex2D(samplerPrevFrame, texcoord);
const float prevScore = tex2D(samplerBurnInScoreC, texcoord).r;
//but check HSL lightness
if (rgb4ToLumaLightness(orig4) <= UserScoringLightnessThres) {
return SCORE_DECREASE //too dark already, reset score
}
//calculate score (if pixel has not changed
const float rScore = abs(prev4.r - orig4.r);
const float gScore = abs(prev4.g - orig4.g);
const float bScore = abs(prev4.b - orig4.b);
const float rgbScoreAvg = (rScore + gScore + bScore) / 3;
//if within leniency
if (rgbScoreAvg <= getUserScoringLenient()) {
return SCORE_DECREASE
} else {
return SCORE_INCREASE
}
}
//Copy
float4 PS_CopyBack(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target {
if (isFrameskip()) discard;
return tex2D(ReShade::BackBuffer, texcoord);
}
//Copy
float4 PS_CopyBackScore(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target {
if (isFrameskip()) discard;
return tex2D(samplerBurnInScore, texcoord);
}
//Final
float4 PS_BurnInDim(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target {
float4 orig4 = tex2D(ReShade::BackBuffer, texcoord);
float currScore = tex2D(samplerBurnInScore, texcoord).r;
// //final
// if (UserBlur > 0) { //blur
// for (int i = 1; i < UserBlur; i++) {
// currScore += tex2D(samplerBurnInScore, texcoord + (BUFFER_RCP_WIDTH * i)).r;
// currScore += tex2D(samplerBurnInScore, texcoord - (BUFFER_RCP_HEIGHT * i)).r;
// }
// } //else
return orig4 * min(1, max(currScore * (1/UserScoringDimThres), UserScoringMaxDim));
}
// Technique ///////////////////////////////////////////////////////////////////////////////////////
technique BurnInDimming {
pass Score { //draw to texBurnScore to update where to fade
RenderTarget = texBurnScore;
VertexShader = PostProcessVS; //default
PixelShader = PS_BurnInScoring;
//ClearRenderTargets = false;
//BlendEnable = true;
//BlendOp = ADD;
//BlendOpAlpha = ADD;
}
pass Copy { //draw to texPrevFrame to remember prev frame
RenderTarget = texPrevFrame;
VertexShader = PostProcessVS; //default
PixelShader = PS_CopyBack;
}
pass Copy { //to avoid sampling and drawing to samplerBurnInScore
RenderTarget = texBurnScoreC;
VertexShader = PostProcessVS; //default
PixelShader = PS_CopyBackScore;
}
pass Final { //draw to output with dim
VertexShader = PostProcessVS; //default
PixelShader = PS_BurnInDim;
}
}