Updates to palette filter.

This commit is contained in:
Marisa the Magician 2022-02-05 22:48:15 +01:00
commit 3f83453ee7
4 changed files with 22 additions and 33 deletions

View file

@ -174,6 +174,7 @@ HardwareShader postprocess scene
{
Name "mfx_palette"
Shader "shaders/glsl/mfx_palette.fp" 330
Texture DitherTexture "textures/mfxdither.png"
Texture PalLUTTexture "textures/mfxpal.png"
Uniform vec2 sfact
Uniform float palsat

View file

@ -1,51 +1,33 @@
/*
RetroFX palette reduction from MariENB
(C)2012-2021 Marisa Kirisame
(C)2012-2022 Marisa Kirisame
*/
vec3 rgb2hsv( vec3 c )
{
vec4 K = vec4(0.0,-1.0/3.0,2.0/3.0,-1.0);
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.0e-10;
return vec3(abs(q.z+(q.w-q.y)/(6.0*d+e)),d/(q.x+e),q.x);
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.0,2.0/3.0,1.0/3.0,3.0);
vec3 p = abs(fract(c.xxx+K.xyz)*6.0-K.www);
return c.z*mix(K.xxx,clamp(p-K.xxx,0.0,1.0),c.y);
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()
{
#define d(x) x/64.0
float dither8[64] = float[]
(
d( 0),d(48),d(12),d(60),d( 3),d(51),d(15),d(63),
d(32),d(16),d(44),d(28),d(35),d(19),d(47),d(31),
d( 8),d(56),d( 4),d(52),d(11),d(59),d( 7),d(55),
d(40),d(24),d(36),d(20),d(43),d(27),d(39),d(23),
d( 2),d(50),d(14),d(62),d( 1),d(49),d(13),d(61),
d(34),d(18),d(46),d(30),d(33),d(17),d(45),d(29),
d(10),d(58),d( 6),d(54),d( 9),d(57),d( 5),d(53),
d(42),d(26),d(38),d(22),d(41),d(25),d(37),d(21)
);
#undef d
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);
if ( res.r <= 0.0 ) res.r -= paldither;
if ( res.g <= 0.0 ) res.g -= paldither;
if ( res.b <= 0.0 ) res.b -= paldither;
if ( res.r >= 1.0 ) res.r += paldither;
if ( res.g >= 1.0 ) res.g += paldither;
if ( res.b >= 1.0 ) res.b += paldither;
res.rgb += paldither*dither8[int(coord.x*sfact.x)%8+int(coord.y*sfact.y)%8*8]-0.5*paldither;
ivec2 dcoord = ivec2(int(coord.x*sfact.x)%8,int(coord.y*sfact.y)%8);
res.rgb += paldither*texelFetch(DitherTexture,dcoord,0).x-.5*paldither;
vec3 lc = clamp(floor(res.rgb*64),0,63);
ivec2 lcoord = ivec2(lc.r,lc.g+lc.b*64);
lcoord.x += 64*palnum;

BIN
textures/mfxdither.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

View file

@ -159,11 +159,22 @@ Class OptionMenuItemMFXSlider : OptionMenuItemSlider
// passes shift/alt presses to MFXSliders
Class MFXOptionMenu : OptionMenu
{
private void UpdatePresetNames()
{
for ( int i=0; i<mDesc.mItems.size(); i++ )
{
if ( !(mDesc.mItems[i] is 'OptionMenuItemMFXPresetList') )
continue;
OptionMenuItemMFXPresetList(mDesc.mItems[i]).UpdateNames();
}
}
override void Init( Menu parent, OptionMenuDescriptor desc )
{
Super.init(parent,desc);
DontDim = true;
DontBlur = true;
UpdatePresetNames();
}
override bool OnUIEvent( UIEvent ev )
@ -181,11 +192,6 @@ Class MFXOptionMenu : OptionMenu
override void OnReturn()
{
Super.OnReturn();
for ( int i=0; i<mDesc.mItems.size(); i++ )
{
if ( !(mDesc.mItems[i] is 'OptionMenuItemMFXPresetList') )
continue;
OptionMenuItemMFXPresetList(mDesc.mItems[i]).UpdateNames();
}
UpdatePresetNames();
}
}