Skip to content

Commit d682103

Browse files
committed
nlmeans.glsl: replace SD with TD, drop PSD
1 parent 0b36de1 commit d682103

19 files changed

+360
-576
lines changed

.config/mpv/shaders/HQ/nlmeans.glsl

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -320,55 +320,50 @@
320320
*
321321
* Motion estimation (ME) should improve quality without impacting speed.
322322
*
323+
* Increasing temporal distortion (TD) can reduce motion blur.
324+
*
323325
* T: number of frames used
324326
* ME: motion estimation, 0 for none, 1 for max weight, 2 for weighted avg
325327
* MEF: estimate factor, compensates for ME being one frame behind
326328
* TRF: compare against the denoised frames
329+
* TD: temporal distortion, higher numbers give less weight to previous frames
327330
*/
328331
#ifdef LUMA_raw
329332
#define T 0
330333
#define ME 1
331334
#define MEF 2
332335
#define TRF 0
336+
#define TD 1.0
333337
#else
334338
#define T 0
335339
#define ME 0
336340
#define MEF 2
337341
#define TRF 0
342+
#define TD 1.0
338343
#endif
339344

340345
/* Spatial kernel
341346
*
342347
* Increasing the spatial denoising factor (SS) reduces the weight of further
343348
* pixels.
344349
*
345-
* Spatial distortion instructs the spatial kernel to view that axis as
346-
* closer/further, for instance SD=(1,1,0.5) would make the temporal axis
347-
* appear closer and increase blur between frames.
348-
*
349350
* The intra-patch variants are supposed to help with larger patch sizes.
350351
*
351352
* SST: enables spatial kernel if R>=PST, 0 fully disables
352353
* SS: spatial sigma
353-
* SD: spatial distortion (X, Y, time)
354354
* PSS: intra-patch spatial sigma
355355
* PST: enables intra-patch spatial kernel if P>=PST, 0 fully disables
356-
* PSD: intra-patch spatial distortion (X, Y)
357356
*/
358357
#ifdef LUMA_raw
359358
#define SST 1
360359
#define SS 0.5072938692870894
361-
#define SD vec3(1,1,1)
362360
#define PST 0
363361
#define PSS 0.0
364-
#define PSD vec2(1,1)
365362
#else
366363
#define SST 1
367364
#define SS 0.31580805565941705
368-
#define SD vec3(1,1,1)
369365
#define PST 0
370366
#define PSS 0.0
371-
#define PSD vec2(1,1)
372367
#endif
373368

374369
/* Kernels
@@ -811,24 +806,24 @@ vec2 ref(vec2 p, int d)
811806
float spatial_r(vec3 v)
812807
{
813808
v.xy += 0.5 - fract(HOOKED_pos*HOOKED_size);
814-
return SK(length(v*SD)*SS);
809+
v.z *= TD;
810+
return SK(length(v)*SS);
815811
}
816812
#else
817813
#define spatial_r(v) (1)
818814
#endif
819815

816+
// 2D blur for sharpening
820817
#if AS
821818
float spatial_as(vec3 v)
822819
{
823820
v.xy += 0.5 - fract(HOOKED_pos*HOOKED_size);
824-
return ASK(length(v*SD)*ASS);
821+
return ASK(length(v)*ASS) * int(v.z == 0);
825822
}
826-
#else
827-
#define spatial_as(v) (1)
828823
#endif
829824

830825
#if PST && P >= PST
831-
#define spatial_p(v) PSK(length(v*PSD)*PSS)
826+
#define spatial_p(v) PSK(length(v)*PSS)
832827
#else
833828
#define spatial_p(v) (1)
834829
#endif
@@ -1075,7 +1070,6 @@ vec4 hook()
10751070

10761071
#if AS
10771072
float spatial_as_weight = spatial_as(tr);
1078-
spatial_as_weight *= int(r.z == 0); // ignore temporal
10791073
sum_as += px * spatial_as_weight;
10801074
total_weight_as += spatial_as_weight;
10811075
#endif
@@ -1443,55 +1437,50 @@ return _INJ_RF_LUMA_texOff(0);
14431437
*
14441438
* Motion estimation (ME) should improve quality without impacting speed.
14451439
*
1440+
* Increasing temporal distortion (TD) can reduce motion blur.
1441+
*
14461442
* T: number of frames used
14471443
* ME: motion estimation, 0 for none, 1 for max weight, 2 for weighted avg
14481444
* MEF: estimate factor, compensates for ME being one frame behind
14491445
* TRF: compare against the denoised frames
1446+
* TD: temporal distortion, higher numbers give less weight to previous frames
14501447
*/
14511448
#ifdef LUMA_raw
14521449
#define T 0
14531450
#define ME 1
14541451
#define MEF 2
14551452
#define TRF 0
1453+
#define TD 1.0
14561454
#else
14571455
#define T 0
14581456
#define ME 0
14591457
#define MEF 2
14601458
#define TRF 0
1459+
#define TD 1.0
14611460
#endif
14621461

