diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 2fcfe245a..23fdda2eb 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -105,6 +105,12 @@ CUSTOM_CVAR(Int, gl_ssao, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) self = 0; } +CUSTOM_CVAR(Int, gl_ssao_portals, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + if (self < 0) + self = 0; +} + CVAR(Float, gl_ssao_strength, 0.7, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, gl_ssao_debug, false, 0) CVAR(Float, gl_ssao_bias, 0.5f, 0) diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 3efd22155..b6120f940 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -477,6 +477,7 @@ void FGLRenderer::RenderTranslucent() void FGLRenderer::DrawScene(int drawmode) { static int recursion=0; + static int ssao_portals_available = 0; if (camera != nullptr) { @@ -494,8 +495,16 @@ void FGLRenderer::DrawScene(int drawmode) } GLRenderer->mClipPortal = NULL; // this must be reset before any portal recursion takes place. - // If SSAO is active, switch to gbuffer shaders and use the gbuffer framebuffer - bool applySSAO = gl_ssao != 0 && FGLRenderBuffers::IsEnabled() && drawmode == DM_MAINVIEW; + // Decide if we need to do ssao for this scene + bool applySSAO = gl_ssao != 0 && FGLRenderBuffers::IsEnabled(); + switch (drawmode) + { + case DM_MAINVIEW: ssao_portals_available = gl_ssao_portals; break; + case DM_OFFSCREEN: ssao_portals_available = 0; applySSAO = false; break; + case DM_PORTAL: applySSAO = applySSAO && (ssao_portals_available > 0); ssao_portals_available--; break; + } + + // If SSAO is active, switch to gbuffer shaders and use the framebuffer with gbuffers if (applySSAO) { GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; diff --git a/src/gl/system/gl_cvars.h b/src/gl/system/gl_cvars.h index 845f0dd22..836787117 100644 --- a/src/gl/system/gl_cvars.h +++ b/src/gl/system/gl_cvars.h @@ -51,6 +51,7 @@ EXTERN_CVAR(Float, gl_lens_k) EXTERN_CVAR(Float, gl_lens_kcube) EXTERN_CVAR(Float, gl_lens_chromatic) EXTERN_CVAR(Int, gl_ssao) +EXTERN_CVAR(Int, gl_ssao_portals) EXTERN_CVAR(Float, gl_ssao_strength) EXTERN_CVAR(Bool, gl_ssao_debug) EXTERN_CVAR(Float, gl_ssao_bias) diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index fae6d871b..cb3af51aa 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -2637,6 +2637,7 @@ GLPREFMNU_TONEMAP = "Tonemap Mode"; GLPREFMNU_BLOOM = "Bloom effect"; GLPREFMNU_LENS = "Lens distortion effect"; GLPREFMNU_SSAO = "Ambient occlusion quality"; +GLPREFMNU_SSAO_PORTALS = "Portals with AO"; // Option Values OPTVAL_SMART = "Smart"; diff --git a/wadsrc/static/menudef.zz b/wadsrc/static/menudef.zz index 8b742ceff..4784baa93 100644 --- a/wadsrc/static/menudef.zz +++ b/wadsrc/static/menudef.zz @@ -235,4 +235,5 @@ OptionMenu "GLPrefOptions" Option "$GLPREFMNU_BLOOM", gl_bloom, "OnOff" Option "$GLPREFMNU_LENS", gl_lens, "OnOff" Option "$GLPREFMNU_SSAO", gl_ssao, "SSAOModes" + Slider "$GLPREFMNU_SSAO_PORTALS", gl_ssao_portals, 0.0, 4.0, 1.0, 0 }