From e8b7b1c29fe204aca35b20c1cfb4f95bfaa32d5f Mon Sep 17 00:00:00 2001 From: Marisa the Magician Date: Sat, 4 Mar 2023 18:19:38 +0100 Subject: [PATCH] Keep old naive dither as an option. --- COPYING.txt | 2 +- cvarinfo.marifx | 2 + gldefs.txt | 14 ++++ language.txt | 4 +- menudef.txt | 2 + shaders/glsl/mfx_palette.fp | 4 +- shaders/glsl/mfx_palette_naive.fp | 36 ++++++++++ zscript.txt | 2 +- zscript/mfx_handler.zsc | 107 +++++++++++++++++++++--------- zscript/mfx_menu.zsc | 8 +++ 10 files changed, 145 insertions(+), 36 deletions(-) create mode 100644 shaders/glsl/mfx_palette_naive.fp diff --git a/COPYING.txt b/COPYING.txt index 9cc3c06..def4413 100644 --- a/COPYING.txt +++ b/COPYING.txt @@ -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 diff --git a/cvarinfo.marifx b/cvarinfo.marifx index d0647fa..ddf8b7d 100644 --- a/cvarinfo.marifx +++ b/cvarinfo.marifx @@ -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"; diff --git a/gldefs.txt b/gldefs.txt index 5363bc2..3cf40b9 100644 --- a/gldefs.txt +++ b/gldefs.txt @@ -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 +} diff --git a/language.txt b/language.txt index 6b504be..cf387f6 100644 --- a/language.txt +++ b/language.txt @@ -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"; diff --git a/menudef.txt b/menudef.txt index 41df035..f974ee5 100644 --- a/menudef.txt +++ b/menudef.txt @@ -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" } diff --git a/shaders/glsl/mfx_palette.fp b/shaders/glsl/mfx_palette.fp index 142bd87..0cb7123 100644 --- a/shaders/glsl/mfx_palette.fp +++ b/shaders/glsl/mfx_palette.fp @@ -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); diff --git a/shaders/glsl/mfx_palette_naive.fp b/shaders/glsl/mfx_palette_naive.fp new file mode 100644 index 0000000..16ca129 --- /dev/null +++ b/shaders/glsl/mfx_palette_naive.fp @@ -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