14631462
/* Spatial kernel
14641463
*
14651464
* Increasing the spatial denoising factor (SS) reduces the weight of further
14661465
* pixels.
14671466
*
1468-
* Spatial distortion instructs the spatial kernel to view that axis as
1469-
* closer/further, for instance SD=(1,1,0.5) would make the temporal axis
1470-
* appear closer and increase blur between frames.
1471-
*
14721467
* The intra-patch variants are supposed to help with larger patch sizes.
14731468
*
14741469
* SST: enables spatial kernel if R>=PST, 0 fully disables
14751470
* SS: spatial sigma
1476-
* SD: spatial distortion (X, Y, time)
14771471
* PSS: intra-patch spatial sigma
14781472
* PST: enables intra-patch spatial kernel if P>=PST, 0 fully disables
1479-
* PSD: intra-patch spatial distortion (X, Y)
14801473
*/
14811474
#ifdef LUMA_raw
14821475
#define SST 1
14831476
#define SS 0.5045657681048714
1484-
#define SD vec3(1,1,1)
14851477
#define PST 0
14861478
#define PSS 0.0
1487-
#define PSD vec2(1,1)
14881479
#else
14891480
#define SST 1
14901481
#define SS 0.2660216669677905
1491-
#define SD vec3(1,1,1)
14921482
#define PST 0
14931483
#define PSS 0.0
1494-
#define PSD vec2(1,1)
14951484
#endif
14961485

14971486
/* Kernels
@@ -1934,24 +1923,24 @@ vec2 ref(vec2 p, int d)
19341923
float spatial_r(vec3 v)
19351924
{
19361925
v.xy += 0.5 - fract(HOOKED_pos*HOOKED_size);
1937-
return SK(length(v*SD)*SS);
1926+
v.z *= TD;
1927+
return SK(length(v)*SS);
19381928
}
19391929
#else
19401930
#define spatial_r(v) (1)
19411931
#endif
19421932

1933+
// 2D blur for sharpening
19431934
#if AS
19441935
float spatial_as(vec3 v)
19451936
{
19461937
v.xy += 0.5 - fract(HOOKED_pos*HOOKED_size);
1947-
return ASK(length(v*SD)*ASS);
1938+
return ASK(length(v)*ASS) * int(v.z == 0);
19481939
}
1949-
#else
1950-
#define spatial_as(v) (1)
19511940
#endif
19521941

19531942
#if PST && P >= PST
1954-
#define spatial_p(v) PSK(length(v*PSD)*PSS)
1943+
#define spatial_p(v) PSK(length(v)*PSS)
19551944
#else
19561945
#define spatial_p(v) (1)
19571946
#endif
@@ -2198,7 +2187,6 @@ vec4 hook()
21982187

21992188
#if AS
22002189
float spatial_as_weight = spatial_as(tr);
2201-
spatial_as_weight *= int(r.z == 0); // ignore temporal
22022190
sum_as += px * spatial_as_weight;
22032191
total_weight_as += spatial_as_weight;
22042192
#endif
@@ -2565,55 +2553,50 @@ vec4 hook()
25652553
*
25662554
* Motion estimation (ME) should improve quality without impacting speed.
25672555
*
2556+
* Increasing temporal distortion (TD) can reduce motion blur.
2557+
*
25682558
* T: number of frames used
25692559
* ME: motion estimation, 0 for none, 1 for max weight, 2 for weighted avg
25702560
* MEF: estimate factor, compensates for ME being one frame behind
25712561
* TRF: compare against the denoised frames
2562+
* TD: temporal distortion, higher numbers give less weight to previous frames
25722563
*/
25732564
#ifdef LUMA_raw
25742565
#define T 0
25752566
#define ME 1
25762567
#define MEF 2
25772568
#define TRF 0
2569+
#define TD 1.0
25782570
#else
25792571
#define T 0
25802572
#define ME 0
25812573
#define MEF 2
25822574
#define TRF 0
2575+
#define TD 1.0
25832576
#endif
25842577

