-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp5.fx
551 lines (524 loc) · 16.3 KB
/
temp5.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
uniform float ThresoldDiffBetweenPixels <
ui_type = "slider";
ui_min = 0.0; ui_max = 3.0;
> = 0;
uniform float UpLimit <
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
> = 0;
uniform float Downlimit <
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
> = 1;
uniform float LeftLimit <
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
> = 0;
uniform float Rightlimit <
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
> = 1;
uniform float LenLimit <
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
> = 1;
uniform float LenLimitSquare <
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
> = 1;
uniform float ColorTreshold <
ui_type = "slider";
ui_min = 0.0; ui_max = 1;
> = 1;
uniform float NonSquare <
ui_type = "slider";
ui_min = 0.0; ui_max = 1;
> = 0.005;
#include "ReShade.fxh"
texture TargetPS1 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA16; };
sampler SamplerPS1 { Texture = TargetPS1; };
//texture TargetPS2 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
//sampler SamplerPS2 { Texture = TargetPS2; };
texture TargetMask { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA16; };
sampler SamplerMask { Texture = TargetMask; };
bool Equal(float4 a, float4 b)
{
return (abs(a.r-b.r)+abs(a.g-b.g)+abs(a.b-b.b)<=(ThresoldDiffBetweenPixels/10));
}
float2 LREdgesExample(float2 texcoord)
{
float4 CurrentPixel = tex2D(ReShade::BackBuffer, texcoord).rgba;
float4 NextPixel;
float2 texcoord2;
texcoord2.x=texcoord.x;
texcoord2.y=texcoord.x;
bool foundL = false;
bool foundR = false;
[loop]
for(float i=(1.0/BUFFER_WIDTH);i<=(1.0/BUFFER_WIDTH)*128;i+=(1.0/BUFFER_WIDTH))
{
if(!foundL)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x-i,texcoord.y)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.x-i>LeftLimit)
texcoord2.y = texcoord.x-i;//leftedge in y;
foundL = true;
}
}
if(!foundR)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x+i,texcoord.y)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.x+i<Rightlimit)
texcoord2.x = texcoord.x+i;//rightedge in x;
foundR = true;
}
}
}
return texcoord2;
}
float4 UDLREdges(float2 texcoord)
{
float4 CurrentPixel = tex2D(ReShade::BackBuffer, texcoord).rgba;
float4 NextPixel;
float4 texcoord2;
texcoord2.r=texcoord.y;
texcoord2.g=texcoord.y;
texcoord2.b=texcoord.x;
texcoord2.a=texcoord.x;
bool foundU = false;
bool foundD = false;
bool foundL = false;
bool foundR = false;
[loop]
for(float i=(1.0/BUFFER_HEIGHT),j=(1.0/BUFFER_WIDTH);j<=(1.0/BUFFER_WIDTH)*128;i+=(1.0/BUFFER_HEIGHT),j+=(1.0/BUFFER_WIDTH))
{
if(!foundU)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x,texcoord.y-i)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.y-i>UpLimit)
texcoord2.r = texcoord.y-i;//upedge in r;
foundU = true;
}
}
if(!foundD)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x,texcoord.y+i)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.y+i<Downlimit)
texcoord2.g = texcoord.y+i;//downedge in g;
foundD = true;
}
}
if(!foundL)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x-j,texcoord.y)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.x-j>LeftLimit)
texcoord2.b = texcoord.x-j;//leftedge in b;
foundL = true;
}
}
if(!foundR)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x+j,texcoord.y)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.x+j<Rightlimit)
texcoord2.a = texcoord.x+j;//rightedge in a;
foundR = true;
}
}
}
return texcoord2;
}
float2 UDEdges(float2 texcoord)
{
float4 CurrentPixel = tex2D(ReShade::BackBuffer, texcoord).rgba;
float4 NextPixel;
float2 texcoord2;
texcoord2.x=texcoord.y;
texcoord2.y=texcoord.y;
bool foundU = false;
bool foundD = false;
[loop]
for(float i=(1.0/BUFFER_HEIGHT);i<=(1.0/BUFFER_HEIGHT)*128;i+=(1.0/BUFFER_HEIGHT))
{
if(!foundU)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x,texcoord.y-i)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.y-i>UpLimit)
texcoord2.y = texcoord.y-i;//upedge in y;
foundU = true;
}
}
if(!foundD)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x,texcoord.y+i)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.y+i<Downlimit)
texcoord2.x = texcoord.y+i;//downedge in x;
foundD = true;
}
}
}
return texcoord2;
}
float2 UpEdge(float2 texcoord)
{
float4 CurrentPixel = tex2D(ReShade::BackBuffer, texcoord).rgba;
float4 NextPixel;
bool found = false;
[loop]
for(float i=(1.0/BUFFER_HEIGHT);i<=(1.0/BUFFER_HEIGHT)*128;i+=(1.0/BUFFER_HEIGHT))
{
if(!found)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x,texcoord.y-i)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.y-i>UpLimit)
texcoord = float2(texcoord.x,texcoord.y-i);
found = true;
//i=((1.0/BUFFER_HEIGHT)*127);
//i=i+0.1;
//return texcoord;
}
}
}
return texcoord;
}
float2 DownEdge(float2 texcoord)
{
float4 CurrentPixel = tex2D(ReShade::BackBuffer, texcoord).rgba;
float4 NextPixel;
bool found = false;
[loop]
for(float i=(1.0/BUFFER_HEIGHT);i<=(1.0/BUFFER_HEIGHT)*128;i+=(1.0/BUFFER_HEIGHT))
{
if(!found)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x,texcoord.y+i)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.y+i<Downlimit)
texcoord = float2(texcoord.x,texcoord.y+i);
found = true;
//return texcoord;
}
}
}
return texcoord;
}
float2 LeftEdge(float2 texcoord)
{
float4 CurrentPixel = tex2D(ReShade::BackBuffer, texcoord).rgba;
float4 NextPixel;
bool found = false;
[loop]
for(float i=(1.0/BUFFER_WIDTH);i<=(1.0/BUFFER_WIDTH)*128;i+=(1.0/BUFFER_WIDTH))
{
if(!found)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x-i,texcoord.y)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.x-i>LeftLimit)
texcoord = float2(texcoord.x-i,texcoord.y);
found = true;
//[unroll]
//i=1;
//return texcoord;
}
}
}
return texcoord;
}
float2 LREdges(float2 texcoord)
{
float4 CurrentPixel = tex2D(ReShade::BackBuffer, texcoord).rgba;
float4 NextPixel;
float2 texcoord2;
texcoord2.x=texcoord.x;
texcoord2.y=texcoord.x;
bool foundL = false;
bool foundR = false;
[loop]
for(float i=(1.0/BUFFER_WIDTH);i<=(1.0/BUFFER_WIDTH)*128;i+=(1.0/BUFFER_WIDTH))
{
if(!foundL)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x-i,texcoord.y)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.x-i>LeftLimit)
texcoord2.y = texcoord.x-i;//leftedge in y;
foundL = true;
}
}
if(!foundR)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x+i,texcoord.y)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.x+i<Rightlimit)
texcoord2.x = texcoord.x+i;//rightedge in x;
foundR = true;
}
}
}
return texcoord2;
}
float2 RightEdge(float2 texcoord)
{
float4 CurrentPixel = tex2D(ReShade::BackBuffer, texcoord).rgba;
float4 NextPixel;
bool found = false;
[loop]
for(float i=(1.0/BUFFER_WIDTH);i<=(1.0/BUFFER_WIDTH)*128;i+=(1.0/BUFFER_WIDTH))
{
if(!found)
{
NextPixel=tex2D(ReShade::BackBuffer,float2(texcoord.x+i,texcoord.y)).rgba;
if(!Equal(CurrentPixel,NextPixel))
{
if(texcoord.x+i<Rightlimit)
texcoord = float2(texcoord.x+i,texcoord.y);
found = true;
//return texcoord;
}
}
}
return texcoord;
}
float4 Mask(float4 vois : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
// float4 msk = tex2D(ReShade::BackBuffer, texcoord).rgba;
// float4 UDLREdges2 = UDLREdges(texcoord);
// msk.r= UDLREdges2.r;
// msk.g= UDLREdges2.g;
// msk.b= UDLREdges2.b;
// msk.a= UDLREdges2.a;
// return msk;
return UDLREdges(texcoord);
}
float3 DePixel(float4 vois : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float3 col = tex2D(ReShade::BackBuffer, texcoord).rgb;
//float2 current = texcoord;
//float2 upedge = UpEdge (texcoord);
// float4 UDEdges2 = UDLREdges(texcoord);
float4 UDEdges2 = tex2D(SamplerMask,texcoord).rgba;
float2 upedge;
upedge.x=texcoord.x;
upedge.y=UDEdges2.r;//upedge in r
// float3 ColorUpEdge=tex2D(ReShade::BackBuffer, upedge).rgb;
// upedge.y=(tex2D(SamplerMask,upedge).rgba).r;
// upedge.y=UpEdge (texcoord).y;
//float2 downedge = DownEdge(texcoord);
float2 downedge;
downedge.x = texcoord.x;
downedge.y = UDEdges2.g;//downedge in g
// downedge.y = DownEdge(texcoord).y;
float2 centery = (upedge+downedge)/2;//up
float2 centeryD = (upedge+downedge)/2;//down
// if(texcoord.y!=centery.y)
float lenght = abs(downedge.y-upedge.y);
float lenghtUpper = abs(upedge.y-(tex2D(SamplerMask,upedge).rgba).r);
float lenghtDowner = abs((tex2D(SamplerMask,downedge).rgba).g-downedge.y);
if(lenghtUpper+NonSquare<lenght)
{
centery.y = (upedge.y+lenghtUpper/2);//up
}
if(lenghtDowner+NonSquare<lenght)
{
centeryD.y = (downedge.y-lenghtDowner/2);//up
}
//near square pixel test
float2 leftedge;
leftedge.y=texcoord.y;
leftedge.x=UDEdges2.b;//leftedge in b
float2 rightedge;
rightedge.y=texcoord.y;
rightedge.x=UDEdges2.a;//rightedge in a
float lenght2= abs(rightedge.x-leftedge.x);
//near square pixel test
//if(lenght
if(abs(lenght-lenght2)<=LenLimitSquare) //near square pixel test
if(centery.y-upedge.y!=0&&downedge.y-centery.y!=0)
if(texcoord.y<=centery.y)
{
//float realcentery
float lenghtu=abs(tex2D(SamplerMask,upedge).g-tex2D(SamplerMask,upedge).r);
if((lenght-lenghtu)<=LenLimit)
// {
// centery.y-=abs(lenght-lenghtu);
// }
{
float lerpstep=1/(centery.y-upedge.y);
lerpstep=lerpstep*(texcoord.y-upedge.y);
float3 ColorUpEdge=tex2D(ReShade::BackBuffer, upedge).rgb;
float3 Blended50Color=(ColorUpEdge+col)/2;
if(abs(ColorUpEdge.r-col.r)<=ColorTreshold&&
abs(ColorUpEdge.g-col.g)<=ColorTreshold&&
abs(ColorUpEdge.b-col.b)<=ColorTreshold)
{
// col=lerp(Blended50Color,col,lerpstep);
col=lerp(Blended50Color,col,lerpstep);
//.r=lerp(Blended50Color.r,col.r,lerpstep);
//col.g=lerp(Blended50Color.g,col.g,lerpstep);
//col.b=lerp(Blended50Color.b,col.b,lerpstep);
}
}
//col=Blended50Color;
}
// if(1)
// {
// }
// else
if(centeryD.y-upedge.y!=0&&downedge.y-centeryD.y!=0)
if(texcoord.y>=centeryD.y)
{
float lenghtd=abs(tex2D(SamplerMask,downedge).g-tex2D(SamplerMask,downedge).r);
if((lenght-lenghtd)<=LenLimit)
{
float lerpstep=1/(downedge.y-centeryD.y);
lerpstep=lerpstep*(downedge.y-texcoord.y);
float3 ColorDownEdge=tex2D(ReShade::BackBuffer, downedge).rgb;
float3 Blended50Color=(ColorDownEdge+col)/2;
if(abs(ColorDownEdge.r-col.r)<=ColorTreshold&&
abs(ColorDownEdge.g-col.g)<=ColorTreshold&&
abs(ColorDownEdge.b-col.b)<=ColorTreshold)
{
col=lerp(Blended50Color,col,lerpstep);
//col.r=lerp(Blended50Color.r,col.r,lerpstep);
// col.g=lerp(Blended50Color.g,col.g,lerpstep);
// col.b=lerp(Blended50Color.b,col.b,lerpstep);
}
}
}
return col;
}
float3 DePixelH(float4 vois : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
// float3 col = tex2D(ReShade::BackBuffer, texcoord).rgb;
float3 colPS1 = tex2D(SamplerPS1 , texcoord).rgb;
// float2 leftedge = LeftEdge ( texcoord);
// float2 rightedge= RightEdge (texcoord);
// float4 LREdges2 = UDLREdges(texcoord);
float4 LREdges2 = tex2D(SamplerMask,texcoord).rgba;
float2 leftedge;
leftedge.y=texcoord.y;
leftedge.x=LREdges2.b;//leftedge in b
float2 rightedge;
rightedge.y=texcoord.y;
rightedge.x=LREdges2.a;//rightedge in a
float2 centerx = (leftedge+rightedge)/2;
float2 centerxR = (leftedge+rightedge)/2;
//float2 upedge = UpEdge (texcoord);
//float2 downedge = DownEdge(texcoord);
//float2 centery = (upedge+downedge)/2;
//(centery-centerx);
//if(abs(rightedge.x-leftedge.x-downedge.y-upedge.y)<=0.2)
// if(texcoord.x!=centerx.x)
//near square pixel test
float2 upedge;
upedge.x=texcoord.x;
upedge.y=LREdges2.r;//upedge in r
// upedge.y=UpEdge (texcoord).y;
//float2 downedge = DownEdge(texcoord);
float2 downedge;
downedge.x = texcoord.x;
downedge.y = LREdges2.g;//downedge in g
float lenght2= abs(downedge.y-upedge.y);
//near square pixel test
float lenght = abs(rightedge.x-leftedge.x);
float lenghtLefter = abs(leftedge.x-(tex2D(SamplerMask,leftedge).rgba).b);
float lenghtRighter = abs((tex2D(SamplerMask,rightedge).rgba).a-rightedge.x);
if(lenghtLefter+NonSquare<lenght)
{
centerx.x = (leftedge.x+lenghtLefter/2);//up
}
if(lenghtRighter+NonSquare<lenght)
{
centerxR.x = (rightedge.x-lenghtRighter/2);//up
}
if(abs(lenght-lenght2)<=LenLimitSquare) //near square pixel test
if(centerx.x-leftedge.x!=0&&rightedge.x-centerx.x!=0)
if(texcoord.x<=centerx.x)
{
float lenghtl=abs(tex2D(SamplerMask,leftedge).a-tex2D(SamplerMask,leftedge).b);
if((lenght-lenghtl)<=LenLimit)
{
float lerpstep=1/(centerx.x-leftedge.x);
lerpstep=lerpstep*(texcoord.x-leftedge.x);
float3 ColorLeftEdge=tex2D(SamplerPS1, leftedge).rgb;
float3 Blended50Color=(ColorLeftEdge+colPS1)/2;
if(abs(ColorLeftEdge.r-colPS1.r)<=ColorTreshold&&
abs(ColorLeftEdge.g-colPS1.g)<=ColorTreshold&&
abs(ColorLeftEdge.b-colPS1.b)<=ColorTreshold)
{
colPS1=lerp(Blended50Color,colPS1,lerpstep);
//col.r=lerp(Blended50Color.r,colPS1.r,lerpstep);
//col.g=lerp(Blended50Color.g,colPS1.g,lerpstep);
//col.b=lerp(Blended50Color.b,colPS1.b,lerpstep);
}
}
}
// else
// if(centerxD.x-upedge.y!=0&&downedge.y-centeryD.y!=0)
// if(0)
if(centerxR.x-leftedge.x!=0&&rightedge.x-centerxR.x!=0)
if(texcoord.x>=centerxR.x)
{
float lenghtr=abs(tex2D(SamplerMask,rightedge).a-tex2D(SamplerMask,rightedge).b);
if((lenght-lenghtr)<=LenLimit)
{
float lerpstep=1/(rightedge.x-centerxR.x);
lerpstep=lerpstep*(rightedge.x-texcoord.x);
float3 ColorRightEdge=tex2D(SamplerPS1, rightedge).rgb;
float3 Blended50Color=(ColorRightEdge+colPS1)/2;
if(abs(ColorRightEdge.r-colPS1.r)<=ColorTreshold&&
abs(ColorRightEdge.g-colPS1.g)<=ColorTreshold&&
abs(ColorRightEdge.b-colPS1.b)<=ColorTreshold)
{
colPS1=lerp(Blended50Color,colPS1,lerpstep);
//col.r=lerp(Blended50Color.r,colPS1.r,lerpstep);
//col.g=lerp(Blended50Color.g,colPS1.g,lerpstep);
//col.b=lerp(Blended50Color.b,colPS1.b,lerpstep);
}
}
}
return colPS1;
}
technique DePixel5
{
pass
{
VertexShader = PostProcessVS;
PixelShader = Mask;
RenderTarget = TargetMask;
}
pass
{
VertexShader = PostProcessVS;
PixelShader = DePixel;
RenderTarget = TargetPS1;
}
pass
{
VertexShader = PostProcessVS;
PixelShader = DePixelH;
//RenderTarget = TargetPS2;
}
}