From ae729a1ac74ff2e1891bfd770f13e746f2de1eca Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Wed, 29 Apr 2020 11:46:52 +0200 Subject: [PATCH] add ability to set the type of near far method to be used in shadow calculation; default to bounding volumes; cleaned up code while there and re-ordered items --- apps/launcher/graphicspage.cpp | 11 +- apps/launcher/graphicspage.hpp | 4 +- components/sceneutil/shadow.cpp | 8 +- .../reference/modding/settings/shadows.rst | 14 +- files/settings-default.cfg | 4 +- files/ui/graphicspage.ui | 162 ++++++++++-------- 6 files changed, 120 insertions(+), 83 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 6bc22bad69..421691a55e 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -1,6 +1,5 @@ #include "graphicspage.hpp" -#include #include #include #include @@ -145,6 +144,10 @@ bool Launcher::GraphicsPage::loadSettings() if (mEngineSettings.getBool("enable indoor shadows", "Shadows")) indoorShadowsCheckBox->setCheckState(Qt::Checked); + shadowNearFarComputationComboBox->setCurrentIndex( + shadowNearFarComputationComboBox->findText( + QString(tr(mEngineSettings.getString("near far computation", "Shadows").c_str())))); + int shadowDistLimit = mEngineSettings.getInt("maximum shadow map distance", "Shadows"); if (shadowDistLimit > 0) { @@ -231,7 +234,7 @@ void Launcher::GraphicsPage::saveSettings() bool cPlayerShadows = playerShadowsCheckBox->checkState(); if (cActorShadows || cObjectShadows || cTerrainShadows || cPlayerShadows) { - if (mEngineSettings.getBool("enable shadows", "Shadows") != true) + if (!mEngineSettings.getBool("enable shadows", "Shadows")) mEngineSettings.setBool("enable shadows", "Shadows", true); if (mEngineSettings.getBool("actor shadows", "Shadows") != cActorShadows) mEngineSettings.setBool("actor shadows", "Shadows", cActorShadows); @@ -263,6 +266,10 @@ void Launcher::GraphicsPage::saveSettings() int cShadowRes = shadowResolutionComboBox->currentText().toInt(); if (cShadowRes != mEngineSettings.getInt("shadow map resolution", "Shadows")) mEngineSettings.setInt("shadow map resolution", "Shadows", cShadowRes); + + auto cShadowNearFarMode = shadowNearFarComputationComboBox->currentText().toStdString(); + if (cShadowNearFarMode != mEngineSettings.getString("near far computation", "Shadows")) + mEngineSettings.setString("near far computation", "Shadows", cShadowNearFarMode); } QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen) diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index b230625fc6..4ce5b584f0 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -38,8 +38,8 @@ namespace Launcher Files::ConfigurationManager &mCfgMgr; Settings::Manager &mEngineSettings; - QStringList getAvailableResolutions(int screen); - QRect getMaximumResolution(); + static QStringList getAvailableResolutions(int screen); + static QRect getMaximumResolution(); bool setupSDL(); }; diff --git a/components/sceneutil/shadow.cpp b/components/sceneutil/shadow.cpp index a1cd1d660b..7c2dfd7671 100644 --- a/components/sceneutil/shadow.cpp +++ b/components/sceneutil/shadow.cpp @@ -2,6 +2,7 @@ #include +#include #include namespace SceneUtil @@ -38,11 +39,14 @@ namespace SceneUtil } mShadowSettings->setMinimumShadowMapNearFarRatio(Settings::Manager::getFloat("minimum lispsm near far ratio", "Shadows")); - if (Settings::Manager::getBool("compute tight scene bounds", "Shadows")) + + std::string computeNearFarMode = Settings::Manager::getString("near far computation", "Shadows"); + if (Misc::StringUtils::lowerCase(computeNearFarMode) == "primitives") mShadowSettings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES); - else + else if (Misc::StringUtils::lowerCase(computeNearFarMode) == "bounding volumes") mShadowSettings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES); + int mapres = Settings::Manager::getInt("shadow map resolution", "Shadows"); mShadowSettings->setTextureSize(osg::Vec2s(mapres, mapres)); diff --git a/docs/source/reference/modding/settings/shadows.rst b/docs/source/reference/modding/settings/shadows.rst index d0d92a6e26..861cc03efd 100644 --- a/docs/source/reference/modding/settings/shadows.rst +++ b/docs/source/reference/modding/settings/shadows.rst @@ -80,15 +80,15 @@ enable debug overlay Enable or disable the debug overlay to see the area covered by each shadow map. This setting is only recommended for developers, bug reporting and advanced users performing fine-tuning of shadow settings. -compute tight scene bounds --------------------------- +near far computation +-------------------- -:Type: boolean -:Range: True/False -:Default: True +:Type: string +:Range: bounding volumes|primitives +:Default: bounding volumes -With this setting enabled, attempt to better use the shadow map(s) by making them cover a smaller area. -May have a minor to major performance impact. +Two different ways to make better use of shadow map(s) by making them cover a smaller area. +While primitives give better results at expense of more CPU, bounding volumes gives better performance overall but with lower quality shadows. shadow map resolution --------------------- diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 6703e77326..7fc2db728c 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -805,8 +805,8 @@ enable debug hud = false # Enable the debug overlay to see where each shadow map affects. enable debug overlay = false -# Attempt to better use the shadow map by making them cover a smaller area. May have a minor to major performance impact. -compute tight scene bounds = true +# Used to set type of tight scene bound calculation that makes use the shadow map by making them cover a smaller area. "bounding volumes" (default) is less precise shadows but lower CPU cost or "primitives" for more precise shadows at expense of CPU. +near far computation = bounding volumes # How large to make the shadow map(s). Higher values increase GPU load, but can produce better-looking results. Power-of-two values may turn out to be faster on some GPU/driver combinations. shadow map resolution = 1024 diff --git a/files/ui/graphicspage.ui b/files/ui/graphicspage.ui index 18d220797e..1b11632e53 100644 --- a/files/ui/graphicspage.ui +++ b/files/ui/graphicspage.ui @@ -201,49 +201,92 @@ - - + + + - <html><head/><body><p>The distance from the camera at which shadows completely disappear.</p></body></html> + <html><head/><body><p>Enable shadows exclusively for the player character. May have a very minor performance impact.</p></body></html> - Shadow Distance Limit: + Enable Player Shadows - - - - false + + + + <html><head/><body><p>Enable shadows for NPCs and creatures besides the player character. May have a minor performance impact.</p></body></html> + + + Enable Actor Shadows + + + + - <html><head/><body><p>64 game units is 1 real life yard or about 0.9 m</p></body></html> + <html><head/><body><p>Enable shadows for primarily inanimate objects. May have a significant performance impact.</p></body></html> - - unit(s) + + Enable Object Shadows - - 512 + + + + + + <html><head/><body><p>Enable shadows for the terrain including distant terrain. May have a significant performance and shadow quality impact.</p></body></html> - - 81920 + + Enable Terrain Shadows - - 8192 + + + + + + <html><head/><body><p>Due to limitations with Morrowind's data, only actors can cast shadows indoors, which some might feel is distracting.</p><p>Has no effect if actor/player shadows are not enabled.</p></body></html> + + + Enable Indoor Shadows - - + + - <html><head/><body><p>The fraction of the limit above at which shadows begin to gradually fade away.</p></body></html> + <html><head/><body><p>Type of "near far plane" computation method to be used. Bounding Volumes (default) for better performance, Primitives for better looking shadows or none.</p></body></html> - Fade Start Multiplier: + Shadow Near Far Computation Method: + + + + bounding volumes + + + + + primitives + + + + + + + + <html><head/><body><p>The resolution of each individual shadow map. Increasing it significantly improves shadow quality but may have a minor performance impact.</p></body></html> + + + Shadow Map Resolution: + + + + @@ -267,85 +310,68 @@ - - - - <html><head/><body><p>Enable shadows for NPCs and creatures besides the player character. May have a minor performance impact.</p></body></html> - - - Enable Actor Shadows - - - - - + + - <html><head/><body><p>Enable shadows for the terrain including distant terrain. May have a significant performance and shadow quality impact.</p></body></html> + <html><head/><body><p>The distance from the camera at which shadows completely disappear.</p></body></html> - Enable Terrain Shadows + Shadow Distance Limit: - + false - - 2 + + <html><head/><body><p>64 game units is 1 real life yard or about 0.9 m</p></body></html> + + + unit(s) - 0 + 512 - 1 + 81920 - 0.90 + 8192 - - + + - <html><head/><body><p>Enable shadows exclusively for the player character. May have a very minor performance impact.</p></body></html> + <html><head/><body><p>The fraction of the limit above at which shadows begin to gradually fade away.</p></body></html> - Enable Player Shadows + Fade Start Multiplier: - - - - <html><head/><body><p>The resolution of each individual shadow map. Increasing it significantly improves shadow quality but may have a minor performance impact.</p></body></html> - - - Shadow Map Resolution: + + + + false - - - - - - <html><head/><body><p>Enable shadows for primarily inanimate objects. May have a significant performance impact.</p></body></html> + + 2 - - Enable Object Shadows + + 0 - - - - - - <html><head/><body><p>Due to limitations with Morrowind's data, only actors can cast shadows indoors, which some might feel is distracting.</p><p>Has no effect if actor/player shadows are not enabled.</p></body></html> + + 1 - - Enable Indoor Shadows + + 0.90 +