Less naive palette shader.

This commit is contained in:
Marisa the Magician 2023-02-26 16:31:20 +01:00
commit a0521259a7
14 changed files with 57 additions and 7 deletions

BIN
Logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 KiB

After

Width:  |  Height:  |  Size: 282 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 116 KiB

After

Width:  |  Height:  |  Size: 102 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Before After
Before After

View file

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

View file

@ -191,6 +191,8 @@ HardwareShader postprocess scene
Uniform vec2 sfact Uniform vec2 sfact
Uniform float palsat Uniform float palsat
Uniform float palpow Uniform float palpow
Uniform float paldither Uniform int paldepth
Uniform int dsize
Uniform int doffset
Uniform int palnum Uniform int palnum
} }

View file

@ -78,6 +78,11 @@ MFX_PALETTE61="RGB3";
MFX_PALETTE62="RGB4"; MFX_PALETTE62="RGB4";
MFX_PALETTE63="RGB5"; MFX_PALETTE63="RGB5";
MFX_PALETTE64="RGB6"; MFX_PALETTE64="RGB6";
MFX_DITHER1="Checkerboard";
MFX_DITHER2="Bayer 2x2";
MFX_DITHER3="Bayer 4x4";
MFX_DITHER4="Bayer 8x8";
MFX_DITHER5="Bayer 16x16";
MFX_LUT1="Skyrim Day"; MFX_LUT1="Skyrim Day";
MFX_LUT2="Skyrim Interior Day"; MFX_LUT2="Skyrim Interior Day";
MFX_LUT3="Skyrim Interior Night"; MFX_LUT3="Skyrim Interior Night";
@ -226,6 +231,7 @@ MFX_PALNUM="Palette";
MFX_PALSAT="Saturation"; MFX_PALSAT="Saturation";
MFX_PALPOW="Gamma"; MFX_PALPOW="Gamma";
MFX_PALDITHER="Dithering"; MFX_PALDITHER="Dithering";
MFX_PALDEPTH="Depth";
MFX_PRESETNUM="Preset Slot"; MFX_PRESETNUM="Preset Slot";
MFX_PRESETNAME="Preset Name"; MFX_PRESETNAME="Preset Name";
MFX_LOADPRESET="Load Preset"; MFX_LOADPRESET="Load Preset";

View file

@ -105,6 +105,15 @@ OptionValue "MFXPalette"
63, "$MFX_PALETTE64" 63, "$MFX_PALETTE64"
} }
OptionValue "MFXDither"
{
0, "$MFX_DITHER1"
1, "$MFX_DITHER2"
2, "$MFX_DITHER3"
3, "$MFX_DITHER4"
4, "$MFX_DITHER5"
}
OptionValue "MFXLUT" OptionValue "MFXLUT"
{ {
0, "$MFX_LUT1" 0, "$MFX_LUT1"
@ -308,6 +317,7 @@ OptionMenu "MFXOptionsMenu"
Option "$MFX_PALNUM", "mfx_palnum", "MFXPalette" Option "$MFX_PALNUM", "mfx_palnum", "MFXPalette"
MFXSlider "$MFX_PALSAT", "mfx_palsat", 0, 2, 0.01, 2 MFXSlider "$MFX_PALSAT", "mfx_palsat", 0, 2, 0.01, 2
MFXSlider "$MFX_PALPOW", "mfx_palpow", 0, 2, 0.01, 2 MFXSlider "$MFX_PALPOW", "mfx_palpow", 0, 2, 0.01, 2
MFXSlider "$MFX_PALDITHER", "mfx_paldither", 0, 1, 0.01, 2 Option "$MFX_PALDITHER", "mfx_paldither", "MFXDither"
MFXSlider "$MFX_PALDEPTH", "mfx_paldepth", 1, 6, 1, 0
SafeCommand "$MFX_RESET", "event resetmfxvars 7" SafeCommand "$MFX_RESET", "event resetmfxvars 7"
} }

View file

@ -26,9 +26,16 @@ void main()
hsv.y = clamp(hsv.y*palsat,0.,1.); hsv.y = clamp(hsv.y*palsat,0.,1.);
hsv.z = pow(max(hsv.z,0.),palpow); hsv.z = pow(max(hsv.z,0.),palpow);
res.rgb = hsv2rgb(hsv); res.rgb = hsv2rgb(hsv);
ivec2 dcoord = ivec2(int(coord.x*sfact.x)%8,int(coord.y*sfact.y)%8); float cstep = float(paldepth);
res.rgb += paldither*texelFetch(DitherTexture,dcoord,0).x-.5*paldither; float cdiv = 1./cstep;
vec3 lc = clamp(floor(res.rgb*64),0,63); 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);
vec3 lc = clamp(floor(res.rgb*64.),0.,63.);
ivec2 lcoord = ivec2(lc.r,lc.g+lc.b*64); ivec2 lcoord = ivec2(lc.r,lc.g+lc.b*64);
lcoord.x += 64*palnum; lcoord.x += 64*palnum;
res.rgb = texelFetch(PalLUTTexture,lcoord,0).rgb; res.rgb = texelFetch(PalLUTTexture,lcoord,0).rgb;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 720 KiB

After

Width:  |  Height:  |  Size: 720 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 B

After

Width:  |  Height:  |  Size: 166 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5 MiB

After

Width:  |  Height:  |  Size: 4.6 MiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 MiB

After

Width:  |  Height:  |  Size: 3.9 MiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 569 KiB

After

Width:  |  Height:  |  Size: 503 KiB

Before After
Before After

View file

@ -164,8 +164,31 @@ Class MariFXHandler : StaticEventHandler
Shader.SetUniform2f(p,"mfx_palette","sfact",mfx_retroenable?bresl:rresl); Shader.SetUniform2f(p,"mfx_palette","sfact",mfx_retroenable?bresl:rresl);
Shader.SetUniform1f(p,"mfx_palette","palsat",mfx_palsat); Shader.SetUniform1f(p,"mfx_palette","palsat",mfx_palsat);
Shader.SetUniform1f(p,"mfx_palette","palpow",mfx_palpow); Shader.SetUniform1f(p,"mfx_palette","palpow",mfx_palpow);
Shader.SetUniform1i(p,"mfx_palette","paldepth",mfx_paldepth);
switch ( mfx_paldither )
{
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",2);
Shader.SetUniform1i(p,"mfx_palette","doffset",0);
break;
}
Shader.SetUniform1i(p,"mfx_palette","palnum",mfx_palnum); Shader.SetUniform1i(p,"mfx_palette","palnum",mfx_palnum);
Shader.SetUniform1f(p,"mfx_palette","paldither",mfx_paldither);
} }
override void ConsoleProcess( ConsoleEvent e ) override void ConsoleProcess( ConsoleEvent e )
{ {
@ -297,6 +320,7 @@ Class MariFXHandler : StaticEventHandler
CVar.FindCVar('mfx_palsat').ResetToDefault(); CVar.FindCVar('mfx_palsat').ResetToDefault();
CVar.FindCVar('mfx_palpow').ResetToDefault(); CVar.FindCVar('mfx_palpow').ResetToDefault();
CVar.FindCVar('mfx_paldither').ResetToDefault(); CVar.FindCVar('mfx_paldither').ResetToDefault();
CVar.FindCVar('mfx_paldepth').ResetToDefault();
break; break;
case 8: case 8:
CVar.FindCVar('mfx_lsharpenable').ResetToDefault(); CVar.FindCVar('mfx_lsharpenable').ResetToDefault();