- add gl_dither for toggling dithered output on and off

# Conflicts:
#	src/gl/renderer/gl_stereo3d.cpp
#	wadsrc/static/menudef.txt

# Conflicts:
#	src/gl/renderer/gl_postprocess.cpp
#	src/gl/stereo3d/gl_interleaved3d.cpp
#	src/hwrenderer/postprocessing/hw_presentshader.h
This commit is contained in:
Magnus Norddahl 2018-08-08 21:58:23 +02:00 committed by drfrag
parent 4cd535b3b6
commit 7021e612b0
7 changed files with 19 additions and 3 deletions

View file

@ -157,6 +157,8 @@ EXTERN_CVAR(Float, vid_contrast)
EXTERN_CVAR(Float, vid_saturation)
EXTERN_CVAR(Int, gl_satformula)
CVAR(Bool, gl_dither, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
void FGLRenderer::RenderScreenQuad()
{
mVBO->BindVBO();
@ -900,6 +902,11 @@ void FGLRenderer::DrawPresentTexture(const GL_IRECT &box, bool applyGamma)
// It probably will eventually in desktop mode too, but the DWM doesn't seem to support that.
invgamma *= 2.2f;
mPresentShader->InvGamma.Set(invgamma);
mPresentShader->ColorScale.Set(static_cast<float>(gl_dither ? 1023.0f : 0.0f));
}
else
{
mPresentShader->ColorScale.Set(static_cast<float>(gl_dither ? 255.0f : 0.0f));
}
mPresentShader->Scale.Set(mScreenViewport.width / (float)mBuffers->GetWidth(), mScreenViewport.height / (float)mBuffers->GetHeight());
RenderScreenQuad();

View file

@ -49,6 +49,7 @@ void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program
Saturation.Init(mShader, "Saturation");
GrayFormula.Init(mShader, "GrayFormula");
Scale.Init(mShader, "UVScale");
ColorScale.Init(mShader, "ColorScale");
}
void FPresentShader::Bind()

View file

@ -15,6 +15,7 @@ public:
FBufferedUniform1f Saturation;
FBufferedUniform1i GrayFormula;
FBufferedUniform2f Scale;
FBufferedUniform1f ColorScale;
protected:
virtual void Init(const char * vtx_shader_name, const char * program_name);

View file

@ -48,6 +48,7 @@ EXTERN_CVAR(Int, gl_satformula)
EXTERN_CVAR(Bool, fullscreen)
EXTERN_CVAR(Int, win_x) // screen pixel position of left of display window
EXTERN_CVAR(Int, win_y) // screen pixel position of top of display window
EXTERN_CVAR(Bool, gl_dither)
namespace s3d {
@ -112,6 +113,7 @@ static void prepareInterleavedPresent(FPresentStereoShaderBase& shader)
shader.Saturation.Set(clamp<float>(vid_saturation, -15.0f, 15.0f));
shader.GrayFormula.Set(static_cast<int>(gl_satformula));
}
shader.ColorScale.Set(static_cast<float>(gl_dither ? 255.0f : 0.0f));
shader.Scale.Set(
GLRenderer->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(),
GLRenderer->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight());

View file

@ -2769,6 +2769,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";

View file

@ -2548,6 +2548,7 @@ OptionMenu "PostProcessMenu" 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"
Option "$GLPREFMNU_TONEMAP", gl_tonemap, "TonemapModes"
StaticText " "
Slider "$GLPREFMNU_PALTONEMAPPOWER", gl_paltonemap_powtable, 0.2, 3.0, 0.1, 1

View file

@ -9,6 +9,7 @@ uniform float Brightness;
uniform float Saturation;
uniform int GrayFormula;
uniform sampler2D DitherTexture;
uniform float ColorScale;
vec4 ApplyGamma(vec4 c)
{
@ -23,14 +24,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)));
}