From e0a99f104b2b2030923d460a5a13420430e0b639 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 11 Jul 2012 04:28:45 +0200 Subject: [PATCH] settings tab "shadows" --- apps/openmw/mwgui/settingswindow.cpp | 66 ++++++++++++-- apps/openmw/mwgui/settingswindow.hpp | 9 ++ apps/openmw/mwrender/renderingmanager.cpp | 8 +- apps/openmw/mwrender/shadows.cpp | 104 ++++++++++++---------- files/materials/objects.shader | 9 +- files/mygui/openmw_settings_window.layout | 44 +++++++++ files/settings-default.cfg | 2 + 7 files changed, 182 insertions(+), 60 deletions(-) diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 122849634..3ef89d422 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -112,6 +112,13 @@ namespace MWGui getWidget(mReflectActorsButton, "ReflectActorsButton"); getWidget(mReflectTerrainButton, "ReflectTerrainButton"); getWidget(mShadersButton, "ShadersButton"); + getWidget(mShadowsEnabledButton, "ShadowsEnabledButton"); + getWidget(mShadowsLargeDistance, "ShadowsLargeDistance"); + getWidget(mShadowsTextureSize, "ShadowsTextureSize"); + getWidget(mActorShadows, "ActorShadows"); + getWidget(mStaticsShadows, "StaticsShadows"); + getWidget(mMiscShadows, "MiscShadows"); + getWidget(mShadowsDebug, "ShadowsDebug"); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onOkButtonClicked); mShadersButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onShadersToggled); @@ -130,6 +137,14 @@ namespace MWGui mResolutionList->eventListChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onResolutionSelected); mAnisotropySlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); + mShadowsEnabledButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); + mShadowsLargeDistance->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); + mShadowsTextureSize->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onShadowTextureSize); + mActorShadows->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); + mStaticsShadows->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); + mMiscShadows->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); + mShadowsDebug->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); + mMasterVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); mVoiceVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); mEffectsVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); @@ -182,7 +197,6 @@ namespace MWGui std::string tf = Settings::Manager::getString("texture filtering", "General"); mTextureFilteringButton->setCaption(textureFilteringToStr(tf)); mAnisotropyLabel->setCaption("Anisotropy (" + boost::lexical_cast(Settings::Manager::getInt("anisotropy", "General")) + ")"); - mAnisotropyBox->setVisible(tf == "anisotropic"); float val = (Settings::Manager::getFloat("max viewing distance", "Viewing distance")-sViewDistMin)/(sViewDistMax-sViewDistMin); int viewdist = (mViewDistanceSlider->getScrollRange()-1) * val; @@ -199,6 +213,14 @@ namespace MWGui mReflectActorsButton->setCaptionWithReplacing(Settings::Manager::getBool("reflect actors", "Water") ? "#{sOn}" : "#{sOff}"); mReflectTerrainButton->setCaptionWithReplacing(Settings::Manager::getBool("reflect terrain", "Water") ? "#{sOn}" : "#{sOff}"); + mShadowsTextureSize->setCaption (Settings::Manager::getString ("texture size", "Shadows")); + mShadowsLargeDistance->setCaptionWithReplacing(Settings::Manager::getBool("split", "Shadows") ? "#{sOn}" : "#{sOff}"); + mShadowsEnabledButton->setCaptionWithReplacing(Settings::Manager::getBool("enabled", "Shadows") ? "#{sOn}" : "#{sOff}"); + mActorShadows->setCaptionWithReplacing(Settings::Manager::getBool("actor shadows", "Shadows") ? "#{sOn}" : "#{sOff}"); + mStaticsShadows->setCaptionWithReplacing(Settings::Manager::getBool("statics shadows", "Shadows") ? "#{sOn}" : "#{sOff}"); + mMiscShadows->setCaptionWithReplacing(Settings::Manager::getBool("misc shadows", "Shadows") ? "#{sOn}" : "#{sOff}"); + mShadowsDebug->setCaptionWithReplacing(Settings::Manager::getBool("debug", "Shadows") ? "#{sOn}" : "#{sOff}"); + std::string shaders; if (!Settings::Manager::getBool("shaders", "Objects")) shaders = "off"; @@ -256,6 +278,25 @@ namespace MWGui mResolutionList->setIndexSelected(MyGUI::ITEM_NONE); } + void SettingsWindow::onShadowTextureSize(MyGUI::Widget* _sender) + { + std::string size = mShadowsTextureSize->getCaption(); + + if (size == "512") + size = "1024"; + else if (size == "1024") + size = "2048"; + else if (size == "2048") + size = "4096"; + else + size = "512"; + + mShadowsTextureSize->setCaption(size); + + Settings::Manager::setString("texture size", "Shadows", size); + apply(); + } + void SettingsWindow::onButtonToggled(MyGUI::Widget* _sender) { std::string on = mWindowManager.getGameSettingString("sOn", "On"); @@ -299,10 +340,6 @@ namespace MWGui Settings::Manager::setBool("fullscreen", "Video", newState); apply(); } - } - else if (_sender == mShadersButton) - { - } else if (_sender == mVSyncButton) { @@ -324,6 +361,18 @@ namespace MWGui Settings::Manager::setBool("reflect actors", "Water", newState); else if (_sender == mReflectTerrainButton) Settings::Manager::setBool("reflect terrain", "Water", newState); + else if (_sender == mShadowsEnabledButton) + Settings::Manager::setBool("enabled", "Shadows", newState); + else if (_sender == mShadowsLargeDistance) + Settings::Manager::setBool("split", "Shadows", newState); + else if (_sender == mActorShadows) + Settings::Manager::setBool("actor shadows", "Shadows", newState); + else if (_sender == mStaticsShadows) + Settings::Manager::setBool("statics shadows", "Shadows", newState); + else if (_sender == mMiscShadows) + Settings::Manager::setBool("misc shadows", "Shadows", newState); + else if (_sender == mShadowsDebug) + Settings::Manager::setBool("debug", "Shadows", newState); apply(); } @@ -352,6 +401,11 @@ namespace MWGui mReflectActorsButton->setEnabled(false); mReflectTerrainButton->setEnabled(false); Settings::Manager::setBool("shader", "Water", false); + + // shadows not supported + mShadowsEnabledButton->setEnabled(false); + mShadowsEnabledButton->setCaptionWithReplacing("#{sOff}"); + Settings::Manager::setBool("enabled", "Shadows", false); } else { @@ -360,6 +414,7 @@ namespace MWGui mReflectObjectsButton->setEnabled(true); mReflectActorsButton->setEnabled(true); mReflectTerrainButton->setEnabled(true); + mShadowsEnabledButton->setEnabled(true); Settings::Manager::setBool("shaders", "Objects", true); Settings::Manager::setString("shader mode", "General", val); @@ -390,7 +445,6 @@ namespace MWGui next = "none"; mTextureFilteringButton->setCaption(textureFilteringToStr(next)); - mAnisotropyBox->setVisible(next == "anisotropic"); Settings::Manager::setString("texture filtering", "General", next); apply(); diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index 2bcab9d21..840d266f1 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -44,6 +44,14 @@ namespace MWGui MyGUI::Button* mReflectTerrainButton; MyGUI::Button* mShadersButton; + MyGUI::Button* mShadowsEnabledButton; + MyGUI::Button* mShadowsLargeDistance; + MyGUI::Button* mShadowsTextureSize; + MyGUI::Button* mActorShadows; + MyGUI::Button* mStaticsShadows; + MyGUI::Button* mMiscShadows; + MyGUI::Button* mShadowsDebug; + // audio MyGUI::ScrollBar* mMasterVolumeSlider; MyGUI::ScrollBar* mVoiceVolumeSlider; @@ -61,6 +69,7 @@ namespace MWGui void onResolutionCancel(); void onShadersToggled(MyGUI::Widget* _sender); + void onShadowTextureSize(MyGUI::Widget* _sender); void apply(); }; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index b3e3e42a4..d0613648d 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -62,8 +62,6 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const sh::OgrePlatform* platform = new sh::OgrePlatform("General", (resDir / "materials").string()); platform->setCacheFolder ("./"); mFactory = new sh::Factory(platform); - mFactory->setSharedParameter ("pssmSplitPoints", sh::makeProperty(new sh::Vector4(0,0,0,0))); - mFactory->setSharedParameter ("shadowFar_fadeStart", sh::makeProperty(new sh::Vector4(0,0,0,0))); //The fog type must be set before any terrain objects are created as if the //fog type is set to FOG_NONE then the initially created terrain won't have any fog @@ -646,6 +644,12 @@ void RenderingManager::processChangedSettings(const Settings::CategorySettingVec sh::Factory::getInstance ().setCurrentLanguage (lang); mObjects.rebuildStaticGeometry (); } + else if (it->first == "Shadows") + { + mShadows->recreate (); + + mObjects.rebuildStaticGeometry (); + } } if (changeRes) diff --git a/apps/openmw/mwrender/shadows.cpp b/apps/openmw/mwrender/shadows.cpp index b4982e22d..4c5188e37 100644 --- a/apps/openmw/mwrender/shadows.cpp +++ b/apps/openmw/mwrender/shadows.cpp @@ -36,6 +36,9 @@ void Shadows::recreate() bool split = Settings::Manager::getBool("split", "Shadows"); //const bool split = false; + sh::Factory::getInstance ().setGlobalSetting ("shadows", enabled && !split ? "true" : "false"); + sh::Factory::getInstance ().setGlobalSetting ("shadows_pssm", enabled && split ? "true" : "false"); + if (!enabled) { mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); @@ -122,53 +125,62 @@ void Shadows::recreate() // -------------------------------------------------------------------------------------------------------------------- // --------------------------- Debug overlays to display the content of shadow maps ----------------------------------- // -------------------------------------------------------------------------------------------------------------------- + if (Settings::Manager::getBool("debug", "Shadows")) + { + OverlayManager& mgr = OverlayManager::getSingleton(); + Overlay* overlay; + + // destroy if already exists + if (overlay = mgr.getByName("DebugOverlay")) + mgr.destroy(overlay); + + overlay = mgr.create("DebugOverlay"); + for (size_t i = 0; i < (split ? 3 : 1); ++i) { + TexturePtr tex = mRendering->getScene()->getShadowTexture(i); + + // Set up a debug panel to display the shadow + + if (MaterialManager::getSingleton().resourceExists("Ogre/DebugTexture" + StringConverter::toString(i))) + MaterialManager::getSingleton().remove("Ogre/DebugTexture" + StringConverter::toString(i)); + MaterialPtr debugMat = MaterialManager::getSingleton().create( + "Ogre/DebugTexture" + StringConverter::toString(i), + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); + + debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); + TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(tex->getName()); + t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); + + OverlayContainer* debugPanel; + + // destroy container if exists + try + { + if (debugPanel = + static_cast( + mgr.getOverlayElement("Ogre/DebugTexPanel" + StringConverter::toString(i) + ))) + mgr.destroyOverlayElement(debugPanel); + } + catch (Ogre::Exception&) {} + + debugPanel = (OverlayContainer*) + (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugTexPanel" + StringConverter::toString(i))); + debugPanel->_setPosition(0.8, i*0.25); + debugPanel->_setDimensions(0.2, 0.24); + debugPanel->setMaterialName(debugMat->getName()); + debugPanel->show(); + overlay->add2D(debugPanel); + overlay->show(); + } + } + else + { + OverlayManager& mgr = OverlayManager::getSingleton(); + Overlay* overlay; - OverlayManager& mgr = OverlayManager::getSingleton(); - Overlay* overlay; - - // destroy if already exists - if (overlay = mgr.getByName("DebugOverlay")) - mgr.destroy(overlay); - - overlay = mgr.create("DebugOverlay"); - for (size_t i = 0; i < (split ? 3 : 1); ++i) { - TexturePtr tex = mRendering->getScene()->getShadowTexture(i); - - // Set up a debug panel to display the shadow - - if (MaterialManager::getSingleton().resourceExists("Ogre/DebugTexture" + StringConverter::toString(i))) - MaterialManager::getSingleton().remove("Ogre/DebugTexture" + StringConverter::toString(i)); - MaterialPtr debugMat = MaterialManager::getSingleton().create( - "Ogre/DebugTexture" + StringConverter::toString(i), - ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); - - debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); - TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(tex->getName()); - t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); - - OverlayContainer* debugPanel; - - // destroy container if exists - try - { - if (debugPanel = - static_cast( - mgr.getOverlayElement("Ogre/DebugTexPanel" + StringConverter::toString(i) - ))) - mgr.destroyOverlayElement(debugPanel); - } - catch (Ogre::Exception&) {} - - debugPanel = (OverlayContainer*) - (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugTexPanel" + StringConverter::toString(i))); - debugPanel->_setPosition(0.8, i*0.25); - debugPanel->_setDimensions(0.2, 0.24); - debugPanel->setMaterialName(debugMat->getName()); - debugPanel->show(); - overlay->add2D(debugPanel); - overlay->show(); - } - + if (overlay = mgr.getByName("DebugOverlay")) + mgr.destroy(overlay); + } } PSSMShadowCameraSetup* Shadows::getPSSMSetup() diff --git a/files/materials/objects.shader b/files/materials/objects.shader index 517845cb5..c80a592a3 100644 --- a/files/materials/objects.shader +++ b/files/materials/objects.shader @@ -7,11 +7,8 @@ #define MRT @shPropertyNotBool(is_transparent) && @shPropertyBool(mrt_output) && @shGlobalSettingBool(mrt_output) #define LIGHTING @shPropertyBool(lighting) -#define SHADOWS LIGHTING && 0 -#define SHADOWS_PSSM LIGHTING - -#define SHADOWS 0 && LIGHTING -#define SHADOWS_PSSM 0 && LIGHTING +#define SHADOWS_PSSM LIGHTING && @shGlobalSettingBool(shadows_pssm) +#define SHADOWS LIGHTING && @shGlobalSettingBool(shadows) #if FOG || MRT || SHADOWS_PSSM #define NEED_DEPTH @@ -183,7 +180,7 @@ lightDir = normalize(lightDir); -#if @shIterator == 0 +#if @shIterator == 0 && (SHADOWS || SHADOWS_PSSM) diffuse += materialDiffuse.xyz * lightDiffuse@shIterator.xyz * (1.0 / ((lightAttenuation@shIterator.y) + (lightAttenuation@shIterator.z * d) + (lightAttenuation@shIterator.w * d * d))) * max(dot(normal, lightDir), 0) * shadow; #else diffuse += materialDiffuse.xyz * lightDiffuse@shIterator.xyz * (1.0 / ((lightAttenuation@shIterator.y) + (lightAttenuation@shIterator.z * d) + (lightAttenuation@shIterator.w * d * d))) * max(dot(normal, lightDir), 0); diff --git a/files/mygui/openmw_settings_window.layout b/files/mygui/openmw_settings_window.layout index 9d25b3ee5..d8fbca69c 100644 --- a/files/mygui/openmw_settings_window.layout +++ b/files/mygui/openmw_settings_window.layout @@ -190,6 +190,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/files/settings-default.cfg b/files/settings-default.cfg index bd8bb64b3..a723e307c 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -76,6 +76,8 @@ statics shadows = true # Fraction of the total shadow distance after which the shadow starts to fade out fade start = 0.8 +debug = false + [HUD] # FPS counter # 0: not visible