Merge pull request #568 from Hyllian/master

Update DDT and NEDI shaders
This commit is contained in:
hizzlekizzle 2024-04-05 15:28:55 -05:00 committed by GitHub
commit 05414f65e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 152 additions and 68 deletions

View File

@ -3,7 +3,7 @@
/*
Hyllian's DDT Shader
Copyright (C) 2011-2016 Hyllian/Jararaca - sergiogdb@gmail.com
Copyright (C) 2011-2024 Hyllian/Jararaca - sergiogdb@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -26,15 +26,20 @@
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float BIL_FALLBACK;
} params;
#pragma parameter BIL_FALLBACK "Bilinear Fallback Threshold" 0.6 0.0 1.0 0.05
#define BIL_FALLBACK params.BIL_FALLBACK
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
mat4 MVP;
} global;
#define saturate(c) clamp(c, 0.0, 1.0)
@ -67,7 +72,7 @@ float luma(float3 color)
float3 bilinear(float p, float q, float3 A, float3 B, float3 C, float3 D)
{
return ((1-p)*(1-q)*A + p*(1-q)*B + (1-p)*q*C + p*q*D);
return ((1-p)*(1-q)*A + p*(1-q)*B + (1-p)*q*C + p*q*D);
}
#pragma stage vertex
@ -83,12 +88,12 @@ void main()
vTexCoord = TexCoord * 1.0001;
float2 ps = float2(params.SourceSize.z, params.SourceSize.w);
float dx = ps.x;
float dy = ps.y;
float dx = ps.x;
float dy = ps.y;
t1.xy = float2( dx, 0); // F
t1.zw = float2( 0, dy); // H
loc = vTexCoord*params.SourceSize.xy;
t1.xy = float2( dx, 0); // F
t1.zw = float2( 0, dy); // H
loc = vTexCoord*params.SourceSize.xy;
}
#pragma stage fragment
@ -101,46 +106,51 @@ layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
float2 pos = frac(loc)-float2(0.5, 0.5); // pos = pixel position
float2 dir = sign(pos); // dir = pixel direction
float2 dir = sign(pos); // dir = pixel direction
float2 g1 = dir*t1.xy;
float2 g2 = dir*t1.zw;
float2 g1 = dir*t1.xy;
float2 g2 = dir*t1.zw;
float3 A = tex2D(decal, vTexCoord ).xyz;
float3 B = tex2D(decal, vTexCoord +g1 ).xyz;
float3 C = tex2D(decal, vTexCoord +g2).xyz;
float3 D = tex2D(decal, vTexCoord +g1+g2).xyz;
float3 A = tex2D(decal, vTexCoord ).xyz;
float3 B = tex2D(decal, vTexCoord +g1 ).xyz;
float3 C = tex2D(decal, vTexCoord +g2).xyz;
float3 D = tex2D(decal, vTexCoord +g1+g2).xyz;
float a = luma(A);
float b = luma(B);
float c = luma(C);
float d = luma(D);
float a = luma(A);
float b = luma(B);
float c = luma(C);
float d = luma(D);
float p = abs(pos.x);
float q = abs(pos.y);
float p = abs(pos.x);
float q = abs(pos.y);
float k = distance(pos,g1 * params.SourceSize.xy);
float l = distance(pos,g2 * params.SourceSize.xy);
float k = distance(pos,g1 * params.SourceSize.xy);
float l = distance(pos,g2 * params.SourceSize.xy);
float wd1 = abs(a-d);
float wd2 = abs(b-c);
float wd1 = abs(a-d);
float wd2 = abs(b-c);
if ( wd1 < wd2 )
{
if (k < l)
{
C = A + D - B;
}
else
{
B = A + D - C;
}
}
else if (wd1 > wd2)
{
D = B + C - A;
}
float3 color = bilinear(p, q, A, B, C, D);
float3 color = bilinear(p, q, A, B, C, D);
FragColor = vec4(color, 1.0);
if ( wd1 < wd2 )
{
if (k < l)
{
C = A + D - B;
}
else
{
B = A + D - C;
}
}
else if (wd1 > wd2)
{
D = B + C - A;
}
float3 ddt = bilinear(p, q, A, B, C, D);
color = mix(color, ddt, smoothstep(0.0, BIL_FALLBACK, abs(wd2-wd1)));
FragColor = vec4(color, 1.0);
}

View File

@ -4,7 +4,7 @@ filter_linear0 = false
scale_type0 = source
shader1 = "shaders/nedi-pass0.slang"
filter_linear1 = false
wrap_mode1 = "clamp_to_border"
wrap_mode1 = "clamp_to_edge"
float_framebuffer1 = "false"
scale_type_x1 = "source"
scale_x1 = "2.000000"
@ -12,7 +12,7 @@ scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "shaders/nedi-pass1.slang"
filter_linear2 = false
wrap_mode2 = "clamp_to_border"
wrap_mode2 = "clamp_to_edge"
float_framebuffer2 = "false"
scale_type_x2 = "source"
scale_x2 = "1.000000"
@ -20,7 +20,7 @@ scale_type_y2 = "source"
scale_y2 = "2.000000"
shader3 = "shaders/nedi-pass2.slang"
filter_linear3 = false
wrap_mode3 = "clamp_to_border"
wrap_mode3 = "clamp_to_edge"
float_framebuffer3 = "false"
scale_type_x3 = "source"
scale_x3 = "1.000000"
@ -28,6 +28,6 @@ scale_type_y3 = "source"
scale_y3 = "1.000000"
shader4 = "shaders/nedi-jinc.slang"
filter_linear4 = false
wrap_mode4 = "clamp_to_border"
wrap_mode4 = "clamp_to_edge"
float_framebuffer4 = "false"
scale_type4 = viewport

View File

@ -0,0 +1,59 @@
shaders = "5"
feedback_pass = "0"
shader0 = "../../sharpen/shaders/cheap-sharpen.slang"
filter_linear0 = "false"
wrap_mode0 = "clamp_to_border"
mipmap_input0 = "false"
alias0 = ""
float_framebuffer0 = "false"
srgb_framebuffer0 = "false"
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "shaders/nedi-pass0.slang"
filter_linear1 = "false"
wrap_mode1 = "clamp_to_edge"
mipmap_input1 = "false"
alias1 = ""
float_framebuffer1 = "false"
srgb_framebuffer1 = "false"
scale_type_x1 = "source"
scale_x1 = "2.000000"
scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "shaders/nedi-pass1.slang"
filter_linear2 = "false"
wrap_mode2 = "clamp_to_edge"
mipmap_input2 = "false"
alias2 = ""
float_framebuffer2 = "false"
srgb_framebuffer2 = "false"
scale_type_x2 = "source"
scale_x2 = "1.000000"
scale_type_y2 = "source"
scale_y2 = "2.000000"
shader3 = "shaders/nedi-pass2.slang"
filter_linear3 = "false"
wrap_mode3 = "clamp_to_edge"
mipmap_input3 = "false"
alias3 = ""
float_framebuffer3 = "false"
srgb_framebuffer3 = "false"
scale_type_x3 = "source"
scale_x3 = "1.000000"
scale_type_y3 = "source"
scale_y3 = "1.000000"
shader4 = "shaders/nedi-jinc.slang"
filter_linear4 = "false"
wrap_mode4 = "clamp_to_edge"
mipmap_input4 = "false"
alias4 = ""
float_framebuffer4 = "false"
srgb_framebuffer4 = "false"
scale_type_x4 = "viewport"
scale_x4 = "1.000000"
scale_type_y4 = "viewport"
scale_y4 = "1.000000"
CS_SHARPNESS = "0.300000"
NEDI_E = "0.650000"

View File

@ -1,7 +1,7 @@
shaders = "4"
shader0 = "shaders/nedi-pass0.slang"
filter_linear0 = false
wrap_mode0 = "clamp_to_border"
wrap_mode0 = "clamp_to_edge"
float_framebuffer0 = "false"
scale_type_x0 = "source"
scale_x0 = "2.000000"
@ -9,7 +9,7 @@ scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "shaders/nedi-pass1.slang"
filter_linear1 = false
wrap_mode1 = "clamp_to_border"
wrap_mode1 = "clamp_to_edge"
float_framebuffer1 = "false"
scale_type_x1 = "source"
scale_x1 = "1.000000"
@ -17,7 +17,7 @@ scale_type_y1 = "source"
scale_y1 = "2.000000"
shader2 = "shaders/nedi-pass2.slang"
filter_linear2 = false
wrap_mode2 = "clamp_to_border"
wrap_mode2 = "clamp_to_edge"
float_framebuffer2 = "false"
scale_type_x2 = "source"
scale_x2 = "1.000000"
@ -25,6 +25,6 @@ scale_type_y2 = "source"
scale_y2 = "1.000000"
shader3 = "shaders/nedi-jinc.slang"
filter_linear3 = false
wrap_mode3 = "clamp_to_border"
wrap_mode3 = "clamp_to_edge"
float_framebuffer3 = "false"
scale_type3 = viewport

View File

@ -46,9 +46,9 @@ layout(push_constant) uniform Push
float NEDI_JINC2_AR_STRENGTH;
} params;
#pragma parameter NEDI_JINC2_WINDOW_SINC "Window Sinc Param" 0.42 0.0 1.0 0.01
#pragma parameter NEDI_JINC2_SINC "Sinc Param" 0.92 0.0 1.0 0.01
#pragma parameter NEDI_JINC2_AR_STRENGTH "Anti-ringing Strength" 0.8 0.0 1.0 0.1
#pragma parameter NEDI_JINC2_WINDOW_SINC "Window Sinc Param" 0.46 0.0 1.0 0.01
#pragma parameter NEDI_JINC2_SINC "Sinc Param" 0.88 0.0 1.0 0.01
#pragma parameter NEDI_JINC2_AR_STRENGTH "Anti-ringing Strength" 0.0 0.0 1.0 0.1
#define JINC2_WINDOW_SINC params.NEDI_JINC2_WINDOW_SINC
#define JINC2_SINC params.NEDI_JINC2_SINC

View File

@ -33,6 +33,7 @@ layout(push_constant) uniform Push
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float NEDI_E;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
@ -40,6 +41,10 @@ layout(std140, set = 0, binding = 0) uniform UBO
mat4 MVP;
} global;
#pragma parameter NEDI_E "EDGE STRENGTH" 0.55 0.0 1.0 0.05
#define NEDI_E (1.0-params.NEDI_E)
#define saturate(c) clamp(c, 0.0, 1.0)
#define lerp(c) mix(c)
#define mul(a,b) (b*a)
@ -63,10 +68,10 @@ layout(std140, set = 0, binding = 0) uniform UBO
#define NEDI_WEIGHT 4.0
#define NEDI_N 24.0
#define NEDI_E 0.0
//#define NEDI_E 0.0
#define NEDI_OFFSET 0.0
#define ITERATIONS 3
#define ITERATIONS 4
#define WGT 2
#define width (params.SourceSize.x)
@ -171,4 +176,4 @@ float2 tex = vTexCoord + float2(0.0, 0.25*params.SourceSize.w);
//Skip pixels on wrong grid
if (frac(tex.x*width)<0.499999) FragColor = c0;
else FragColor = vec4(c, 1.0);
}
}

View File

@ -33,6 +33,7 @@ layout(push_constant) uniform Push
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float NEDI_E;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
@ -40,6 +41,10 @@ layout(std140, set = 0, binding = 0) uniform UBO
mat4 MVP;
} global;
#pragma parameter NEDI_E "EDGE STRENGTH" 0.55 0.0 1.0 0.05
#define NEDI_E (1.0-params.NEDI_E)
#define saturate(c) clamp(c, 0.0, 1.0)
#define lerp(c) mix(c)
#define mul(a,b) (b*a)
@ -66,10 +71,10 @@ layout(std140, set = 0, binding = 0) uniform UBO
#define NEDI_WEIGHT2 4.0
#define NEDI_N2 24.0
#define NEDI_E2 0.0
//#define NEDI_E2 0.0
#define NEDI_OFFSET2 0.0
#define ITERATIONS 3
#define ITERATIONS 4
#define WGT 2
#define width (params.SourceSize.x)
@ -165,7 +170,7 @@ float2 tex = vTexCoord;
R /= n; r /= n;
//Calculate a = R^-1 . r
float e = NEDI_E2;
float e = NEDI_E;
float2 a = solve(R+e*e*I,r+e*e/2.0);
//Nomalize 'a' (prevents overshoot)
@ -178,4 +183,4 @@ float2 tex = vTexCoord;
//Skip pixels on wrong grid
if ((frac(tex.x*width/2.0)<0.4999)&&(frac(tex.y*height)<0.4999) || (frac(tex.x*width/2.0)>0.4999)&&(frac(tex.y*height)>0.4999)) FragColor = c0;
else FragColor = float4(c, 1.0);//+float4(0,0.49999,0.49999,0);
}
}

View File

@ -33,6 +33,7 @@ layout(push_constant) uniform Push
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float NEDI_E;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
@ -40,6 +41,10 @@ layout(std140, set = 0, binding = 0) uniform UBO
mat4 MVP;
} global;
#pragma parameter NEDI_E "EDGE STRENGTH" 0.55 0.0 1.0 0.05
#define NEDI_E (1.0-params.NEDI_E)
#define saturate(c) clamp(c, 0.0, 1.0)
#define lerp(c) mix(c)
#define mul(a,b) (b*a)
@ -65,9 +70,9 @@ layout(std140, set = 0, binding = 0) uniform UBO
#define NEDI_WEIGHT3 2.0
#define NEDI_N3 24.0
#define NEDI_E3 0.0
//#define NEDI_E3 0.0
#define ITERATIONS 3
#define ITERATIONS 4
#define WGT NEDI_WEIGHT3
#define width (params.SourceSize.x)
@ -155,7 +160,7 @@ void main()
R /= n; r /= n;
//Calculate a = R^-1 . r
float e = NEDI_E3;
float e = NEDI_E;
float2 a = solve(R+e*e*I,r+e*e/2.0);
//Nomalize 'a' (prevents overshoot)
@ -168,4 +173,4 @@ void main()
// float3 c = Value(dir[0]);
FragColor = float4(c, 1.0);//+float4(0,0.5,0.5,0);
}
}