From 019ec344fe00649eab15fcfe70a97de9dd99e446 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 11 Jan 2015 00:44:06 +0100 Subject: [PATCH] Allow to reduce shadow resolution --- data/shaders/sunlightshadow.frag | 3 ++- src/config/user_config.hpp | 6 +++--- src/graphics/central_settings.cpp | 2 +- src/graphics/render.cpp | 2 +- src/graphics/render_lighting.cpp | 6 +++--- src/graphics/rtts.cpp | 6 +++--- src/graphics/shaders.cpp | 4 ++-- src/graphics/shaders.hpp | 4 ++-- src/graphics/stkscenemanager.cpp | 2 +- src/states_screens/dialogs/custom_video_settings.cpp | 8 ++++---- src/states_screens/options_screen_video.cpp | 6 +++--- 11 files changed, 25 insertions(+), 24 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index ca199d4cf..de43cc66e 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -6,6 +6,7 @@ uniform float split0; uniform float split1; uniform float split2; uniform float splitmax; +uniform float shadow_res; in vec2 uv; out vec4 Diff; @@ -29,7 +30,7 @@ float getShadowFactor(vec3 pos, int index) for (float i = -1.; i <= 1.; i += 1.) { for (float j = -1.; j <= 1.; j += 1.) - result += texture(shadowtex, vec4(shadowtexcoord + vec2(i,j) / 1024., float(index), d)); + result += texture(shadowtex, vec4(shadowtexcoord + vec2(i,j) / shadow_res, float(index), d)); } return result / 9.; diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 70659f906..6352ec70c 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -640,10 +640,10 @@ namespace UserConfigParams PARAM_DEFAULT(BoolUserConfigParam(false, "ssao", &m_graphics_quality, "Enable Screen Space Ambient Occlusion") ); - PARAM_PREFIX IntUserConfigParam m_shadows + PARAM_PREFIX IntUserConfigParam m_shadows_resolution PARAM_DEFAULT( IntUserConfigParam(0, - "shadows", &m_graphics_quality, - "Whether shadows are enabled (0 = disabled, 1 = low, 2 = high") ); + "shadows_resoltion", &m_graphics_quality, + "Shadow resolution (0 = disabled") ); // ---- Misc PARAM_PREFIX BoolUserConfigParam m_cache_overworld diff --git a/src/graphics/central_settings.cpp b/src/graphics/central_settings.cpp index 7eb602e95..16a969b84 100644 --- a/src/graphics/central_settings.cpp +++ b/src/graphics/central_settings.cpp @@ -272,7 +272,7 @@ bool CentralVideoSettings::supportsComputeShadersFiltering() const bool CentralVideoSettings::isShadowEnabled() const { - return supportsShadows() && UserConfigParams::m_shadows; + return supportsShadows() && (UserConfigParams::m_shadows_resolution > 0); } bool CentralVideoSettings::isGlobalIlluminationEnabled() const diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 02bb831c6..577b3e79f 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -349,7 +349,7 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po // To avoid wrong culling, use the largest view possible m_scene_manager->setActiveCamera(m_suncam); if (UserConfigParams::m_dynamic_lights && - UserConfigParams::m_shadows && CVS->isShadowEnabled() && hasShadow) + CVS->isShadowEnabled() && hasShadow) { PROFILER_PUSH_CPU_MARKER("- Shadow", 0x30, 0x6F, 0x90); renderShadows(); diff --git a/src/graphics/render_lighting.cpp b/src/graphics/render_lighting.cpp index fcc43d067..8a2b7169e 100644 --- a/src/graphics/render_lighting.cpp +++ b/src/graphics/render_lighting.cpp @@ -132,7 +132,7 @@ extern float shadowSplit[5]; void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow) { //RH - if (UserConfigParams::m_gi && UserConfigParams::m_shadows && hasShadow) + if (CVS->isGlobalIlluminationEnabled() && hasShadow) { ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_RH)); glDisable(GL_BLEND); @@ -195,12 +195,12 @@ void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow) if (CVS->isESMEnabled()) { FullScreenShader::ShadowedSunLightShaderESM::getInstance()->SetTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), m_rtts->getShadowFBO().getRTT()[0]); - DrawFullScreenEffect(shadowSplit[1], shadowSplit[2], shadowSplit[3], shadowSplit[4], irr_driver->getSunDirection(), irr_driver->getSunColor()); + DrawFullScreenEffect(shadowSplit[1], shadowSplit[2], shadowSplit[3], shadowSplit[4]); } else { FullScreenShader::ShadowedSunLightShaderPCF::getInstance()->SetTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), m_rtts->getShadowFBO().getDepthTexture()); - DrawFullScreenEffect(shadowSplit[1], shadowSplit[2], shadowSplit[3], shadowSplit[4], irr_driver->getSunDirection(), irr_driver->getSunColor()); + DrawFullScreenEffect(shadowSplit[1], shadowSplit[2], shadowSplit[3], shadowSplit[4], UserConfigParams::m_shadows_resolution); } } else diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 647fafe9c..ad735d2a8 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -245,12 +245,12 @@ RTT::RTT(size_t width, size_t height) if (CVS->isShadowEnabled()) { - shadowColorTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_R32F, GL_RED, GL_FLOAT, 10); - shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 1); + shadowColorTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4, GL_R32F, GL_RED, GL_FLOAT, 10); + shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 1); somevector.clear(); somevector.push_back(shadowColorTex); - m_shadow_FBO = new FrameBuffer(somevector, shadowDepthTex, 1024, 1024, true); + m_shadow_FBO = new FrameBuffer(somevector, shadowDepthTex, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, true); } if (CVS->isGlobalIlluminationEnabled()) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index c278c5f98..18c931c2f 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1702,7 +1702,7 @@ namespace FullScreenShader // Use 8 to circumvent a catalyst bug when binding sampler AssignSamplerNames(Program, 0, "ntex", 1, "dtex", 8, "shadowtex"); - AssignUniforms("split0", "split1", "split2", "splitmax", "direction", "col"); + AssignUniforms("split0", "split1", "split2", "splitmax", "shadow_res"); } ShadowedSunLightShaderESM::ShadowedSunLightShaderESM() @@ -1718,7 +1718,7 @@ namespace FullScreenShader // Use 8 to circumvent a catalyst bug when binding sampler AssignSamplerNames(Program, 0, "ntex", 1, "dtex", 8, "shadowtex"); - AssignUniforms("split0", "split1", "split2", "splitmax", "direction", "col"); + AssignUniforms("split0", "split1", "split2", "splitmax"); } RadianceHintsConstructionShader::RadianceHintsConstructionShader() diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 25e3fcb94..a040e4e76 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -426,13 +426,13 @@ public: IBLShader(); }; -class ShadowedSunLightShaderPCF : public ShaderHelperSingleton, public TextureRead +class ShadowedSunLightShaderPCF : public ShaderHelperSingleton, public TextureRead { public: ShadowedSunLightShaderPCF(); }; -class ShadowedSunLightShaderESM : public ShaderHelperSingleton, public TextureRead +class ShadowedSunLightShaderESM : public ShaderHelperSingleton, public TextureRead { public: ShadowedSunLightShaderESM(); diff --git a/src/graphics/stkscenemanager.cpp b/src/graphics/stkscenemanager.cpp index 69853608d..a73d2f9b0 100644 --- a/src/graphics/stkscenemanager.cpp +++ b/src/graphics/stkscenemanager.cpp @@ -362,7 +362,7 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector *Immed } } } - if (!UserConfigParams::m_shadows) + if (!CVS->isShadowEnabled()) return; for (unsigned cascade = 0; cascade < 4; ++cascade) { diff --git a/src/states_screens/dialogs/custom_video_settings.cpp b/src/states_screens/dialogs/custom_video_settings.cpp index 69489208f..13d76eceb 100644 --- a/src/states_screens/dialogs/custom_video_settings.cpp +++ b/src/states_screens/dialogs/custom_video_settings.cpp @@ -86,7 +86,7 @@ void CustomVideoSettingsDialog::beforeAddingWidgets() shadows->addLabel(_("low")); // 1 shadows->addLabel(_("high")); // 2 if (CVS->supportsShadows()) - shadows->setValue(UserConfigParams::m_shadows); + shadows->setValue(UserConfigParams::m_shadows_resolution / 512); else shadows->setValue(0); getWidget("dynamiclight")->setState(UserConfigParams::m_dynamic_lights); @@ -132,12 +132,12 @@ GUIEngine::EventPropagation CustomVideoSettingsDialog::processEvent(const std::s if (advanced_pipeline && CVS->supportsShadows()) { - UserConfigParams::m_shadows = - getWidget("shadows")->getValue(); + UserConfigParams::m_shadows_resolution = + getWidget("shadows")->getValue() * 512; } else { - UserConfigParams::m_shadows = 0; + UserConfigParams::m_shadows_resolution = 0; } UserConfigParams::m_mlaa = diff --git a/src/states_screens/options_screen_video.cpp b/src/states_screens/options_screen_video.cpp index 561b30144..d3415d180 100644 --- a/src/states_screens/options_screen_video.cpp +++ b/src/states_screens/options_screen_video.cpp @@ -371,7 +371,7 @@ void OptionsScreenVideo::updateGfxSlider() GFX_PRESETS[l].mlaa == UserConfigParams::m_mlaa && GFX_PRESETS[l].motionblur == UserConfigParams::m_motionblur && //GFX_PRESETS[l].shaders == UserConfigParams::m_pixel_shaders - GFX_PRESETS[l].shadows == UserConfigParams::m_shadows && + GFX_PRESETS[l].shadows == UserConfigParams::m_shadows_resolution && GFX_PRESETS[l].ssao == UserConfigParams::m_ssao && GFX_PRESETS[l].weather == UserConfigParams::m_weather_effects && GFX_PRESETS[l].dof == UserConfigParams::m_dof && @@ -443,7 +443,7 @@ void OptionsScreenVideo::updateTooltip() UserConfigParams::m_ssao ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Shadows: %s", - UserConfigParams::m_shadows == 1 ? "low" : UserConfigParams::m_shadows == 2 ? + UserConfigParams::m_shadows_resolution == 1 ? "low" : UserConfigParams::m_shadows_resolution == 2 ? "high" : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Bloom : %s", @@ -540,7 +540,7 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name, UserConfigParams::m_mlaa = GFX_PRESETS[level].mlaa; UserConfigParams::m_motionblur = GFX_PRESETS[level].motionblur; //UserConfigParams::m_pixel_shaders = GFX_PRESETS[level].shaders; - UserConfigParams::m_shadows = GFX_PRESETS[level].shadows; + UserConfigParams::m_shadows_resolution = GFX_PRESETS[level].shadows; UserConfigParams::m_ssao = GFX_PRESETS[level].ssao; UserConfigParams::m_weather_effects = GFX_PRESETS[level].weather; UserConfigParams::m_dof = GFX_PRESETS[level].dof;