From 83d1a645748d63033aaeac10d7c27cb3aeafa5ab Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 8 Apr 2024 22:28:38 -0400 Subject: [PATCH] fragment shader optimization and dither toggle --- shaders/composite.fsh | 37 ++++++++++++++++++++++--------------- shaders/lang/en_US.lang | 8 ++++++-- shaders/shaders.properties | 2 +- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/shaders/composite.fsh b/shaders/composite.fsh index baf35be..16627ee 100644 --- a/shaders/composite.fsh +++ b/shaders/composite.fsh @@ -1,14 +1,14 @@ #version 120 +#define dithering // whether or not to apply dithering +#define colorMode 0 // hsv/rgb [0 1] #define hueSteps 8 // the number of hues to use [2 4 8 16 32 64] #define satSteps 4 // the number of saturations to use [2 4 8 16 32 64] #define valSteps 4 // the number of lightnesses to use [2 4 8 16 32 64] -//#define RGB // whether to use rgb or hsv [0 1] #define rgbSteps 4 // the number of rgb values to use [2 4 8 16 32 64] -//#define BLACKEN // Whether or not to blackent the background #define pixelSize 2 // the size of pixels [1 2 4 8 16] uniform sampler2D gcolor; @@ -114,6 +114,7 @@ float dither(float color, float dithersteps) { } void main() { + // adjust texture coordinate based on pixel size if needed vec2 newcoord = texcoord; #if pixelSize > 1 vec2 view = vec2(viewWidth, viewHeight) / float(pixelSize); @@ -122,19 +123,25 @@ void main() { #endif vec3 color = texture2D(gcolor, newcoord).rgb; - float mask; - //vec3 ogRGB = texture2D(gcolor, texcoord).rgb; - vec3 ogRGB = color; - vec3 ogHSV = rgb2hsv(ogRGB).xyz; - float val = ogHSV.z; - vec3 ditherhsv = hsv2rgb(vec3(dither(ogHSV.x, hueSteps), dither(ogHSV.y, satSteps), dither(ogHSV.z, valSteps))).rgb; - vec3 nonditherhsv = hsv2rgb(vec3(lightnessStep(ogHSV.x, hueSteps), lightnessStep(ogHSV.y, satSteps), lightnessStep(ogHSV.z, valSteps))).rgb; - vec3 ditherrgb = vec3(dither(ogRGB.r, rgbSteps), dither(ogRGB.g, rgbSteps), dither(ogRGB.b, rgbSteps)).rgb; - vec3 nonditherrgb = vec3(lightnessStep(ogRGB.r, rgbSteps), lightnessStep(ogRGB.g, rgbSteps), lightnessStep(ogRGB.b, rgbSteps)).rgb; - #ifdef RGB - vec3 final = ditherrgb; - #else - vec3 final = ditherhsv; + #if colorMode == 0 + color = rgb2hsv(color).xyz; + #endif + + vec3 final; + #ifdef dithering + #if colorMode == 0 + vec3 filtered = vec3(dither(color.x, hueSteps), dither(color.y, satSteps), dither(color.z, valSteps)).rgb; + final = hsv2rgb(filtered); + #else + final = vec3(dither(color.r, rgbSteps), dither(color.g, rgbSteps), dither(color.b, rgbSteps)); + #endif + #else + #if colorMode == 0 + vec3 filtered = vec3(lightnessStep(color.x, hueSteps), lightnessStep(color.y, satSteps), lightnessStep(color.z, valSteps)).rgb; + final = hsv2rgb(filtered); + #else + final = vec3(lightnessStep(color.r, rgbSteps), lightnessStep(color.g, rgbSteps), lightnessStep(color.b, rgbSteps)).rgb; + #endif #endif gl_FragData[0] = vec4(vec3(final), 1.0); //gcolor } diff --git a/shaders/lang/en_US.lang b/shaders/lang/en_US.lang index 4b6f05a..ad61535 100644 --- a/shaders/lang/en_US.lang +++ b/shaders/lang/en_US.lang @@ -6,8 +6,11 @@ value.pixelSize.4=Medium (4x) value.pixelSize.8=High (8x) value.pixelSize.16=Silly (16x) -screen.COLOR=Color Depth -option.RGB=Use RGB +screen.COLOR=Color +option.colorMode=Color Mode +value.colorMode.0=HSV +value.colorMode.1=RGB +option.dithering=Dithering option.rgbSteps=RGB Depth option.hueSteps=Hue Depth option.satSteps=Saturation Depth @@ -15,6 +18,7 @@ option.valSteps=Value Depth screen.PSX=PSX option.vWarp=Vertex Warping +option.vWarp.comment=Emulates screen-space vertex snapping responsible for vertex wobble on the PSX option.tWarp=Affine Textures option.tWarp.comment=Emulates affine texture mapping responsible for warping textures on the PSX diff --git a/shaders/shaders.properties b/shaders/shaders.properties index 9488a64..52eb3d6 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -2,6 +2,6 @@ sliders=pixelSize hueSteps satSteps valSteps rgbSteps screen=pixelSize [COLOR] [PSX] -screen.COLOR=RGB rgbSteps hueSteps satSteps valSteps +screen.COLOR=colorMode dithering rgbSteps hueSteps satSteps valSteps screen.PSX=vWarp