fragment shader optimization and dither toggle

This commit is contained in:
Valerie Wolfe 2024-04-08 22:28:38 -04:00
parent 52c9809c65
commit 83d1a64574
3 changed files with 29 additions and 18 deletions

View file

@ -1,14 +1,14 @@
#version 120 #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 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 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 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 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] #define pixelSize 2 // the size of pixels [1 2 4 8 16]
uniform sampler2D gcolor; uniform sampler2D gcolor;
@ -114,6 +114,7 @@ float dither(float color, float dithersteps) {
} }
void main() { void main() {
// adjust texture coordinate based on pixel size if needed
vec2 newcoord = texcoord; vec2 newcoord = texcoord;
#if pixelSize > 1 #if pixelSize > 1
vec2 view = vec2(viewWidth, viewHeight) / float(pixelSize); vec2 view = vec2(viewWidth, viewHeight) / float(pixelSize);
@ -122,19 +123,25 @@ void main() {
#endif #endif
vec3 color = texture2D(gcolor, newcoord).rgb; vec3 color = texture2D(gcolor, newcoord).rgb;
float mask; #if colorMode == 0
//vec3 ogRGB = texture2D(gcolor, texcoord).rgb; color = rgb2hsv(color).xyz;
vec3 ogRGB = color; #endif
vec3 ogHSV = rgb2hsv(ogRGB).xyz;
float val = ogHSV.z; vec3 final;
vec3 ditherhsv = hsv2rgb(vec3(dither(ogHSV.x, hueSteps), dither(ogHSV.y, satSteps), dither(ogHSV.z, valSteps))).rgb; #ifdef dithering
vec3 nonditherhsv = hsv2rgb(vec3(lightnessStep(ogHSV.x, hueSteps), lightnessStep(ogHSV.y, satSteps), lightnessStep(ogHSV.z, valSteps))).rgb; #if colorMode == 0
vec3 ditherrgb = vec3(dither(ogRGB.r, rgbSteps), dither(ogRGB.g, rgbSteps), dither(ogRGB.b, rgbSteps)).rgb; vec3 filtered = vec3(dither(color.x, hueSteps), dither(color.y, satSteps), dither(color.z, valSteps)).rgb;
vec3 nonditherrgb = vec3(lightnessStep(ogRGB.r, rgbSteps), lightnessStep(ogRGB.g, rgbSteps), lightnessStep(ogRGB.b, rgbSteps)).rgb; final = hsv2rgb(filtered);
#ifdef RGB #else
vec3 final = ditherrgb; final = vec3(dither(color.r, rgbSteps), dither(color.g, rgbSteps), dither(color.b, rgbSteps));
#endif
#else #else
vec3 final = ditherhsv; #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 #endif
gl_FragData[0] = vec4(vec3(final), 1.0); //gcolor gl_FragData[0] = vec4(vec3(final), 1.0); //gcolor
} }

View file

@ -6,8 +6,11 @@ value.pixelSize.4=Medium (4x)
value.pixelSize.8=High (8x) value.pixelSize.8=High (8x)
value.pixelSize.16=Silly (16x) value.pixelSize.16=Silly (16x)
screen.COLOR=Color Depth screen.COLOR=Color
option.RGB=Use RGB option.colorMode=Color Mode
value.colorMode.0=HSV
value.colorMode.1=RGB
option.dithering=Dithering
option.rgbSteps=RGB Depth option.rgbSteps=RGB Depth
option.hueSteps=Hue Depth option.hueSteps=Hue Depth
option.satSteps=Saturation Depth option.satSteps=Saturation Depth
@ -15,6 +18,7 @@ option.valSteps=Value Depth
screen.PSX=PSX screen.PSX=PSX
option.vWarp=Vertex Warping 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=Affine Textures
option.tWarp.comment=Emulates affine texture mapping responsible for warping textures on the PSX option.tWarp.comment=Emulates affine texture mapping responsible for warping textures on the PSX

View file

@ -2,6 +2,6 @@ sliders=pixelSize hueSteps satSteps valSteps rgbSteps
screen=pixelSize <empty> [COLOR] [PSX] screen=pixelSize <empty> [COLOR] [PSX]
screen.COLOR=RGB rgbSteps hueSteps satSteps valSteps screen.COLOR=colorMode dithering rgbSteps <empty> hueSteps satSteps valSteps
screen.PSX=vWarp screen.PSX=vWarp