25852578
/* Spatial kernel
25862579
*
25872580
* Increasing the spatial denoising factor (SS) reduces the weight of further
25882581
* pixels.
25892582
*
2590-
* Spatial distortion instructs the spatial kernel to view that axis as
2591-
* closer/further, for instance SD=(1,1,0.5) would make the temporal axis
2592-
* appear closer and increase blur between frames.
2593-
*
25942583
* The intra-patch variants are supposed to help with larger patch sizes.
25952584
*
25962585
* SST: enables spatial kernel if R>=PST, 0 fully disables
25972586
* SS: spatial sigma
2598-
* SD: spatial distortion (X, Y, time)
25992587
* PSS: intra-patch spatial sigma
26002588
* PST: enables intra-patch spatial kernel if P>=PST, 0 fully disables
2601-
* PSD: intra-patch spatial distortion (X, Y)
26022589
*/
26032590
#ifdef LUMA_raw
26042591
#define SST 1
26052592
#define SS 0.5045657681048714
2606-
#define SD vec3(1,1,1)
26072593
#define PST 0
26082594
#define PSS 0.0
2609-
#define PSD vec2(1,1)
26102595
#else
26112596
#define SST 1
26122597
#define SS 0.2660216669677905
2613-
#define SD vec3(1,1,1)
26142598
#define PST 0
26152599
#define PSS 0.0
2616-
#define PSD vec2(1,1)
26172600
#endif
26182601

26192602
/* Kernels
@@ -3056,24 +3039,24 @@ vec2 ref(vec2 p, int d)
30563039
float spatial_r(vec3 v)
30573040
{
30583041
v.xy += 0.5 - fract(HOOKED_pos*HOOKED_size);
3059-
return SK(length(v*SD)*SS);
3042+
v.z *= TD;
3043+
return SK(length(v)*SS);
30603044
}
30613045
#else
30623046
#define spatial_r(v) (1)
30633047
#endif
30643048

3049+
// 2D blur for sharpening
30653050
#if AS
30663051
float spatial_as(vec3 v)
30673052
{
30683053
v.xy += 0.5 - fract(HOOKED_pos*HOOKED_size);
3069-
return ASK(length(v*SD)*ASS);
3054+
return ASK(length(v)*ASS) * int(v.z == 0);
30703055
}
3071-
#else
3072-
#define spatial_as(v) (1)
30733056
#endif
30743057

30753058
#if PST && P >= PST
3076-
#define spatial_p(v) PSK(length(v*PSD)*PSS)
3059+
#define spatial_p(v) PSK(length(v)*PSS)
30773060
#else
30783061
#define spatial_p(v) (1)
30793062
#endif
@@ -3320,7 +3303,6 @@ vec4 hook()
33203303

33213304
#if AS
33223305
float spatial_as_weight = spatial_as(tr);
3323-
spatial_as_weight *= int(r.z == 0); // ignore temporal
33243306
sum_as += px * spatial_as_weight;
33253307
total_weight_as += spatial_as_weight;
33263308
#endif

0 commit comments

Comments
 (0)