add gr_lightdithering to shader

mhhm dithering
This commit is contained in:
Alug committed 2024-07-03 13:06:47 +02:00
1 parent 2316c117b1
commit 7f34a1d83e
5 files changed
+67 -4

No files matched your search

+15
View File
@@ -81,6 +81,8 @@ static void CV_grshaders_OnChange(void);
static void CV_grpaletterendering_OnChange(void);
static void CV_grpalettedepth_OnChange(void);
static void CV_grlightdithering_OnChange(void);
static CV_PossibleValue_t grfakecontrast_cons_t[] = {{0, "Off"}, {1, "Standard"}, {2, "Smooth"}, {0, NULL}};
static CV_PossibleValue_t grfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"},
@@ -157,6 +159,8 @@ consvar_t cv_grpaletterendering = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, C
static CV_PossibleValue_t glpalettedepth_cons_t[] = {{16, "16 bits"}, {24, "24 bits"}, {0, NULL}};
consvar_t cv_grpalettedepth = {"gr_palettedepth", "16 bits", CV_SAVE|CV_CALL, glpalettedepth_cons_t, CV_grpalettedepth_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_lightdither = {"gr_lightdithering", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grlightdithering_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletterendering_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_grmdls = {"gr_mdls", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
@@ -217,6 +221,15 @@ static void CV_grpaletterendering_OnChange(void)
}
}
static void CV_grlightdithering_OnChange(void)
{
ONLY_IF_GL_LOADED
if (gr_shadersavailable)
{
HWR_CompileShaders();
}
}
static void CV_grpalettedepth_OnChange(void)
{
ONLY_IF_GL_LOADED
@@ -5999,6 +6012,8 @@ void HWR_AddCommands(void)
CV_RegisterVar(&cv_grpalettedepth);
CV_RegisterVar(&cv_grflashpal);
CV_RegisterVar(&cv_lightdither);
#ifdef USE_FBO_OGL
CV_RegisterVar(&cv_grframebuffer);
#endif
+1
View File
@@ -179,6 +179,7 @@ extern consvar_t cv_grrenderdistance;
extern consvar_t cv_grpaletterendering;
extern consvar_t cv_grpalettedepth;
extern consvar_t cv_grflashpal;
extern consvar_t cv_lightdither;
extern consvar_t cv_grscreentextures;
extern consvar_t cv_grportals;
extern consvar_t cv_nostencil;
+7
View File
@@ -82,6 +82,7 @@ static shadertarget_t gl_shadertargets[NUMSHADERTARGETS];
#define WHITESPACE_CHARS " \t"
#define PALETTE_RENDERING_DEFINE "#define SRB2_PALETTE_RENDERING"
#define LIGHT_DITHERING_DEFINE "#define SRB2_LIGHT_DITHER"
// Initialize shader variables and the backend's shader system. Load the base shaders.
// Returns false if shaders cannot be used.
@@ -282,6 +283,9 @@ static char *HWR_PreprocessShader(char *original)
if (cv_grpaletterendering.value)
ADD_TO_LEN(PALETTE_RENDERING_DEFINE)
if (cv_lightdither.value)
ADD_TO_LEN(LIGHT_DITHERING_DEFINE)
#undef ADD_TO_LEN
#define VERSION_PART "#version "
@@ -323,6 +327,9 @@ static char *HWR_PreprocessShader(char *original)
if (cv_grpaletterendering.value)
WRITE_DEFINE(PALETTE_RENDERING_DEFINE)
if (cv_lightdither.value)
WRITE_DEFINE(LIGHT_DITHERING_DEFINE)
#undef WRITE_DEFINE
// Write a #line directive, so compiler errors will report line numbers from the
+38 -4
View File
@@ -51,15 +51,49 @@
//
// Include GLSL_FLOOR_FUDGES or GLSL_WALL_FUDGES or define the fudges in shaders that use this macro.
#define GLSL_DOOM_COLORMAP_DITHER \
"float baseValue = max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \
"float halfResolutionx = scr_resolution.x;\n" \
"float halfResolutiony = scr_resolution.y;\n" \
"if (scr_resolution.x > 1280.0) {\n" \
" halfResolutionx = scr_resolution.x * 0.5;\n" \
"}\n" \
"if (scr_resolution.y > 720.0) {\n" \
" halfResolutiony = scr_resolution.y * 0.5;\n" \
"}\n" \
"vec2 normalizedPosition = position * vec2(halfResolutionx / scr_resolution.x, halfResolutiony / scr_resolution.y);\n" \
"int x = int(mod(normalizedPosition.x, 8.0));\n" \
"int y = int(mod(normalizedPosition.y, 8.0));\n" \
"float bayerMatrix[8][8] = float[8][8](\n" \
"float[8](0.0, 32.0, 8.0, 40.0, 2.0, 34.0, 10.0, 42.0),\n" \
"float[8](48.0, 16.0, 56.0, 24.0, 50.0, 18.0, 58.0, 26.0),\n" \
"float[8](12.0, 44.0, 4.0, 36.0, 14.0, 46.0, 6.0, 38.0),\n" \
"float[8](60.0, 28.0, 52.0, 20.0, 62.0, 30.0, 54.0, 22.0),\n" \
"float[8](3.0, 35.0, 11.0, 43.0, 1.0, 33.0, 9.0, 41.0),\n" \
"float[8](51.0, 19.0, 59.0, 27.0, 49.0, 17.0, 57.0, 25.0),\n" \
"float[8](15.0, 47.0, 7.0, 39.0, 13.0, 45.0, 5.0, 37.0),\n" \
"float[8](63.0, 31.0, 55.0, 23.0, 61.0, 29.0, 53.0, 21.0)\n" \
");\n" \
"float threshold = bayerMatrix[y][x] / 64.0;\n" \
"return baseValue + threshold - 0.5 / 64.0;\n" \
#define GLSL_DOOM_COLORMAP_NODITHER \
"return max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \
#define GLSL_DOOM_COLORMAP \
"float R_DoomColormap(float light, float z)\n" \
"uniform vec2 scr_resolution;\n" \
"float R_DoomColormap(float light, float z, vec2 position)\n" \
"{\n" \
"float lightnum = clamp(light / 17.0, 0.0, 15.0);\n" \
"float lightz = clamp(z / 16.0, 0.0, 127.0);\n" \
"float startmap = (15.0 - lightnum) * 4.0;\n" \
"float scale = 160.0 / (lightz + 1.0);\n" \
"float cap = (155.0 - light) * 0.26;\n" \
"return max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \
"#ifdef SRB2_LIGHT_DITHER\n" \
GLSL_DOOM_COLORMAP_DITHER \
"#else\n" \
GLSL_DOOM_COLORMAP_NODITHER \
"#endif\n" \
"}\n"
// lighting cap adjustment:
// first num (155.0), increase to make it start to go dark sooner
@@ -69,7 +103,7 @@
"float R_DoomLightingEquation(float light)\n" \
"{\n" \
"float z = gl_FragCoord.z / gl_FragCoord.w;\n" \
"float colormap = floor(R_DoomColormap(light, z)) + 0.5;\n" \
"float colormap = floor(R_DoomColormap(light, z, gl_FragCoord.xy)) + 0.5;\n" \
"return clamp(colormap, 0.0, 31.0) / 32.0;\n" \
"}\n"
@@ -95,7 +129,7 @@
#define GLSL_PALETTE_RENDERING \
"float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \
"float z = gl_FragCoord.z / gl_FragCoord.w;\n" \
"float light_y = clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0);\n" \
"float light_y = clamp(floor(R_DoomColormap(lighting, z, gl_FragCoord.xy)), 0.0, 31.0);\n" \
"vec2 lighttable_coord = vec2((tex_pal_idx + 0.5) / 256.0, (light_y + 0.5) / 32.0);\n" \
"vec4 final_color = texture2D(lighttable_tex, lighttable_coord);\n" \
"final_color.a = texel.a * poly_color.a;\n" \
+6
View File
@@ -669,6 +669,8 @@ typedef enum
// misc.
gluniform_leveltime,
gluniform_scr_resolution,
gluniform_max,
} gluniform_t;
@@ -1836,6 +1838,8 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF
UNIFORM_1(shader->uniforms[gluniform_leveltime], ((float)shader_leveltime) / TICRATE, pglUniform1f);
UNIFORM_2(shader->uniforms[gluniform_scr_resolution], vid.width, vid.height, pglUniform2f);
#undef UNIFORM_1
#undef UNIFORM_2
#undef UNIFORM_3
@@ -1953,6 +1957,8 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i)
shader->uniforms[gluniform_palette_lookup_tex] = GETUNI("palette_lookup_tex");
shader->uniforms[gluniform_lighttable_tex] = GETUNI("lighttable_tex");
shader->uniforms[gluniform_scr_resolution] = GETUNI("scr_resolution");
// misc.
shader->uniforms[gluniform_leveltime] = GETUNI("leveltime");
#undef GETUNI