1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

Separate indoor and outdoor shadow casting masks.

This commit is contained in:
AnyOldName3 2018-02-27 00:13:51 +00:00
parent 35eb71052e
commit f9cf1ac94b
3 changed files with 31 additions and 9 deletions

View File

@ -202,7 +202,7 @@ namespace MWRender
mSceneRoot = sceneRoot; mSceneRoot = sceneRoot;
sceneRoot->setStartLight(1); sceneRoot->setStartLight(1);
int shadowCastingTraversalMask = Mask_Scene; int shadowCastingTraversalMask = 0;
if (Settings::Manager::getBool("actor shadows", "Shadows")) if (Settings::Manager::getBool("actor shadows", "Shadows"))
shadowCastingTraversalMask |= Mask_Actor; shadowCastingTraversalMask |= Mask_Actor;
if (Settings::Manager::getBool("player shadows", "Shadows")) if (Settings::Manager::getBool("player shadows", "Shadows"))
@ -210,8 +210,7 @@ namespace MWRender
if (Settings::Manager::getBool("terrain shadows", "Shadows")) if (Settings::Manager::getBool("terrain shadows", "Shadows"))
shadowCastingTraversalMask |= Mask_Terrain; shadowCastingTraversalMask |= Mask_Terrain;
mShadowManager.reset(new SceneUtil::ShadowManager(sceneRoot, mRootNode)); mShadowManager.reset(new SceneUtil::ShadowManager(sceneRoot, mRootNode, Mask_Scene | shadowCastingTraversalMask, shadowCastingTraversalMask));
mShadowManager->setupShadowSettings(shadowCastingTraversalMask);
Shader::ShaderManager::DefineMap shadowDefines = mShadowManager->getShadowDefines(); Shader::ShaderManager::DefineMap shadowDefines = mShadowManager->getShadowDefines();
Shader::ShaderManager::DefineMap globalDefines = mResourceSystem->getSceneManager()->getShaderManager().getGlobalDefines(); Shader::ShaderManager::DefineMap globalDefines = mResourceSystem->getSceneManager()->getShaderManager().getGlobalDefines();
@ -462,6 +461,10 @@ namespace MWRender
void RenderingManager::setSkyEnabled(bool enabled) void RenderingManager::setSkyEnabled(bool enabled)
{ {
mSky->setEnabled(enabled); mSky->setEnabled(enabled);
if (enabled)
mShadowManager->enableOutdoorMode();
else
mShadowManager->enableIndoorMode();
} }
bool RenderingManager::toggleRenderMode(RenderMode mode) bool RenderingManager::toggleRenderMode(RenderMode mode)

View File

@ -13,7 +13,7 @@ namespace SceneUtil
{ {
using namespace osgShadow; using namespace osgShadow;
void ShadowManager::setupShadowSettings(int castsShadowMask) void ShadowManager::setupShadowSettings()
{ {
mEnableShadows = Settings::Manager::getBool("enable shadows", "Shadows"); mEnableShadows = Settings::Manager::getBool("enable shadows", "Shadows");
@ -26,7 +26,6 @@ namespace SceneUtil
mShadowTechnique->enableShadows(); mShadowTechnique->enableShadows();
mShadowSettings->setLightNum(0); mShadowSettings->setLightNum(0);
mShadowSettings->setCastsShadowTraversalMask(castsShadowMask);
mShadowSettings->setReceivesShadowTraversalMask(~0u); mShadowSettings->setReceivesShadowTraversalMask(~0u);
int numberOfShadowMapsPerLight = Settings::Manager::getInt("number of shadow maps", "Shadows"); int numberOfShadowMapsPerLight = Settings::Manager::getInt("number of shadow maps", "Shadows");
@ -64,8 +63,10 @@ namespace SceneUtil
stateset->setTextureAttributeAndModes(i, fakeShadowMapTexture, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED); stateset->setTextureAttributeAndModes(i, fakeShadowMapTexture, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED);
} }
ShadowManager::ShadowManager(osg::ref_ptr<osg::Group> sceneRoot, osg::ref_ptr<osg::Group> rootNode) : mShadowedScene(new osgShadow::ShadowedScene), ShadowManager::ShadowManager(osg::ref_ptr<osg::Group> sceneRoot, osg::ref_ptr<osg::Group> rootNode, unsigned int outdoorShadowCastingMask, unsigned int indoorShadowCastingMask) : mShadowedScene(new osgShadow::ShadowedScene),
mShadowTechnique(new MWShadowTechnique) mShadowTechnique(new MWShadowTechnique),
mOutdoorShadowCastingMask(outdoorShadowCastingMask),
mIndoorShadowCastingMask(indoorShadowCastingMask)
{ {
mShadowedScene->setShadowTechnique(mShadowTechnique); mShadowedScene->setShadowTechnique(mShadowTechnique);
@ -73,6 +74,9 @@ namespace SceneUtil
rootNode->addChild(mShadowedScene); rootNode->addChild(mShadowedScene);
mShadowSettings = mShadowedScene->getShadowSettings(); mShadowSettings = mShadowedScene->getShadowSettings();
setupShadowSettings();
enableOutdoorMode();
} }
Shader::ShaderManager::DefineMap ShadowManager::getShadowDefines() Shader::ShaderManager::DefineMap ShadowManager::getShadowDefines()
@ -98,4 +102,12 @@ namespace SceneUtil
return definesWithShadows; return definesWithShadows;
} }
void ShadowManager::enableIndoorMode()
{
mShadowSettings->setCastsShadowTraversalMask(mIndoorShadowCastingMask);
}
void ShadowManager::enableOutdoorMode()
{
mShadowSettings->setCastsShadowTraversalMask(mOutdoorShadowCastingMask);
}
} }

View File

@ -15,16 +15,23 @@ namespace SceneUtil
public: public:
static void disableShadowsForStateSet(osg::ref_ptr<osg::StateSet> stateSet); static void disableShadowsForStateSet(osg::ref_ptr<osg::StateSet> stateSet);
ShadowManager(osg::ref_ptr<osg::Group> sceneRoot, osg::ref_ptr<osg::Group> rootNode); ShadowManager(osg::ref_ptr<osg::Group> sceneRoot, osg::ref_ptr<osg::Group> rootNode, unsigned int outdoorShadowCastingMask, unsigned int indoorShadowCastingMask);
virtual void setupShadowSettings(int castsShadowMask); virtual void setupShadowSettings();
virtual Shader::ShaderManager::DefineMap getShadowDefines(); virtual Shader::ShaderManager::DefineMap getShadowDefines();
virtual Shader::ShaderManager::DefineMap getShadowsDisabledDefines(); virtual Shader::ShaderManager::DefineMap getShadowsDisabledDefines();
virtual void enableIndoorMode();
virtual void enableOutdoorMode();
protected: protected:
bool mEnableShadows; bool mEnableShadows;
unsigned int mOutdoorShadowCastingMask;
unsigned int mIndoorShadowCastingMask;
osg::ref_ptr<osgShadow::ShadowedScene> mShadowedScene; osg::ref_ptr<osgShadow::ShadowedScene> mShadowedScene;
osg::ref_ptr<osgShadow::ShadowSettings> mShadowSettings; osg::ref_ptr<osgShadow::ShadowSettings> mShadowSettings;
osg::ref_ptr<MWShadowTechnique> mShadowTechnique; osg::ref_ptr<MWShadowTechnique> mShadowTechnique;