- add gl_dither for toggling dithered output on and off

This commit is contained in:
Magnus Norddahl 2018-08-08 21:58:23 +02:00
parent 863b9fff8a
commit d121fa21bf
6 changed files with 19 additions and 3 deletions

View file

@ -49,6 +49,8 @@
extern bool vid_hdr_active; extern bool vid_hdr_active;
CVAR(Bool, gl_dither, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
void FGLRenderer::RenderScreenQuad() void FGLRenderer::RenderScreenQuad()
{ {
mVBO->BindVBO(); 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. // 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. // It probably will eventually in desktop mode too, but the DWM doesn't seem to support that.
mPresentShader->Uniforms->InvGamma *= 2.2f; 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->Scale = { screen->mScreenViewport.width / (float)mBuffers->GetWidth(), screen->mScreenViewport.height / (float)mBuffers->GetHeight() };
mPresentShader->Uniforms.Set(); mPresentShader->Uniforms.Set();

View file

@ -39,6 +39,7 @@ EXTERN_CVAR(Float, vid_saturation)
EXTERN_CVAR(Float, vid_brightness) EXTERN_CVAR(Float, vid_brightness)
EXTERN_CVAR(Float, vid_contrast) EXTERN_CVAR(Float, vid_contrast)
EXTERN_CVAR(Int, gl_satformula) EXTERN_CVAR(Int, gl_satformula)
EXTERN_CVAR(Bool, gl_dither)
//========================================================================== //==========================================================================
// //
@ -162,6 +163,7 @@ static void prepareInterleavedPresent(FPresentShaderBase& shader)
shader.Uniforms->Saturation = clamp<float>(vid_saturation, -15.0f, 15.0f); shader.Uniforms->Saturation = clamp<float>(vid_saturation, -15.0f, 15.0f);
shader.Uniforms->GrayFormula = static_cast<int>(gl_satformula); shader.Uniforms->GrayFormula = static_cast<int>(gl_satformula);
} }
shader.Uniforms->ColorScale = gl_dither ? 255.0f : 0.0f;
shader.Uniforms->Scale = { shader.Uniforms->Scale = {
screen->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(), screen->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(),
screen->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight() screen->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight()

View file

@ -18,6 +18,8 @@ public:
int GrayFormula; int GrayFormula;
int WindowPositionParity; // top-of-window might not be top-of-screen int WindowPositionParity; // top-of-window might not be top-of-screen
FVector2 Scale; FVector2 Scale;
float ColorScale;
float Padding1, Padding2, Padding3;
static std::vector<UniformFieldDesc> Desc() static std::vector<UniformFieldDesc> Desc()
{ {
@ -30,6 +32,7 @@ public:
{ "GrayFormula", UniformType::Int, offsetof(UniformBlock, GrayFormula) }, { "GrayFormula", UniformType::Int, offsetof(UniformBlock, GrayFormula) },
{ "WindowPositionParity", UniformType::Int, offsetof(UniformBlock, WindowPositionParity) }, { "WindowPositionParity", UniformType::Int, offsetof(UniformBlock, WindowPositionParity) },
{ "UVScale", UniformType::Vec2, offsetof(UniformBlock, Scale) }, { "UVScale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
{ "ColorScale", UniformType::Float, offsetof(UniformBlock, ColorScale) },
}; };
} }
}; };

View file

@ -2815,6 +2815,7 @@ GLPREFMNU_LENS = "Lens distortion effect";
GLPREFMNU_SSAO = "Ambient occlusion quality"; GLPREFMNU_SSAO = "Ambient occlusion quality";
GLPREFMNU_SSAO_PORTALS = "Portals with AO"; GLPREFMNU_SSAO_PORTALS = "Portals with AO";
GLPREFMNU_FXAA = "FXAA Quality"; GLPREFMNU_FXAA = "FXAA Quality";
GLPREFMNU_DITHER = "Dither output";
GLPREFMNU_PALTONEMAPORDER = "Tonemap Palette Order"; GLPREFMNU_PALTONEMAPORDER = "Tonemap Palette Order";
GLPREFMNU_PALTONEMAPPOWER = "Tonemap Palette Exponent"; GLPREFMNU_PALTONEMAPPOWER = "Tonemap Palette Exponent";
GLPREFMNU_SWLMBANDED = "Banded SW Lightmode"; GLPREFMNU_SWLMBANDED = "Banded SW Lightmode";

View file

@ -2286,6 +2286,7 @@ OptionMenu "OpenGLOptions" protected
Option "$GLPREFMNU_SSAO", gl_ssao, "SSAOModes" Option "$GLPREFMNU_SSAO", gl_ssao, "SSAOModes"
Slider "$GLPREFMNU_SSAO_PORTALS", gl_ssao_portals, 0.0, 4.0, 1.0, 0 Slider "$GLPREFMNU_SSAO_PORTALS", gl_ssao_portals, 0.0, 4.0, 1.0, 0
Option "$GLPREFMNU_FXAA", gl_fxaa, "FXAAQuality" Option "$GLPREFMNU_FXAA", gl_fxaa, "FXAAQuality"
Option "$GLPREFMNU_DITHER", gl_dither, "OnOff"
StaticText " " StaticText " "
Slider "$GLPREFMNU_PALTONEMAPPOWER", gl_paltonemap_powtable, 0.2, 3.0, 0.1, 1 Slider "$GLPREFMNU_PALTONEMAPPOWER", gl_paltonemap_powtable, 0.2, 3.0, 0.1, 1
Option "$GLPREFMNU_PALTONEMAPORDER", gl_paltonemap_reverselookup, "LookupOrder" Option "$GLPREFMNU_PALTONEMAPORDER", gl_paltonemap_reverselookup, "LookupOrder"

View file

@ -18,14 +18,16 @@ vec4 ApplyGamma(vec4 c)
return vec4(val, c.a); 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)); vec2 texSize = vec2(textureSize(DitherTexture, 0));
float threshold = texture(DitherTexture, gl_FragCoord.xy / texSize).r; 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() void main()
{ {
FragColor = Dither(ApplyGamma(texture(InputTexture, TexCoord)), 255.0); FragColor = Dither(ApplyGamma(texture(InputTexture, TexCoord)));
} }