From a209fffbe2712e70a1c1f4c9b62a364677d7ddb3 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Nov 2026 09:52:09 +0100 Subject: [PATCH] scale and readjust the ripple shader in gl unbelievably annoying since we still gotta support old gl & glsl versions (glsl 1.30 can just fetch texturesizes directly....) basically this ensures the ripple does not become super strong on flats that are super large (iirc anything marsh related lol) its scaled to always match the size of a 64x64 flat, since thats what i tuned the shader to this matches software much more closely --- src/hardware/hw_defs.h | 1 + src/hardware/hw_main.cpp | 4 ++++ src/hardware/hw_shaders.h | 22 +++++++++++++++------- src/hardware/r_opengl/r_opengl.c | 12 ++++++++++++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 2030420c6..915b9584b 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -338,6 +338,7 @@ enum hwdshaderinfo HWD_SHADERINFO_LIGHT_Z, HWD_SHADERINFO_LIGHT_CONTRAST, HWD_SHADERINFO_LIGHT_BACKLIGHT, + HWD_SHADERINFO_FLATSIZE, }; typedef enum hwdshaderinfo hwdshaderinfo_t; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index afac84c75..9298b531e 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -727,6 +727,8 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool PolyFlags |= PF_ColorMapped; } + GL_SetShaderInfo(HWD_SHADERINFO_FLATSIZE, (INT32)fflatsize); + HWR_ProcessPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, shader, false); if (subsector && subsector->hashorizon && cv_glhorizonlines.value) @@ -994,6 +996,8 @@ static void HWR_RenderFOFHorizonPlane(subsector_t *subsector, extrasubsector_t * PolyFlags |= PF_ColorMapped; } + GL_SetShaderInfo(HWD_SHADERINFO_FLATSIZE, (INT32)fflatsize); + // Horizon lines FOutVector horizonpts[6]; float dist, vx, vy; diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index e9ad69105..507505a2e 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -230,20 +230,26 @@ // Still needs to distort things underneath/around the water... // +// readjusted to match software much more closely + +#define GLSL_WATER_CONST \ + "const float freq = 0.07;\n" \ + "const float amp = 0.07;\n" \ + "const float speed = 3.8;\n" \ + "const float pi = 3.14159;\n" \ + "const float falltresh = 0.007;\n" + #define GLSL_WATER_TEXEL \ "float water_z = (gl_FragCoord.z / gl_FragCoord.w) / 2.0;\n" \ "float a = -pi * (water_z * freq) + (leveltime * speed);\n" \ - "float sdistort = sin(a) * amp;\n" \ - "float cdistort = cos(a) * amp;\n" \ - "vec4 texel = texture2D(tex, vec2(gl_TexCoord[0].s - sdistort, gl_TexCoord[0].t - cdistort));\n" + "float falloff = 1.0 / (1.0 + water_z * falltresh);\n" \ + "float distort = sin(a) * amp * falloff * (64.0 / flat_size);\n" \ + "vec4 texel = texture2D(tex, vec2(gl_TexCoord[0].s - distort, gl_TexCoord[0].t));\n" #define GLSL_WATER_FRAGMENT_SHADER \ "#version 120\n" \ GLSL_FLOOR_FUDGES \ - "const float freq = 0.025;\n" \ - "const float amp = 0.025;\n" \ - "const float speed = 2.0;\n" \ - "const float pi = 3.14159;\n" \ + GLSL_WATER_CONST \ "#ifdef SRB2_PALETTE_RENDERING\n" \ "uniform sampler2D tex;\n" \ "uniform sampler3D palette_lookup_tex;\n" \ @@ -251,6 +257,7 @@ "uniform vec4 poly_color;\n" \ "uniform float lighting;\n" \ "uniform float leveltime;\n" \ + "uniform float flat_size;\n" \ GLSL_DOOM_COLORMAP \ "void main(void) {\n" \ GLSL_WATER_TEXEL \ @@ -265,6 +272,7 @@ "uniform float fade_start;\n" \ "uniform float fade_end;\n" \ "uniform float leveltime;\n" \ + "uniform float flat_size;\n" \ GLSL_DOOM_COLORMAP \ GLSL_DOOM_LIGHT_EQUATION \ "void main(void) {\n" \ diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 74b99ccd9..c464ffcdc 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -759,6 +759,8 @@ typedef enum // misc. gluniform_leveltime, + gluniform_flatsize, + gluniform_scr_resolution, // postprocess stuff @@ -800,6 +802,8 @@ static float shader_light_z = 0.0f; static INT32 shader_light_contrast = 0; static INT32 shader_light_backlight = 0; +static INT32 shader_flatsize = 64; + static float shader_vhs_rewind = 1.0f; static float shader_vhs_time = 0.0f; @@ -1099,6 +1103,9 @@ void GL_SetShaderInfo(hwdshaderinfo_t info, INT32 value) case HWD_SHADERINFO_LIGHT_BACKLIGHT: shader_light_backlight = value; break; + case HWD_SHADERINFO_FLATSIZE: + shader_flatsize = value; + break; default: break; } @@ -2340,6 +2347,9 @@ static void GL_Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRG UNIFORM_2(shader->uniforms[gluniform_scr_resolution], (GLfloat)screen_width, (GLfloat)screen_height, pglUniform2f); + // super annoying, if only we could ditch glsl 1.20 and older..... + UNIFORM_1(shader->uniforms[gluniform_flatsize], (GLfloat)shader_flatsize, pglUniform1f); + // grrrrr stupid 2.0 support.. used similar to yfix, xfix UNIFORM_2(shader->uniforms[gluniform_scr_tex_size], (GLfloat)screen_texsizew, (GLfloat)screen_texsizeh, pglUniform2f); @@ -2478,6 +2488,8 @@ static boolean GL_Shader_CompileProgram(gl_shader_t *shader, GLint i) // misc. shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); + shader->uniforms[gluniform_flatsize] = GETUNI("flat_size"); + // postprocessor stuff (water/heat effect) shader->uniforms[gluniform_scr_tex_size] = GETUNI("scr_tex_size");