Keep old naive dither as an option.

This commit is contained in:
Marisa the Magician 2023-03-04 18:19:38 +01:00
commit e8b7b1c29f
10 changed files with 145 additions and 36 deletions

View file

@ -1,4 +1,4 @@
Copyright (c) 2019-2022 Marisa the Magician, UnSX Team
Copyright (c) 2019-2023 Marisa the Magician, UnSX Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -119,8 +119,10 @@ nosave bool mfx_palenable = false;
nosave int mfx_palnum = 0;
nosave float mfx_palsat = 1.;
nosave float mfx_palpow = 1.;
nosave bool mfx_palnaive = false;
nosave int mfx_paldither = 3;
nosave int mfx_paldepth = 8;
nosave float mfx_palspread = .05;
nosave string mfx_presetname = "Unnamed";

View file

@ -196,3 +196,17 @@ HardwareShader postprocess scene
Uniform int doffset
Uniform int palnum
}
HardwareShader postprocess scene
{
Name "mfx_palette_naive"
Shader "shaders/glsl/mfx_palette_naive.fp" 330
Texture DitherTexture "textures/mfxdither.png"
Texture PalLUTTexture "textures/mfxpal.png"
Uniform vec2 sfact
Uniform float palsat
Uniform float palpow
Uniform float paldither
Uniform int dsize
Uniform int doffset
Uniform int palnum
}

View file

@ -231,8 +231,10 @@ MFX_PALENABLE="Enable Palette";
MFX_PALNUM="Palette";
MFX_PALSAT="Saturation";
MFX_PALPOW="Gamma";
MFX_PALDITHER="Dithering";
MFX_PALNAIVE="Naive Dithering";
MFX_PALDITHER="Dither Pattern";
MFX_PALDEPTH="Depth";
MFX_PALSPREAD="Spread";
MFX_PRESETNUM="Preset Slot";
MFX_PRESETNAME="Preset Name";
MFX_LOADPRESET="Load Preset";

View file

@ -318,7 +318,9 @@ OptionMenu "MFXOptionsMenu"
Option "$MFX_PALNUM", "mfx_palnum", "MFXPalette"
MFXSlider "$MFX_PALSAT", "mfx_palsat", 0, 2, 0.01, 2
MFXSlider "$MFX_PALPOW", "mfx_palpow", 0, 2, 0.01, 2
Option "$MFX_PALNAIVE", "mfx_palnaive", "YesNo"
Option "$MFX_PALDITHER", "mfx_paldither", "MFXDither"
MFXSlider "$MFX_PALDEPTH", "mfx_paldepth", 1, 16, 1, 0
MFXSlider "$MFX_PALSPREAD", "mfx_palspread", 0, 1, 0.01, 2
SafeCommand "$MFX_RESET", "event resetmfxvars 7"
}

View file

