diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 206249c17..e2f3dd82b 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -96,7 +96,7 @@ namespace MWRender class AtmosphereUpdater : public SceneUtil::StateSetUpdater { public: - void setEmissionColor(osg::Vec4f emissionColor) + void setEmissionColor(const osg::Vec4f& emissionColor) { mEmissionColor = emissionColor; } @@ -117,6 +117,45 @@ private: osg::Vec4f mEmissionColor; }; +class AtmosphereNightUpdater : public SceneUtil::StateSetUpdater +{ +public: + AtmosphereNightUpdater(Resource::TextureManager* textureManager) + { + // we just need a texture, its contents don't really matter + mTexture = textureManager->getWarningTexture(); + } + + void setFade(const float fade) + { + mColor.a() = fade; + } + +protected: + virtual void setDefaults(osg::StateSet* stateset) + { + osg::ref_ptr texEnv (new osg::TexEnvCombine); + texEnv->setCombine_Alpha(osg::TexEnvCombine::MODULATE); + texEnv->setSource0_Alpha(osg::TexEnvCombine::PREVIOUS); + texEnv->setSource1_Alpha(osg::TexEnvCombine::CONSTANT); + texEnv->setCombine_RGB(osg::TexEnvCombine::REPLACE); + texEnv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS); + + stateset->setTextureAttributeAndModes(1, mTexture, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + stateset->setTextureAttributeAndModes(1, texEnv, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + } + + virtual void apply(osg::StateSet* stateset, osg::NodeVisitor* /*nv*/) + { + osg::TexEnvCombine* texEnv = static_cast(stateset->getTextureAttribute(1, osg::StateAttribute::TEXENV)); + texEnv->setConstantColor(mColor); + } + + osg::ref_ptr mTexture; + + osg::Vec4f mColor; +}; + class CloudUpdater : public SceneUtil::StateSetUpdater { public: @@ -129,7 +168,7 @@ public: { mTexture = texture; } - void setEmissionColor(osg::Vec4f emissionColor) + void setEmissionColor(const osg::Vec4f& emissionColor) { mEmissionColor = emissionColor; } @@ -570,6 +609,8 @@ void SkyManager::create() atmosphereNight->getOrCreateStateSet()->setAttributeAndModes(createAlphaTrackingUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); ModVertexAlphaVisitor modStars(2); atmosphereNight->accept(modStars); + mAtmosphereNightUpdater = new AtmosphereNightUpdater(mSceneManager->getTextureManager()); + atmosphereNight->addUpdateCallback(mAtmosphereNightUpdater); mSun.reset(new Sun(mRootNode, mSceneManager)); @@ -806,13 +847,9 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) if (weather.mNight && mStarsOpacity != weather.mNightFade) { - if (weather.mNightFade != 0) - { - //sh::Factory::getInstance().setSharedParameter ("nightFade", - // sh::makeProperty(new sh::FloatValue(weather.mNightFade))); + mStarsOpacity = weather.mNightFade; - //mStarsOpacity = weather.mNightFade; - } + mAtmosphereNightUpdater->setFade(mStarsOpacity); } mAtmosphereNightNode->setNodeMask(weather.mNight ? ~0 : 0); diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index bb4d2e184..b05845e53 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -20,6 +20,7 @@ namespace Resource namespace MWRender { class AtmosphereUpdater; + class AtmosphereNightUpdater; class CloudUpdater; class Sun; class Moon; @@ -107,6 +108,7 @@ namespace MWRender osg::ref_ptr mAtmosphereNightNode; float mAtmosphereNightRoll; + osg::ref_ptr mAtmosphereNightUpdater; osg::ref_ptr mAtmosphereUpdater; diff --git a/components/resource/texturemanager.cpp b/components/resource/texturemanager.cpp index 50cfd9d57..62cbd6bb3 100644 --- a/components/resource/texturemanager.cpp +++ b/components/resource/texturemanager.cpp @@ -145,4 +145,9 @@ namespace Resource } } + osg::Texture2D* TextureManager::getWarningTexture() + { + return mWarningTexture.get(); + } + } diff --git a/components/resource/texturemanager.hpp b/components/resource/texturemanager.hpp index 5ff233348..2ee3baa77 100644 --- a/components/resource/texturemanager.hpp +++ b/components/resource/texturemanager.hpp @@ -38,6 +38,8 @@ namespace Resource const VFS::Manager* getVFS() { return mVFS; } + osg::Texture2D* getWarningTexture(); + private: const VFS::Manager* mVFS;