Add gamma slider on checkerboard-dedither (#295)

* Add Retro-Tiles shaders

A shader designed for handheld and low res systems. It turns pixels into crisp tiles.

* Add box scaling

- Turn mandatory integer scaling;
- Add Overscan option.

* Fix gamma on retro-tiles shader

- Increased gamma from 2.2 to 2.7 for a better white balance.

* Add Gamma Slider to checkerboard-dedither

- Add Gamma Slider to checkerboard-dedither.

* Update checkerboard-dedither shaders

- Add new pattern recognitions;
- Add new option to mitigate false positives.
This commit is contained in:
Hyllian 2022-09-15 09:41:16 -03:00 committed by GitHub
parent b671e7c593
commit 797716b17a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 184 additions and 134 deletions

View file

@ -28,17 +28,16 @@
layout(push_constant) uniform Push layout(push_constant) uniform Push
{ {
vec4 SourceSize; vec4 SourceSize;
vec4 OriginalSize; vec4 OriginalSize;
vec4 OutputSize; vec4 OutputSize;
uint FrameCount; uint FrameCount;
float CD_BLEND_OPTION; float CD_BLEND_OPTION;
float CD_BLEND_LEVEL; float CD_BLEND_LEVEL;
} params; } params;
#pragma parameter CB-DEDITHER "[CHECKERBOARD-DEDITHER PARAMS]" 0.0 0.0 0.0 0.0 #pragma parameter CD_BLEND_OPTION "CHECKERBOARD-DEDITHER: [ OFF | ON ]" 1.0 0.0 1.0 1.0
#pragma parameter CD_BLEND_OPTION " [ OFF | ON ]" 1.0 0.0 1.0 1.0 #pragma parameter CD_BLEND_LEVEL " Blend Level" 1.0 0.0 1.0 0.1
#pragma parameter CD_BLEND_LEVEL " Blend Level" 1.0 0.0 1.0 0.1
#define CD_BLEND_OPTION params.CD_BLEND_OPTION #define CD_BLEND_OPTION params.CD_BLEND_OPTION
#define CD_BLEND_LEVEL params.CD_BLEND_LEVEL #define CD_BLEND_LEVEL params.CD_BLEND_LEVEL
@ -50,7 +49,7 @@ vec3 max_s(vec3 central, vec3 adj1, vec3 adj2) {return max(central, min(adj1, ad
layout(std140, set = 0, binding = 0) uniform UBO layout(std140, set = 0, binding = 0) uniform UBO
{ {
mat4 MVP; mat4 MVP;
} global; } global;
@ -72,41 +71,37 @@ layout(set = 0, binding = 2) uniform sampler2D Source;
void main() void main()
{ {
vec2 dx = vec2(1.0, 0.0)*params.SourceSize.zw; vec2 dx = vec2(1.0, 0.0)*params.SourceSize.zw;
vec2 dy = vec2(0.0, 1.0)*params.SourceSize.zw; vec2 dy = vec2(0.0, 1.0)*params.SourceSize.zw;
// Reading the texels. // Reading the texels.
vec3 C = texture(Source, vTexCoord ).xyz; vec3 C = texture(Source, vTexCoord ).xyz;
vec3 L = texture(Source, vTexCoord -dx).xyz; vec3 L = texture(Source, vTexCoord -dx).xyz;
vec3 R = texture(Source, vTexCoord +dx).xyz; vec3 R = texture(Source, vTexCoord +dx).xyz;
vec3 U = texture(Source, vTexCoord -dy).xyz; vec3 U = texture(Source, vTexCoord -dy).xyz;
vec3 D = texture(Source, vTexCoord +dy).xyz; vec3 D = texture(Source, vTexCoord +dy).xyz;
vec3 UL = texture(Source, vTexCoord -dx -dy).xyz; vec3 UL = texture(Source, vTexCoord -dx -dy).xyz;
vec3 UR = texture(Source, vTexCoord +dx -dy).xyz; vec3 UR = texture(Source, vTexCoord +dx -dy).xyz;
vec3 DL = texture(Source, vTexCoord -dx +dy).xyz; vec3 DL = texture(Source, vTexCoord -dx +dy).xyz;
vec3 DR = texture(Source, vTexCoord +dx +dy).xyz; vec3 DR = texture(Source, vTexCoord +dx +dy).xyz;
vec3 color = C; vec3 color = C;
// Get min/max samples if (CD_BLEND_OPTION == 1)
vec3 min_sample = min_s(C, L, R); {
vec3 max_sample = max_s(C, L, R); float diff = dot(max(C, max(L, R)) - min(C, min(L, R)), Y);
float diff = dot(max(max(C, L), max(C, R)) - min(min(C, L), min(C, R)), Y); diff *= (1.0 - CD_BLEND_LEVEL);
diff *= (1.0 - CD_BLEND_LEVEL); vec3 min_sample = max(min_s(C, L, R), min_s(C, U, D));
vec3 max_sample = min(max_s(C, L, R), max_s(C, U, D));
if (CD_BLEND_OPTION == 1) color = 0.5*( 1.0 + diff )*C + 0.125*( 1.0 - diff )*(L + R + U + D);
{
min_sample = max(min_sample, min_s(C, U, D));
max_sample = min(max_sample, max_s(C, U, D));
color = 0.5*( 1.0 + diff )*C + 0.125*( 1.0 - diff )*(L + R + U + D); color = clamp(color, min_sample, max_sample);
} }
color = clamp(color, min_sample, max_sample); float luma_diff = abs(dot(C, Y)-dot(color, Y));
float luma_diff = abs(dot(C, Y)-dot(color, Y)); FragColor = vec4(color, luma_diff);
FragColor = vec4(color, luma_diff);
} }

View file

@ -28,26 +28,25 @@
layout(push_constant) uniform Push layout(push_constant) uniform Push
{ {
vec4 SourceSize; vec4 SourceSize;
vec4 OriginalSize; vec4 OriginalSize;
vec4 OutputSize; vec4 OutputSize;
uint FrameCount; uint FrameCount;
float CD_BLEND_LEVEL; float CD_BLEND_LEVEL;
} params; } params;
#pragma parameter CD_BLEND_LEVEL " Blend Level" 1.0 0.0 1.0 0.1 #pragma parameter CD_BLEND_LEVEL " Blend Level" 1.0 0.0 1.0 0.1
#define CD_BLEND_LEVEL params.CD_BLEND_LEVEL #define CD_BLEND_LEVEL params.CD_BLEND_LEVEL
#define PATTERN(A) step(Delta,A)
const float Delta = 0.000000001; const float Delta = 0.000000001;
const vec3 Y = vec3( 0.299, 0.587, 0.114); const vec3 Y = vec3( 0.299, 0.587, 0.114);
vec3 min_s(vec3 central, vec3 adj1, vec3 adj2) {return min(central, max(adj1, adj2));}
vec3 max_s(vec3 central, vec3 adj1, vec3 adj2) {return max(central, min(adj1, adj2));}
layout(std140, set = 0, binding = 0) uniform UBO layout(std140, set = 0, binding = 0) uniform UBO
{ {
mat4 MVP; mat4 MVP;
} global; } global;
@ -70,53 +69,74 @@ layout(set = 0, binding = 3) uniform sampler2D LinearGamma;
void main() void main()
{ {
vec2 dx = vec2(1.0, 0.0)*params.SourceSize.zw; vec2 dx = vec2(1.0, 0.0)*params.SourceSize.zw;
vec2 dy = vec2(0.0, 1.0)*params.SourceSize.zw; vec2 dy = vec2(0.0, 1.0)*params.SourceSize.zw;
// Reading the texels. // Reading the texels.
vec4 C = texture(Source, vTexCoord ); vec4 C = texture(Source, vTexCoord );
vec4 L = texture(Source, vTexCoord -dx ); vec4 L = texture(Source, vTexCoord -dx );
vec4 R = texture(Source, vTexCoord +dx ); vec4 R = texture(Source, vTexCoord +dx );
vec4 U = texture(Source, vTexCoord -dy); vec4 U = texture(Source, vTexCoord -dy);
vec4 D = texture(Source, vTexCoord +dy); vec4 D = texture(Source, vTexCoord +dy);
vec4 UL = texture(Source, vTexCoord -dx -dy); vec4 UL = texture(Source, vTexCoord -dx -dy);
vec4 UR = texture(Source, vTexCoord +dx -dy); vec4 UR = texture(Source, vTexCoord +dx -dy);
vec4 DL = texture(Source, vTexCoord -dx +dy); vec4 DL = texture(Source, vTexCoord -dx +dy);
vec4 DR = texture(Source, vTexCoord +dx +dy); vec4 DR = texture(Source, vTexCoord +dx +dy);
vec3 color = C.rgb; vec4 L2 = texture(Source, vTexCoord -2.0*dx );
vec4 R2 = texture(Source, vTexCoord +2.0*dx );
vec4 U2 = texture(Source, vTexCoord -2.0*dy);
vec4 D2 = texture(Source, vTexCoord +2.0*dy);
vec3 oriC = texture(LinearGamma, vTexCoord ).rgb; vec4 UL2 = texture(Source, vTexCoord -2.0*dx -dy);
vec3 oriL = texture(LinearGamma, vTexCoord -dx ).rgb; vec4 UR2 = texture(Source, vTexCoord +2.0*dx -dy);
vec3 oriR = texture(LinearGamma, vTexCoord +dx ).rgb; vec4 DL2 = texture(Source, vTexCoord -2.0*dx +dy);
vec3 oriU = texture(LinearGamma, vTexCoord -dy).rgb; vec4 DR2 = texture(Source, vTexCoord +2.0*dx +dy);
vec3 oriD = texture(LinearGamma, vTexCoord +dy).rgb;
float count1 = 0.0; vec4 LU2 = texture(Source, vTexCoord -dx -2.0*dy);
float count2 = 0.0; vec4 RU2 = texture(Source, vTexCoord +dx -2.0*dy);
vec4 LD2 = texture(Source, vTexCoord -dx +2.0*dy);
vec4 RD2 = texture(Source, vTexCoord +dx -2.0*dy);
float diff = (1.0 - CD_BLEND_LEVEL); vec3 color = C.rgb;
// UL U UR vec3 oriC = texture(LinearGamma, vTexCoord ).rgb;
// L C R vec3 oriL = texture(LinearGamma, vTexCoord -dx ).rgb;
// DL D DR vec3 oriR = texture(LinearGamma, vTexCoord +dx ).rgb;
vec3 oriU = texture(LinearGamma, vTexCoord -dy).rgb;
vec3 oriD = texture(LinearGamma, vTexCoord +dy).rgb;
count1 += (step(Delta, L.a*D.a*R.a)); float count1 = 0.0;
count1 += (step(Delta, L.a*U.a*R.a)); float count2 = 0.0;
count1 += (step(Delta, L.a*UL.a*R.a*UR.a + L.a*DL.a*R.a*DR.a));
count2 += (step(Delta, U.a*L.a*D.a)); float diff = (1.0 - CD_BLEND_LEVEL);
count2 += (step(Delta, U.a*R.a*D.a));
count2 += (step(Delta, U.a*UR.a*D.a*DR.a + D.a*DL.a*U.a*UL.a));
if ((count1 * count2) > 0.0) // LU2 U2 RU2
color = 0.5*(1.0+diff)*oriC + 0.125*(1.0-diff)*(oriL + oriR + oriU + oriD); // UL2 UL U UR UR2
else if (count1 > 0.0) // L2 L C R R2
color = 0.5*(1.0+diff)*oriC + 0.25*(1.0-diff)*(oriL + oriR); // DL2 DL D DR DR2
else if (count2 > 0.0) // LD2 D2 RD2
color = 0.5*(1.0+diff)*oriC + 0.25*(1.0-diff)*(oriU + oriD);
float luma_diff = abs(dot(oriC, Y)-dot(color, Y)); count1 += PATTERN(L.a*D.a*R.a);
count1 += PATTERN(L.a*U.a*R.a);
count1 += PATTERN(L.a*UL.a*R.a*UR.a + L.a*DL.a*R.a*DR.a);
FragColor = vec4(color, luma_diff); count1 += PATTERN(U.a*D2.a*(UL.a*LD2.a + UR.a*RD2.a) + U2.a*D.a*(LU2.a*DL.a + RU2.a*DR.a));
count2 += PATTERN(U.a*L.a*D.a);
count2 += PATTERN(U.a*R.a*D.a);
count2 += PATTERN(U.a*UR.a*D.a*DR.a + D.a*DL.a*U.a*UL.a);
count2 += PATTERN(L.a*R2.a*(DL.a*DR2.a + UL.a*UR2.a) + L2.a*R.a*(DL2.a*DR.a + UL2.a*UR.a));
if ((count1 * count2) > 0.0 && count1 == count2)
color = 0.5*(1.0+diff)*oriC + 0.125*(1.0-diff)*(oriL + oriR + oriU + oriD);
else if (count1 > 0.0 && count1 > count2)
color = 0.5*(1.0+diff)*oriC + 0.25*(1.0-diff)*(oriL + oriR);
else if (count2 > 0.0 && count2 > count1)
color = 0.5*(1.0+diff)*oriC + 0.25*(1.0-diff)*(oriU + oriD);
float luma_diff = abs(dot(oriC, Y)-dot(color, Y));
FragColor = vec4(color, luma_diff);
} }

View file

@ -28,33 +28,37 @@
layout(push_constant) uniform Push layout(push_constant) uniform Push
{ {
vec4 SourceSize; vec4 SourceSize;
vec4 OriginalSize; vec4 OriginalSize;
vec4 OutputSize; vec4 OutputSize;
uint FrameCount; uint FrameCount;
float CD_HUD_DETAILS; float CD_MITIG_NEIGHBRS;
float CD_ADJUST_VIEW; float CD_MITIG_LINES;
float CD_ADJUST_VIEW;
float UseGamma;
} params; } params;
#pragma parameter CD_HUD_DETAILS " Details Threshold" 1.0 0.0 5.0 1.0 #pragma parameter CD_MITIG_NEIGHBRS " Mitigate Errors (neighbors)" 1.0 0.0 4.0 1.0
#pragma parameter CD_ADJUST_VIEW " Adjust View" 0.0 0.0 1.0 1.0 #pragma parameter CD_MITIG_LINES " Mitigate Errors (regions)" 0.0 0.0 1.0 1.0
#pragma parameter CD_ADJUST_VIEW " Adjust View" 0.0 0.0 1.0 1.0
#pragma parameter UseGamma " Gamma Slider" 1.0 0.0 1.0 0.1
#define CD_HUD_DETAILS params.CD_HUD_DETAILS #define CD_MITIG_NEIGHBRS params.CD_MITIG_NEIGHBRS
#define CD_ADJUST_VIEW params.CD_ADJUST_VIEW #define CD_MITIG_LINES params.CD_MITIG_LINES
#define CD_ADJUST_VIEW params.CD_ADJUST_VIEW
#define UseGamma params.UseGamma
#define OuputGamma (UseGamma+1.0)
#define GAMMA_EXP 2.0 #define GAMMA_OUT(color) pow(color, vec3(1.0 / OuputGamma, 1.0 / OuputGamma, 1.0 / OuputGamma))
#define GAMMA_IN(color) pow(color, vec3(GAMMA_EXP, GAMMA_EXP, GAMMA_EXP))
#define GAMMA_OUT(color) pow(color, vec3(1.0 / GAMMA_EXP, 1.0 / GAMMA_EXP, 1.0 / GAMMA_EXP)) #define PATTERN(A) step(Delta,A)
const float Delta = 0.000000001; const float Delta = 0.000000001;
const vec3 Y = vec3( 0.299, 0.587, 0.114); const vec3 Y = vec3( 0.299, 0.587, 0.114);
vec3 min_s(vec3 central, vec3 adj1, vec3 adj2) {return min(central, max(adj1, adj2));}
vec3 max_s(vec3 central, vec3 adj1, vec3 adj2) {return max(central, min(adj1, adj2));}
layout(std140, set = 0, binding = 0) uniform UBO layout(std140, set = 0, binding = 0) uniform UBO
{ {
mat4 MVP; mat4 MVP;
} global; } global;
@ -77,45 +81,72 @@ layout(set = 0, binding = 3) uniform sampler2D LinearGamma;
void main() void main()
{ {
vec2 dx = vec2(1.0, 0.0)*params.SourceSize.zw; vec2 dx = vec2(1.0, 0.0)*params.SourceSize.zw;
vec2 dy = vec2(0.0, 1.0)*params.SourceSize.zw; vec2 dy = vec2(0.0, 1.0)*params.SourceSize.zw;
// Reading the texels. // Reading the texels.
vec4 C = texture(Source, vTexCoord ); vec4 C = texture(Source, vTexCoord );
vec4 L = texture(Source, vTexCoord -dx ); vec4 L = texture(Source, vTexCoord -dx );
vec4 R = texture(Source, vTexCoord +dx ); vec4 R = texture(Source, vTexCoord +dx );
vec4 U = texture(Source, vTexCoord -dy); vec4 U = texture(Source, vTexCoord -dy);
vec4 D = texture(Source, vTexCoord +dy); vec4 D = texture(Source, vTexCoord +dy);
vec4 UL = texture(Source, vTexCoord -dx -dy); vec4 UL = texture(Source, vTexCoord -dx -dy);
vec4 UR = texture(Source, vTexCoord +dx -dy); vec4 UR = texture(Source, vTexCoord +dx -dy);
vec4 DL = texture(Source, vTexCoord -dx +dy); vec4 DL = texture(Source, vTexCoord -dx +dy);
vec4 DR = texture(Source, vTexCoord +dx +dy); vec4 DR = texture(Source, vTexCoord +dx +dy);
vec3 color = C.rgb; vec4 L2 = texture(Source, vTexCoord -2.0*dx );
vec4 R2 = texture(Source, vTexCoord +2.0*dx );
vec4 U2 = texture(Source, vTexCoord -2.0*dy);
vec4 D2 = texture(Source, vTexCoord +2.0*dy);
vec3 oriC = texture(LinearGamma, vTexCoord ).rgb; vec4 L3 = texture(Source, vTexCoord -3.0*dx );
vec4 R3 = texture(Source, vTexCoord +3.0*dx );
vec4 U3 = texture(Source, vTexCoord -3.0*dy);
vec4 D3 = texture(Source, vTexCoord +3.0*dy);
float count = 0.0; vec3 color = C.rgb;
float count2 = 0.0;
// UL U UR vec3 oriC = texture(LinearGamma, vTexCoord ).rgb;
// L C R
// DL D DR
count += step(Delta, L.a); float count = 0.0;
count += step(Delta, R.a); float count2 = 0.0;
count += step(Delta, U.a); float count3 = 0.0;
count += step(Delta, D.a);
count += step(Delta, UL.a*UR.a*DL.a*DR.a);
count2 += (step(Delta, L.a*UL.a*U.a + U.a*UR.a*R.a + R.a*DR.a*D.a + D.a*DL.a*L.a)); // U3
// U2
// UL U UR
// L3 L2 L C R R2 R3
// DL D DR
// D2
// D3
if ((count < CD_HUD_DETAILS) && (count2 < 1.0)) count += PATTERN(L.a);
color = oriC; count += PATTERN(R.a);
count += PATTERN(U.a);
count += PATTERN(D.a);
count += PATTERN(UL.a*UR.a*DL.a*DR.a);
float luma_diff = abs(dot(oriC, Y)-dot(color, Y)); count2 += PATTERN(L.a*UL.a*U.a + U.a*UR.a*R.a + R.a*DR.a*D.a + D.a*DL.a*L.a);
color = mix(color, vec3(luma_diff), CD_ADJUST_VIEW); count3 += PATTERN(L3.a*L2.a*L.a);
count3 += PATTERN(L2.a*L.a*R.a);
count3 += PATTERN(L.a*R.a*R2.a);
count3 += PATTERN(R.a*R2.a*R3.a);
FragColor = vec4(GAMMA_OUT(color), 1.0); count3 += PATTERN(U3.a*U2.a*U.a);
count3 += PATTERN(U2.a*U.a*D.a);
count3 += PATTERN(U.a*D.a*D2.a);
count3 += PATTERN(D.a*D2.a*D3.a);
if ((count < CD_MITIG_NEIGHBRS) && (count2 < 1.0))
color = oriC;
else if ((CD_MITIG_LINES == 1.0) && (count3 < 1.0))
color = oriC;
float luma_diff = abs(dot(oriC, Y)-dot(color, Y));
color = mix(color, vec3(luma_diff), CD_ADJUST_VIEW);
FragColor = vec4(GAMMA_OUT(color), 1.0);
} }

View file

@ -6,11 +6,15 @@ layout(push_constant) uniform Push
vec4 OriginalSize; vec4 OriginalSize;
vec4 OutputSize; vec4 OutputSize;
uint FrameCount; uint FrameCount;
float InputGamma; float CD_BLEND_OPTION;
float UseGamma;
} params; } params;
#pragma parameter CD_BLEND_OPTION "CHECKERBOARD-DEDITHER: [ OFF | ON ]" 1.0 0.0 1.0 1.0
#pragma parameter UseGamma " Gamma Slider" 1.0 0.0 1.0 0.1
#define InputGamma 2.0 #define UseGamma params.UseGamma
#define InputGamma (UseGamma+1.0)
#define GAMMA_IN(color) pow(color, vec3(InputGamma, InputGamma, InputGamma)) #define GAMMA_IN(color) pow(color, vec3(InputGamma, InputGamma, InputGamma))