@ -1,6 +1,6 @@
/*
RetroFX palette reduction from MariENB
(C)2012-2022 Marisa the Magician
(C)2012-2023 Marisa the Magician
*/
vec3 rgb2hsv( vec3 c )
{
@ -26,12 +26,12 @@ void main()
hsv.y = clamp(hsv.y*palsat,0.,1.);
hsv.z = pow(max(hsv.z,0.),palpow);
res.rgb = hsv2rgb(hsv);
ivec2 dcoord = ivec2(int(coord.x*sfact.x)%dsize,int(coord.y*sfact.y)%dsize+doffset);
float cstep = float(paldepth);
float cdiv = 1./cstep;
vec3 cl = floor(res.rgb*cstep)*cdiv;
vec3 ch = ceil(res.rgb*cstep)*cdiv;
vec3 cf = fract(res.rgb*cstep);
ivec2 dcoord = ivec2(int(coord.x*sfact.x)%dsize,int(coord.y*sfact.y)%dsize+doffset);
float dth = texelFetch(DitherTexture,dcoord,0).x*.9375+.03125;
vec3 thr = vec3(step(dth,cf.r),step(dth,cf.g),step(dth,cf.b));
res.rgb = mix(cl,ch,thr);

View file

@ -0,0 +1,36 @@
/*
RetroFX palette reduction from MariENB
(C)2012-2023 Marisa the Magician
*/
vec3 rgb2hsv( vec3 c )
{
vec4 K = vec4(0.,-1./3.,2./3.,-1.);
vec4 p = (c.g<c.b)?vec4(c.bg,K.wz):vec4(c.gb,K.xy);
vec4 q = (c.r<p.x)?vec4(p.xyw,c.r):vec4(c.r,p.yzx);
float d = q.x-min(q.w,q.y);
float e = 1.e-10;
return vec3(abs(q.z+(q.w-q.y)/(6.*d+e)),d/(q.x+e),q.x);
}
vec3 hsv2rgb( vec3 c )
{
vec4 K = vec4(1.,2./3.,1./3.,3.);
vec3 p = abs(fract(c.xxx+K.xyz)*6.-K.www);
return c.z*mix(K.xxx,clamp(p-K.xxx,0.,1.),c.y);
}
void main()
{
vec2 coord = TexCoord;
vec4 res = texture(InputTexture,coord);
vec3 hsv = rgb2hsv(res.rgb);
hsv.y = clamp(hsv.y*palsat,0.,1.);
hsv.z = pow(max(hsv.z,0.),palpow);
res.rgb = hsv2rgb(hsv);
ivec2 dcoord = ivec2(int(coord.x*sfact.x)%dsize,int(coord.y*sfact.y)%dsize+doffset);
res.rgb += (texelFetch(DitherTexture,dcoord,0).x-.5)*paldither;
vec3 lc = clamp(floor(res.rgb*63.),0.,63.);
ivec2 lcoord = ivec2(int(lc.r),int(lc.g)+int(lc.b)*64);
lcoord.x += 64*palnum;
res.rgb = texelFetch(PalLUTTexture,lcoord,0).rgb;
FragColor = res;
}

View file

@ -2,7 +2,7 @@ version "4.7.1"
/*
MariFX Shader Suite for GZDoom
(C)2019-2022 Marisa the Magician, UnSX Team
(C)2019-2023 Marisa the Magician, UnSX Team
This copyright and the attached COPYING.txt file apply to all files
included from here.
*/

View file

@ -160,39 +160,82 @@ Class MariFXHandler : StaticEventHandler
}
Shader.SetEnabled(p,"mfx_retrofx",mfx_retroenable);
Shader.SetUniform2f(p,"mfx_retrofx","bresl",bresl);
Shader.SetEnabled(p,"mfx_palette",mfx_palenable);
Shader.SetUniform2f(p,"mfx_palette","sfact",mfx_retroenable?bresl:rresl);
Shader.SetUniform1f(p,"mfx_palette","palsat",mfx_palsat);
Shader.SetUniform1f(p,"mfx_palette","palpow",mfx_palpow);
Shader.SetUniform1i(p,"mfx_palette","paldepth",int(2.**mfx_paldepth)-1);
switch ( mfx_paldither )
if ( mfx_palnaive )
{
case 0:
Shader.SetUniform1i(p,"mfx_palette","dsize",2);
Shader.SetUniform1i(p,"mfx_palette","doffset",0);
break;
case 1:
Shader.SetUniform1i(p,"mfx_palette","dsize",2);
Shader.SetUniform1i(p,"mfx_palette","doffset",2);
break;
case 2:
Shader.SetUniform1i(p,"mfx_palette","dsize",4);
Shader.SetUniform1i(p,"mfx_palette","doffset",4);
break;
case 3:
Shader.SetUniform1i(p,"mfx_palette","dsize",8);
Shader.SetUniform1i(p,"mfx_palette","doffset",8);
break;
case 4:
Shader.SetUniform1i(p,"mfx_palette","dsize",16);
Shader.SetUniform1i(p,"mfx_palette","doffset",16);
break;
default:
Shader.SetUniform1i(p,"mfx_palette","dsize",1);
Shader.SetUniform1i(p,"mfx_palette","doffset",0);
break;
Shader.SetEnabled(p,"mfx_palette",false);
Shader.SetEnabled(p,"mfx_palette_naive",mfx_palenable);
Shader.SetUniform2f(p,"mfx_palette_naive","sfact",mfx_retroenable?bresl:rresl);
Shader.SetUniform1f(p,"mfx_palette_naive","palsat",mfx_palsat);
Shader.SetUniform1f(p,"mfx_palette_naive","palpow",mfx_palpow);
bool dospread = true;
switch ( mfx_paldither )
{
case 0:
Shader.SetUniform1i(p,"mfx_palette_naive","dsize",2);
Shader.SetUniform1i(p,"mfx_palette_naive","doffset",0);
break;
case 1:
Shader.SetUniform1i(p,"mfx_palette_naive","dsize",2);
Shader.SetUniform1i(p,"mfx_palette_naive","doffset",2);
break;
case 2:
Shader.SetUniform1i(p,"mfx_palette_naive","dsize",4);
Shader.SetUniform1i(p,"mfx_palette_naive","doffset",4);
break;
case 3:
Shader.SetUniform1i(p,"mfx_palette_naive","dsize",8);
Shader.SetUniform1i(p,"mfx_palette_naive","doffset",8);
break;
case 4:
Shader.SetUniform1i(p,"mfx_palette_naive","dsize",16);
Shader.SetUniform1i(p,"mfx_palette_naive","doffset",16);
break;
default:
Shader.SetUniform1i(p,"mfx_palette_naive","dsize",1);
Shader.SetUniform1i(p,"mfx_palette_naive","doffset",0);
dospread = false;
break;
}
Shader.SetUniform1f(p,"mfx_palette_naive","paldither",dospread?mfx_palspread:0.);
Shader.SetUniform1i(p,"mfx_palette_naive","palnum",mfx_palnum);
}
else
{
Shader.SetEnabled(p,"mfx_palette_naive",false);
Shader.SetEnabled(p,"mfx_palette",mfx_palenable);
Shader.SetUniform2f(p,"mfx_palette","sfact",mfx_retroenable?bresl:rresl);
Shader.SetUniform1f(p,"mfx_palette","palsat",mfx_palsat);
Shader.SetUniform1f(p,"mfx_palette","palpow",mfx_palpow);
Shader.SetUniform1i(p,"mfx_palette","paldepth",int(2.**mfx_paldepth)-1);
switch ( mfx_paldither )
{
case 0:
Shader.SetUniform1i(p,"mfx_palette","dsize",2);
Shader.SetUniform1i(p,"mfx_palette","doffset",0);
break;
case 1:
Shader.SetUniform1i(p,"mfx_palette","dsize",2);
Shader.SetUniform1i(p,"mfx_palette","doffset",2);
break;
case 2:
Shader.SetUniform1i(p,"mfx_palette","dsize",4);
Shader.SetUniform1i(p,"mfx_palette","doffset",4);
break;
case 3:
Shader.SetUniform1i(p,"mfx_palette","dsize",8);
Shader.SetUniform1i(p,"mfx_palette","doffset",8);
break;
case 4:
Shader.SetUniform1i(p,"mfx_palette","dsize",16);
Shader.SetUniform1i(p,"mfx_palette","doffset",16);
break;
default:
Shader.SetUniform1i(p,"mfx_palette","dsize",1);
Shader.SetUniform1i(p,"mfx_palette","doffset",0);
break;
}
Shader.SetUniform1i(p,"mfx_palette","palnum",mfx_palnum);
}
Shader.SetUniform1i(p,"mfx_palette","palnum",mfx_palnum);
}
override void ConsoleProcess( ConsoleEvent e )
{
@ -323,8 +366,10 @@ Class MariFXHandler : StaticEventHandler
CVar.FindCVar('mfx_palnum').ResetToDefault();
CVar.FindCVar('mfx_palsat').ResetToDefault();
CVar.FindCVar('mfx_palpow').ResetToDefault();
CVar.FindCVar('mfx_palnaive').ResetToDefault();
CVar.FindCVar('mfx_paldither').ResetToDefault();
CVar.FindCVar('mfx_paldepth').ResetToDefault();
CVar.FindCVar('mfx_palspread').ResetToDefault();
break;
case 8:
CVar.FindCVar('mfx_lsharpenable').ResetToDefault();

View file

@ -154,6 +154,14 @@ Class OptionMenuItemMFXSlider : OptionMenuItemSlider
Menu.MenuSound("menu/change");
return true;
}
override bool isGrayed()
{
// HACK
if ( (mAction == 'mfx_paldepth') && mfx_palnaive ) return true;
if ( (mAction == 'mfx_palspread') && !mfx_palnaive ) return true;
return Super.isGrayed();
}
}
// passes shift/alt presses to MFXSliders