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.
This commit is contained in:
Hyllian 2022-08-08 09:34:00 -03:00
parent 8766bbc0bf
commit e16a936fb5
2 changed files with 34 additions and 0 deletions

View file

@ -37,8 +37,15 @@ layout(push_constant) uniform Push
vec4 OriginalSize; vec4 OriginalSize;
vec4 OutputSize; vec4 OutputSize;
uint FrameCount; uint FrameCount;
float LANCZOS3_ANTI_RINGING;
} params; } 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)) #define FIX(c) (max(abs(c), 1e-5))
const float PI = 3.1415926535897932384626433832795; const float PI = 3.1415926535897932384626433832795;
@ -102,5 +109,15 @@ void main()
vec3 color = mat3( C0, C2, C4 ) * w1 + mat3( C1, C3, C5) * w2; 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); FragColor = vec4(color, 1.0);
} }

View file

@ -37,8 +37,15 @@ layout(push_constant) uniform Push
vec4 OriginalSize; vec4 OriginalSize;
vec4 OutputSize; vec4 OutputSize;
uint FrameCount; uint FrameCount;
float LANCZOS3_ANTI_RINGING;
} params; } 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)) #define FIX(c) (max(abs(c), 1e-5))
const float PI = 3.1415926535897932384626433832795; const float PI = 3.1415926535897932384626433832795;
@ -102,5 +109,15 @@ void main()
vec3 color = mat3( C0, C2, C4 ) * w1 + mat3( C1, C3, C5) * w2; 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); FragColor = vec4(color, 1.0);
} }