From d121fa21bf385697d69726d939409da551a2dbf4 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 8 Aug 2018 21:58:23 +0200 Subject: [PATCH] - add gl_dither for toggling dithered output on and off --- src/gl/renderer/gl_postprocess.cpp | 7 +++++++ src/gl/renderer/gl_stereo3d.cpp | 2 ++ src/hwrenderer/postprocessing/hw_presentshader.h | 3 +++ wadsrc/static/language.enu | 1 + wadsrc/static/menudef.txt | 1 + wadsrc/static/shaders/glsl/present.fp | 8 +++++--- 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 9b66070a5..0ae3a6db3 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -49,6 +49,8 @@ extern bool vid_hdr_active; +CVAR(Bool, gl_dither, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) + void FGLRenderer::RenderScreenQuad() { mVBO->BindVBO(); @@ -234,6 +236,11 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma) // Full screen exclusive mode treats a rgba16f frame buffer as linear. // It probably will eventually in desktop mode too, but the DWM doesn't seem to support that. mPresentShader->Uniforms->InvGamma *= 2.2f; + mPresentShader->Uniforms->ColorScale = gl_dither ? 1023.0f : 0.0f; + } + else + { + mPresentShader->Uniforms->ColorScale = gl_dither ? 255.0f : 0.0f; } mPresentShader->Uniforms->Scale = { screen->mScreenViewport.width / (float)mBuffers->GetWidth(), screen->mScreenViewport.height / (float)mBuffers->GetHeight() }; mPresentShader->Uniforms.Set(); diff --git a/src/gl/renderer/gl_stereo3d.cpp b/src/gl/renderer/gl_stereo3d.cpp index 3155bbdc5..6bf7a80db 100644 --- a/src/gl/renderer/gl_stereo3d.cpp +++ b/src/gl/renderer/gl_stereo3d.cpp @@ -39,6 +39,7 @@ EXTERN_CVAR(Float, vid_saturation) EXTERN_CVAR(Float, vid_brightness) EXTERN_CVAR(Float, vid_contrast) EXTERN_CVAR(Int, gl_satformula) +EXTERN_CVAR(Bool, gl_dither) //========================================================================== // @@ -162,6 +163,7 @@ static void prepareInterleavedPresent(FPresentShaderBase& shader) shader.Uniforms->Saturation = clamp(vid_saturation, -15.0f, 15.0f); shader.Uniforms->GrayFormula = static_cast(gl_satformula); } + shader.Uniforms->ColorScale = gl_dither ? 255.0f : 0.0f; shader.Uniforms->Scale = { screen->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(), screen->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight() diff --git a/src/hwrenderer/postprocessing/hw_presentshader.h b/src/hwrenderer/postprocessing/hw_presentshader.h index 309d05546..feba2c435 100644 --- a/src/hwrenderer/postprocessing/hw_presentshader.h +++ b/src/hwrenderer/postprocessing/hw_presentshader.h @@ -18,6 +18,8 @@ public: int GrayFormula; int WindowPositionParity; // top-of-window might not be top-of-screen FVector2 Scale; + float ColorScale; + float Padding1, Padding2, Padding3; static std::vector Desc() { @@ -30,6 +32,7 @@ public: { "GrayFormula", UniformType::Int, offsetof(UniformBlock, GrayFormula) }, { "WindowPositionParity", UniformType::Int, offsetof(UniformBlock, WindowPositionParity) }, { "UVScale", UniformType::Vec2, offsetof(UniformBlock, Scale) }, + { "ColorScale", UniformType::Float, offsetof(UniformBlock, ColorScale) }, }; } }; diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index ebe3cce68..c3bff9b29 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -2815,6 +2815,7 @@ GLPREFMNU_LENS = "Lens distortion effect"; GLPREFMNU_SSAO = "Ambient occlusion quality"; GLPREFMNU_SSAO_PORTALS = "Portals with AO"; GLPREFMNU_FXAA = "FXAA Quality"; +GLPREFMNU_DITHER = "Dither output"; GLPREFMNU_PALTONEMAPORDER = "Tonemap Palette Order"; GLPREFMNU_PALTONEMAPPOWER = "Tonemap Palette Exponent"; GLPREFMNU_SWLMBANDED = "Banded SW Lightmode"; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 3c6c8600a..b4c23003e 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -2286,6 +2286,7 @@ OptionMenu "OpenGLOptions" protected Option "$GLPREFMNU_SSAO", gl_ssao, "SSAOModes" Slider "$GLPREFMNU_SSAO_PORTALS", gl_ssao_portals, 0.0, 4.0, 1.0, 0 Option "$GLPREFMNU_FXAA", gl_fxaa, "FXAAQuality" + Option "$GLPREFMNU_DITHER", gl_dither, "OnOff" StaticText " " Slider "$GLPREFMNU_PALTONEMAPPOWER", gl_paltonemap_powtable, 0.2, 3.0, 0.1, 1 Option "$GLPREFMNU_PALTONEMAPORDER", gl_paltonemap_reverselookup, "LookupOrder" diff --git a/wadsrc/static/shaders/glsl/present.fp b/wadsrc/static/shaders/glsl/present.fp index 539107f6b..6059a66f0 100644 --- a/wadsrc/static/shaders/glsl/present.fp +++ b/wadsrc/static/shaders/glsl/present.fp @@ -18,14 +18,16 @@ vec4 ApplyGamma(vec4 c) return vec4(val, c.a); } -vec4 Dither(vec4 c, float colorscale) +vec4 Dither(vec4 c) { + if (ColorScale == 0.0) + return c; vec2 texSize = vec2(textureSize(DitherTexture, 0)); float threshold = texture(DitherTexture, gl_FragCoord.xy / texSize).r; - return vec4(floor(c.rgb * colorscale + threshold) / colorscale, c.a); + return vec4(floor(c.rgb * ColorScale + threshold) / ColorScale, c.a); } void main() { - FragColor = Dither(ApplyGamma(texture(InputTexture, TexCoord)), 255.0); + FragColor = Dither(ApplyGamma(texture(InputTexture, TexCoord))); }