make downsampleshader respect the resoltion factor

This commit is contained in:
Alug committed 2024-09-01 00:51:58 +02:00
1 parent 8aeedadbcf
commit bc356ceac9
5 files changed
+43 -10

No files matched your search

+6 -4
View File
@@ -48,6 +48,7 @@
#define GLSL_DOWNSAMPLE_FRAGMENT_SHADER \
"uniform sampler2D tex;\n" \
"uniform vec2 inv_supersamplefactor;\n" \
"#ifdef SRB2_PALETTE_RENDERING\n" \
"uniform sampler3D palette_lookup_tex;\n" \
"uniform sampler1D palette_tex;\n" \
@@ -55,10 +56,10 @@
"void main(void) {\n" \
"vec2 uv = gl_TexCoord[0].st;\n" \
"vec2 texel_size = 1.0 / textureSize(tex, 0);\n" \
"vec2 offset1 = vec2(texel_size.x * 0.5, texel_size.y * 0.5);\n" \
"vec2 offset2 = vec2(-texel_size.x * 0.5, texel_size.y * 0.5);\n" \
"vec2 offset3 = vec2(texel_size.x * 0.5, -texel_size.y * 0.5);\n" \
"vec2 offset4 = vec2(-texel_size.x * 0.5, -texel_size.y * 0.5);\n" \
"vec2 offset1 = vec2(texel_size.x * inv_supersamplefactor.x, texel_size.y * inv_supersamplefactor.y);\n" \
"vec2 offset2 = vec2(-texel_size.x * inv_supersamplefactor.x, texel_size.y * inv_supersamplefactor.y);\n" \
"vec2 offset3 = vec2(texel_size.x * inv_supersamplefactor.x, -texel_size.y * inv_supersamplefactor.y);\n" \
"vec2 offset4 = vec2(-texel_size.x * inv_supersamplefactor.x, -texel_size.y * inv_supersamplefactor.y);\n" \
"vec4 color1 = texture2D(tex, uv + offset1);\n" \
"vec4 color2 = texture2D(tex, uv + offset2);\n" \
"vec4 color3 = texture2D(tex, uv + offset3);\n" \
@@ -127,6 +128,7 @@
GLSL_DOOM_COLORMAP_NODITHER \
"#endif\n" \
"}\n"
// lighting cap adjustment:
// first num (155.0), increase to make it start to go dark sooner
// second num (0.26), increase to make it go dark faster
+16
View File
@@ -31,6 +31,8 @@
#include "../hw_main.h"
#include "../hw_clip.h"
#include "../../i_video.h"
// Eeeeh not sure is this right way, but it works < sry :c < sry again it had to go :c
extern fixed_t fovtan; // also extremely bad, I'm just too lazy!!!
@@ -673,6 +675,9 @@ typedef enum
gluniform_leveltime,
gluniform_scr_resolution,
// supersampling crap
gluniform_inv_supersamplefactor,
gluniform_max,
} gluniform_t;
@@ -1984,6 +1989,9 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i)
shader->uniforms[gluniform_scr_resolution] = GETUNI("scr_resolution");
// supersampling crap
shader->uniforms[gluniform_inv_supersamplefactor] = GETUNI("inv_supersamplefactor");
// misc.
shader->uniforms[gluniform_leveltime] = GETUNI("leveltime");
#undef GETUNI
@@ -1993,6 +2001,10 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i)
if (uniform != -1) \
function (uniform, a);
#define UNIFORM_2(uniform, a, b, function) \
if (uniform != -1) \
function (uniform, a, b);
pglUseProgram(shader->program);
// texture unit numbers for the samplers used for palette rendering
@@ -2000,9 +2012,13 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i)
UNIFORM_1(shader->uniforms[gluniform_palette_lookup_tex], 1, pglUniform1i);
UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i);
// supersampling crap
UNIFORM_2(shader->uniforms[gluniform_inv_supersamplefactor], InvSupersampleFactorX, InvSupersampleFactorY, pglUniform2f);
// restore gl shader state
pglUseProgram(gl_shaderstate.program);
#undef UNIFORM_1
#undef UNIFORM_2
return true;
}
+3
View File
@@ -144,6 +144,9 @@ boolean I_UseNativeKeyboard(void);
extern boolean xwaylandcrap;
#endif
extern float InvSupersampleFactorX;
extern float InvSupersampleFactorY;
void RefreshOGLSDLSurface(void);
void I_DownSample(void);
extern boolean downsample;
+13 -6
View File
@@ -222,6 +222,10 @@ static void I_FixXwaylandNvidia(void);
boolean xwaylandcrap = false;
#endif
boolean downsample = false;
float InvSupersampleFactorX = 0.0;
float InvSupersampleFactorY = 0.0;
void RefreshOGLSDLSurface(void)
{
if (rendermode == render_opengl)
@@ -780,6 +784,9 @@ void I_DownSample(void)
if ((vid.width > curmode.w) || (vid.height > curmode.h)) //check if current resolution is higher than current display resolution
{
downsample = true;
InvSupersampleFactorX = (float)(curmode.w) / vid.width;
InvSupersampleFactorY = (float)(curmode.h) / vid.height;
RefreshOGLSDLSurface();
}
else
@@ -809,7 +816,7 @@ static void I_FixXwaylandNvidia(void) //dumbass crap, fix ur shit nvidia
static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
{
#define FOCUSUNION (mousefocus | (kbfocus << 1))
#define FOCUSUNION (mousefocus | (kbfocus << 1) | (windowmoved << 2))
static SDL_bool firsttimeonmouse = SDL_TRUE;
static SDL_bool mousefocus = SDL_TRUE;
static SDL_bool kbfocus = SDL_TRUE;
@@ -844,6 +851,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
#endif
}
if (FOCUSUNION == oldfocus) // No state change
{
return;
}
#ifdef USE_FBO_OGL
if (windowmoved && rendermode == render_opengl)
{
@@ -851,11 +863,6 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
}
#endif
if (FOCUSUNION == oldfocus) // No state change
{
return;
}
if (mousefocus && kbfocus)
{
// Tell game we got focus back, resume music if necessary
+5
View File
@@ -220,6 +220,11 @@ boolean OglSdlSurface(INT32 w, INT32 h)
GLFramebuffer_Enable();
else
GLFramebuffer_Disable();
if (RenderToFramebuffer && HWR_UseShader())
{
HWR_CompileShaders();
}
#endif
HWR_Startup();