mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 15:51:30 +11:00
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:
parent
b671e7c593
commit
797716b17a
|
@ -36,8 +36,7 @@ layout(push_constant) uniform Push
|
||||||
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
|
||||||
|
@ -88,23 +87,19 @@ void main()
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
if (CD_BLEND_OPTION == 1)
|
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));
|
||||||
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 = 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));
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,11 @@ layout(push_constant) uniform Push
|
||||||
|
|
||||||
#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;
|
||||||
|
@ -84,6 +83,21 @@ void main()
|
||||||
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
vec4 UL2 = texture(Source, vTexCoord -2.0*dx -dy);
|
||||||
|
vec4 UR2 = texture(Source, vTexCoord +2.0*dx -dy);
|
||||||
|
vec4 DL2 = texture(Source, vTexCoord -2.0*dx +dy);
|
||||||
|
vec4 DR2 = texture(Source, vTexCoord +2.0*dx +dy);
|
||||||
|
|
||||||
|
vec4 LU2 = texture(Source, vTexCoord -dx -2.0*dy);
|
||||||
|
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);
|
||||||
|
|
||||||
vec3 color = C.rgb;
|
vec3 color = C.rgb;
|
||||||
|
|
||||||
vec3 oriC = texture(LinearGamma, vTexCoord ).rgb;
|
vec3 oriC = texture(LinearGamma, vTexCoord ).rgb;
|
||||||
|
@ -97,23 +111,29 @@ void main()
|
||||||
|
|
||||||
float diff = (1.0 - CD_BLEND_LEVEL);
|
float diff = (1.0 - CD_BLEND_LEVEL);
|
||||||
|
|
||||||
// UL U UR
|
// LU2 U2 RU2
|
||||||
// L C R
|
// UL2 UL U UR UR2
|
||||||
// DL D DR
|
// L2 L C R R2
|
||||||
|
// DL2 DL D DR DR2
|
||||||
|
// LD2 D2 RD2
|
||||||
|
|
||||||
count1 += (step(Delta, L.a*D.a*R.a));
|
count1 += PATTERN(L.a*D.a*R.a);
|
||||||
count1 += (step(Delta, L.a*U.a*R.a));
|
count1 += PATTERN(L.a*U.a*R.a);
|
||||||
count1 += (step(Delta, L.a*UL.a*R.a*UR.a + L.a*DL.a*R.a*DR.a));
|
count1 += PATTERN(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));
|
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 += (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)
|
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);
|
color = 0.5*(1.0+diff)*oriC + 0.125*(1.0-diff)*(oriL + oriR + oriU + oriD);
|
||||||
else if (count1 > 0.0)
|
else if (count1 > 0.0 && count1 > count2)
|
||||||
color = 0.5*(1.0+diff)*oriC + 0.25*(1.0-diff)*(oriL + oriR);
|
color = 0.5*(1.0+diff)*oriC + 0.25*(1.0-diff)*(oriL + oriR);
|
||||||
else if (count2 > 0.0)
|
else if (count2 > 0.0 && count2 > count1)
|
||||||
color = 0.5*(1.0+diff)*oriC + 0.25*(1.0-diff)*(oriU + oriD);
|
color = 0.5*(1.0+diff)*oriC + 0.25*(1.0-diff)*(oriU + oriD);
|
||||||
|
|
||||||
float luma_diff = abs(dot(oriC, Y)-dot(color, Y));
|
float luma_diff = abs(dot(oriC, Y)-dot(color, Y));
|
||||||
|
|
|
@ -32,26 +32,30 @@ layout(push_constant) uniform Push
|
||||||
vec4 OriginalSize;
|
vec4 OriginalSize;
|
||||||
vec4 OutputSize;
|
vec4 OutputSize;
|
||||||
uint FrameCount;
|
uint FrameCount;
|
||||||
float CD_HUD_DETAILS;
|
float CD_MITIG_NEIGHBRS;
|
||||||
|
float CD_MITIG_LINES;
|
||||||
float CD_ADJUST_VIEW;
|
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_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 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_MITIG_LINES params.CD_MITIG_LINES
|
||||||
#define CD_ADJUST_VIEW params.CD_ADJUST_VIEW
|
#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;
|
||||||
|
@ -91,26 +95,53 @@ void main()
|
||||||
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
vec3 color = C.rgb;
|
vec3 color = C.rgb;
|
||||||
|
|
||||||
vec3 oriC = texture(LinearGamma, vTexCoord ).rgb;
|
vec3 oriC = texture(LinearGamma, vTexCoord ).rgb;
|
||||||
|
|
||||||
float count = 0.0;
|
float count = 0.0;
|
||||||
float count2 = 0.0;
|
float count2 = 0.0;
|
||||||
|
float count3 = 0.0;
|
||||||
|
|
||||||
|
// U3
|
||||||
|
// U2
|
||||||
// UL U UR
|
// UL U UR
|
||||||
// L C R
|
// L3 L2 L C R R2 R3
|
||||||
// DL D DR
|
// DL D DR
|
||||||
|
// D2
|
||||||
|
// D3
|
||||||
|
|
||||||
count += step(Delta, L.a);
|
count += PATTERN(L.a);
|
||||||
count += step(Delta, R.a);
|
count += PATTERN(R.a);
|
||||||
count += step(Delta, U.a);
|
count += PATTERN(U.a);
|
||||||
count += step(Delta, D.a);
|
count += PATTERN(D.a);
|
||||||
count += step(Delta, UL.a*UR.a*DL.a*DR.a);
|
count += PATTERN(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));
|
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);
|
||||||
|
|
||||||
if ((count < CD_HUD_DETAILS) && (count2 < 1.0))
|
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);
|
||||||
|
|
||||||
|
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;
|
color = oriC;
|
||||||
|
|
||||||
float luma_diff = abs(dot(oriC, Y)-dot(color, Y));
|
float luma_diff = abs(dot(oriC, Y)-dot(color, Y));
|
||||||
|
|
|
@ -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))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue