From e16a936fb56b0877a5efa9b5c68fec5cf31a999a Mon Sep 17 00:00:00 2001 From: Hyllian Date: Mon, 8 Aug 2022 09:34:00 -0300 Subject: [PATCH] Add anti-ringing to lanczos3-fast shaders - Similar to spline16 and spline36 anti-ringing code; - ON by default and can be disabled using realtime param. --- windowed/shaders/lanczos3-x.slang | 17 +++++++++++++++++ windowed/shaders/lanczos3-y.slang | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/windowed/shaders/lanczos3-x.slang b/windowed/shaders/lanczos3-x.slang index 05c248d..2c1a618 100644 --- a/windowed/shaders/lanczos3-x.slang +++ b/windowed/shaders/lanczos3-x.slang @@ -37,8 +37,15 @@ layout(push_constant) uniform Push vec4 OriginalSize; vec4 OutputSize; uint FrameCount; + float LANCZOS3_ANTI_RINGING; } params; +#pragma parameter LANCZOS3_ANTI_RINGING "Lanczos3 Anti-Ringing [ OFF | ON ]" 1.0 0.0 1.0 1.0 + +#define LANCZOS3_ANTI_RINGING params.LANCZOS3_ANTI_RINGING + +#define AR_STRENGTH 0.8 + #define FIX(c) (max(abs(c), 1e-5)) const float PI = 3.1415926535897932384626433832795; @@ -102,5 +109,15 @@ void main() vec3 color = mat3( C0, C2, C4 ) * w1 + mat3( C1, C3, C5) * w2; + // Anti-ringing + if (LANCZOS3_ANTI_RINGING == 1.0) + { + vec3 aux = color; + vec3 min_sample = min(min(C1, C2), min(C3, C4)); + vec3 max_sample = max(max(C1, C2), max(C3, C4)); + color = clamp(color, min_sample, max_sample); + color = mix(aux, color, AR_STRENGTH*step(0.0, (C1-C2)*(C3-C4))); + } + FragColor = vec4(color, 1.0); } diff --git a/windowed/shaders/lanczos3-y.slang b/windowed/shaders/lanczos3-y.slang index c5fb65e..617ebd8 100644 --- a/windowed/shaders/lanczos3-y.slang +++ b/windowed/shaders/lanczos3-y.slang @@ -37,8 +37,15 @@ layout(push_constant) uniform Push vec4 OriginalSize; vec4 OutputSize; uint FrameCount; + float LANCZOS3_ANTI_RINGING; } params; +#pragma parameter LANCZOS3_ANTI_RINGING "Lanczos3 Anti-Ringing [ OFF | ON ]" 1.0 0.0 1.0 1.0 + +#define LANCZOS3_ANTI_RINGING params.LANCZOS3_ANTI_RINGING + +#define AR_STRENGTH 0.8 + #define FIX(c) (max(abs(c), 1e-5)) const float PI = 3.1415926535897932384626433832795; @@ -102,5 +109,15 @@ void main() vec3 color = mat3( C0, C2, C4 ) * w1 + mat3( C1, C3, C5) * w2; + // Anti-ringing + if (LANCZOS3_ANTI_RINGING == 1.0) + { + vec3 aux = color; + vec3 min_sample = min(min(C1, C2), min(C3, C4)); + vec3 max_sample = max(max(C1, C2), max(C3, C4)); + color = clamp(color, min_sample, max_sample); + color = mix(aux, color, AR_STRENGTH*step(0.0, (C1-C2)*(C3-C4))); + } + FragColor = vec4(color, 1.0); }