From 0d8b7c55ef1d1a4f6688f770461840c104f7dabb Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 26 Jun 2017 06:33:59 -0400 Subject: [PATCH] - added a grayscale formula selector --- src/gl/renderer/gl_postprocess.cpp | 2 ++ src/gl/shaders/gl_presentshader.cpp | 1 + src/gl/shaders/gl_presentshader.h | 1 + src/gl/stereo3d/gl_interleaved3d.cpp | 3 +++ src/gl/system/gl_menu.cpp | 10 +++++++++- wadsrc/static/shaders/glsl/present.fp | 6 +++++- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index efc9e1911..21eaf874d 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -150,6 +150,7 @@ CVAR(Float, gl_menu_blur, -1.0f, CVAR_ARCHIVE) EXTERN_CVAR(Float, vid_brightness) EXTERN_CVAR(Float, vid_contrast) EXTERN_CVAR(Float, vid_saturation) +EXTERN_CVAR(Int, gl_satformula) void FGLRenderer::RenderScreenQuad() @@ -867,6 +868,7 @@ void FGLRenderer::DrawPresentTexture(const GL_IRECT &box, bool applyGamma) mPresentShader->Contrast.Set(clamp(vid_contrast, 0.1f, 3.f)); mPresentShader->Brightness.Set(clamp(vid_brightness, -0.8f, 0.8f)); mPresentShader->Saturation.Set(clamp(vid_saturation, -15.0f, 15.f)); + mPresentShader->GrayFormula.Set(static_cast(gl_satformula)); } mPresentShader->Scale.Set(mScreenViewport.width / (float)mBuffers->GetWidth(), mScreenViewport.height / (float)mBuffers->GetHeight()); RenderScreenQuad(); diff --git a/src/gl/shaders/gl_presentshader.cpp b/src/gl/shaders/gl_presentshader.cpp index 8fdf623d9..06056f539 100644 --- a/src/gl/shaders/gl_presentshader.cpp +++ b/src/gl/shaders/gl_presentshader.cpp @@ -47,6 +47,7 @@ void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program Contrast.Init(mShader, "Contrast"); Brightness.Init(mShader, "Brightness"); Saturation.Init(mShader, "Saturation"); + GrayFormula.Init(mShader, "GrayFormula"); Scale.Init(mShader, "UVScale"); } diff --git a/src/gl/shaders/gl_presentshader.h b/src/gl/shaders/gl_presentshader.h index acb3f50eb..377a6a4f2 100644 --- a/src/gl/shaders/gl_presentshader.h +++ b/src/gl/shaders/gl_presentshader.h @@ -13,6 +13,7 @@ public: FBufferedUniform1f Contrast; FBufferedUniform1f Brightness; FBufferedUniform1f Saturation; + FBufferedUniform1i GrayFormula; FBufferedUniform2f Scale; protected: diff --git a/src/gl/stereo3d/gl_interleaved3d.cpp b/src/gl/stereo3d/gl_interleaved3d.cpp index a499f6e0e..4729fbf77 100644 --- a/src/gl/stereo3d/gl_interleaved3d.cpp +++ b/src/gl/stereo3d/gl_interleaved3d.cpp @@ -44,6 +44,7 @@ EXTERN_CVAR(Float, vid_saturation) EXTERN_CVAR(Float, vid_brightness) EXTERN_CVAR(Float, vid_contrast) +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 @@ -101,6 +102,7 @@ static void prepareInterleavedPresent(FPresentStereoShaderBase& shader) shader.InvGamma.Set(1.0f); shader.Contrast.Set(1.0f); shader.Brightness.Set(0.0f); + shader.Saturation.Set(1.0f); } else { @@ -108,6 +110,7 @@ static void prepareInterleavedPresent(FPresentStereoShaderBase& shader) shader.Contrast.Set(clamp(vid_contrast, 0.1f, 3.f)); shader.Brightness.Set(clamp(vid_brightness, -0.8f, 0.8f)); shader.Saturation.Set(clamp(vid_saturation, -15.0f, 15.0f)); + shader.GrayFormula.Set(static_cast(gl_satformula)); } shader.Scale.Set( GLRenderer->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(), diff --git a/src/gl/system/gl_menu.cpp b/src/gl/system/gl_menu.cpp index 5813613b4..489ad4a9d 100644 --- a/src/gl/system/gl_menu.cpp +++ b/src/gl/system/gl_menu.cpp @@ -77,7 +77,15 @@ CUSTOM_CVAR (Float, vid_saturation, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) { if (screen != NULL) { - screen->SetGamma(Gamma); //SetContrast (self); + screen->SetGamma(Gamma); + } +} + +CUSTOM_CVAR(Int, gl_satformula, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +{ + if (screen != NULL) + { + screen->SetGamma(Gamma); } } diff --git a/wadsrc/static/shaders/glsl/present.fp b/wadsrc/static/shaders/glsl/present.fp index 9a53e0eb5..eff874ed2 100644 --- a/wadsrc/static/shaders/glsl/present.fp +++ b/wadsrc/static/shaders/glsl/present.fp @@ -7,12 +7,16 @@ uniform float InvGamma; uniform float Contrast; uniform float Brightness; uniform float Saturation; +uniform int GrayFormula; vec4 ApplyGamma(vec4 c) { vec3 valgray; if (Saturation != 1.0) // attempt to cool things a bit, this calculation makes the GPU run really hot - valgray = (0.3 * c.r + 0.59 * c.g + 0.11 * c.b) * (1 - Saturation) + c.rgb * Saturation; + if (GrayFormula == 0) + valgray = vec3(c.r + c.g + c.b) * (1 - Saturation) / 3 + c.rgb * Saturation; + else + valgray = vec3(0.3 * c.r + 0.56 * c.g + 0.14 * c.b) * (1 - Saturation) + c.rgb * Saturation; else valgray = c.rgb; vec3 val = valgray * Contrast - (Contrast - 1.0) * 0.5;