use shader for downsampling with fbo
looks alot better and actually makes supersampling worth it will be disabled when shaders also are
This commit is contained in:
1 parent
6f1fcd3e10
commit
8a19bda170
7 files changed
+44
-5
No files matched your search
@@ -182,6 +182,7 @@ enum
|
||||
SHADER_SKY,
|
||||
SHADER_PALETTE_POSTPROCESS,
|
||||
SHADER_UI_COLORMAP_FADE,
|
||||
SHADER_DOWNSAMPLE,
|
||||
|
||||
NUMSHADERTARGETS
|
||||
};
|
||||
|
||||
@@ -56,6 +56,9 @@ static struct {
|
||||
// UI colormap fade shader
|
||||
{GLSL_DEFAULT_VERTEX_SHADER, GLSL_UI_COLORMAP_FADE_FRAGMENT_SHADER},
|
||||
|
||||
// downsampling
|
||||
{GLSL_DEFAULT_VERTEX_SHADER, GLSL_DOWNSAMPLE_FRAGMENT_SHADER},
|
||||
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -441,6 +444,7 @@ customshaderxlat_t shaderxlat[] =
|
||||
{"Sky", SHADER_SKY},
|
||||
{"PalettePostprocess", SHADER_PALETTE_POSTPROCESS},
|
||||
{"UIColormapFade", SHADER_UI_COLORMAP_FADE},
|
||||
{"Downsampling", SHADER_DOWNSAMPLE},
|
||||
{NULL, 0},
|
||||
};
|
||||
|
||||
|
||||
@@ -46,6 +46,25 @@
|
||||
"gl_FragColor = texture2D(tex, gl_TexCoord[0].st) * poly_color;\n" \
|
||||
"}\0"
|
||||
|
||||
|
||||
#define GLSL_DOWNSAMPLE_FRAGMENT_SHADER \
|
||||
"uniform sampler2D tex;\n" \
|
||||
"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" \
|
||||
"vec4 color1 = texture2D(tex, uv + offset1);\n" \
|
||||
"vec4 color2 = texture2D(tex, uv + offset2);\n" \
|
||||
"vec4 color3 = texture2D(tex, uv + offset3);\n" \
|
||||
"vec4 color4 = texture2D(tex, uv + offset4);\n" \
|
||||
"vec4 final_color = (color1 + color2 + color3 + color4) * 0.25;\n" \
|
||||
"gl_FragColor = final_color;\n" \
|
||||
"}\0"
|
||||
|
||||
|
||||
//
|
||||
// Software fragment shader
|
||||
//
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include "../../r_local.h" // For rendertimefrac, used for the leveltime shader uniform
|
||||
#include "../../f_finale.h"
|
||||
#include "r_opengl.h"
|
||||
#include "r_vbo.h"
|
||||
#include "../hw_shaders.h"
|
||||
@@ -124,6 +125,7 @@ GLuint FramebufferObject, FramebufferTexture, RenderbufferObject;
|
||||
GLboolean FrameBufferEnabled = GL_FALSE, RenderToFramebuffer = GL_FALSE;
|
||||
|
||||
boolean supportFBO = false;
|
||||
boolean fbo_shader = false;
|
||||
#endif
|
||||
|
||||
// Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing
|
||||
@@ -1124,6 +1126,8 @@ void GLFramebuffer_Disable(void)
|
||||
if (!supportFBO)
|
||||
return;
|
||||
|
||||
fbo_shader = false;
|
||||
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
pglBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
@@ -3473,17 +3477,20 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int tex, INT32 width, INT32 height)
|
||||
SetBlend(PF_NoDepthTest);
|
||||
|
||||
pglBindTexture(GL_TEXTURE_2D, screenTextures[tex]);
|
||||
|
||||
|
||||
if (HWR_ShouldUsePaletteRendering())
|
||||
pglUseProgram(gl_shaders[SHADER_PALETTE_POSTPROCESS].program); // palette postprocess shader
|
||||
|
||||
if (HWR_UseShader() && fbo_shader && !WipeInAction) // this looks awful with wipes
|
||||
pglUseProgram(gl_shaders[SHADER_DOWNSAMPLE].program);
|
||||
|
||||
pglColor4ubv(white);
|
||||
|
||||
pglTexCoordPointer(2, GL_FLOAT, 0, fix);
|
||||
pglVertexPointer(3, GL_FLOAT, 0, off);
|
||||
|
||||
pglDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
|
||||
if (HWR_ShouldUsePaletteRendering())
|
||||
pglUseProgram(0);
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@ void GLFramebuffer_Disable(void);
|
||||
extern GLuint FramebufferObject, FramebufferTexture, RenderbufferObject;
|
||||
extern GLboolean FrameBufferEnabled, RenderToFramebuffer;
|
||||
extern boolean supportFBO;
|
||||
extern boolean fbo_shader;
|
||||
#endif
|
||||
|
||||
// ==========================================================================
|
||||
|
||||
+9
-2
@@ -68,8 +68,8 @@ PFNglGetIntegerv pglGetIntegerv;
|
||||
PFNglGetString pglGetString;
|
||||
#endif
|
||||
|
||||
#if defined (__unix__)
|
||||
#ifdef USE_FBO_OGL
|
||||
#if defined (__unix__)
|
||||
boolean isnvidiagpu = false;
|
||||
#endif
|
||||
#endif
|
||||
@@ -264,14 +264,20 @@ void OglSdlFinishUpdate(boolean waitvbl)
|
||||
);
|
||||
|
||||
if (RenderToFramebuffer)
|
||||
{
|
||||
GLFramebuffer_Unbind();
|
||||
fbo_shader = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
HWR_DrawScreenFinalTexture(sdlw, sdlh);
|
||||
|
||||
#ifdef USE_FBO_OGL
|
||||
if (RenderToFramebuffer)
|
||||
{
|
||||
GLFramebuffer_Enable();
|
||||
fbo_shader = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
@@ -280,6 +286,7 @@ void OglSdlFinishUpdate(boolean waitvbl)
|
||||
|
||||
// Sryder: We need to draw the final screen texture again into the other buffer in the original position so that
|
||||
// effects that want to take the old screen can do so after this
|
||||
|
||||
HWR_DrawScreenFinalTexture(realwidth, realheight);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,8 +20,8 @@
|
||||
|
||||
boolean OglSdlSurface(INT32 w, INT32 h);
|
||||
|
||||
#if defined (__unix__)
|
||||
#ifdef USE_FBO_OGL
|
||||
#if defined (__unix__)
|
||||
extern boolean isnvidiagpu;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user