From ea2f88a355f7c1aeaad26fced87a70863f72ad6a Mon Sep 17 00:00:00 2001 From: slothlife Date: Tue, 4 Aug 2015 21:07:42 -0500 Subject: [PATCH 1/5] Fix several sky rendering bugs, maybe also #639 Added code to hide the moons, sun, and stars for certain weather effects. Lightly refactored CelestialBody and derived classes. Fixed moons switching phase at 24:00. --- apps/openmw/mwrender/sky.cpp | 318 ++++++++++++++++---------------- apps/openmw/mwrender/sky.hpp | 58 +++++- apps/openmw/mwworld/weather.cpp | 37 +++- apps/openmw/mwworld/weather.hpp | 54 +----- 4 files changed, 248 insertions(+), 219 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 8330835a6..3a2da230f 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -322,11 +321,12 @@ private: int mMeshType; }; -class CelestialBody +// A base class for the sun and moons. Must be stored in an osg::ref_ptr due to being +// derived from osg::Referenced. +class CelestialBody : public SceneUtil::StateSetUpdater { public: - CelestialBody(osg::Group* parentNode, Resource::SceneManager* sceneManager, float scaleFactor = 1.f, int numUvSets=1) - : mSceneManager(sceneManager) + CelestialBody(osg::Group* parentNode, float scaleFactor = 1.f, int numUvSets=1) { mGeode = new osg::Geode; osg::ref_ptr geom = createTexturedQuad(numUvSets); @@ -336,42 +336,85 @@ public: mTransform->addChild(mGeode); parentNode->addChild(mTransform); + + mGeode->addUpdateCallback(this); } - void setDirection(const osg::Vec3f& direction) + virtual ~CelestialBody() { - osg::Vec3f normalizedDirection = direction / direction.length(); - mTransform->setPosition(normalizedDirection*1000.f); - - osg::Quat quat; - quat.makeRotate(osg::Vec3f(0,0,1), normalizedDirection); - mTransform->setAttitude(quat); + mGeode->removeUpdateCallback(this); } + virtual void adjustTransparency(const float ratio) = 0; + void setVisible(bool visible) { mTransform->setNodeMask(visible ? ~0 : 0); } protected: + static const float mDistance; osg::ref_ptr mTransform; osg::ref_ptr mGeode; - Resource::SceneManager* mSceneManager; - }; +const float CelestialBody::mDistance = 1000.0f; + class Sun : public CelestialBody { public: - Sun(osg::Group* parentNode, Resource::SceneManager* sceneManager) - : CelestialBody(parentNode, sceneManager, 1.f, 1) + Sun(osg::Group* parentNode, Resource::TextureManager& textureManager) + : CelestialBody(parentNode, 1.0f, 1) + , mColor(1.0f, 1.0f, 1.0f, 1.0f) + , mDummyTexture(textureManager.getWarningTexture()) { - osg::ref_ptr tex = mSceneManager->getTextureManager()->getTexture2D("textures/tx_sun_05.dds", - osg::Texture::CLAMP, osg::Texture::CLAMP); + osg::ref_ptr tex = textureManager.getTexture2D("textures/tx_sun_05.dds", + osg::Texture::CLAMP, + osg::Texture::CLAMP); mTransform->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); mTransform->getOrCreateStateSet()->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON); } + + 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); + texEnv->setConstantColor(osg::Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + + stateset->setTextureAttributeAndModes(1, mDummyTexture, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + stateset->setTextureAttributeAndModes(1, texEnv, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + } + + virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*) + { + osg::TexEnvCombine* texEnv = static_cast(stateset->getTextureAttribute(1, osg::StateAttribute::TEXENV)); + texEnv->setConstantColor(mColor); + } + + virtual void adjustTransparency(const float ratio) + { + mColor.a() = ratio; + } + + void setDirection(const osg::Vec3f& direction) + { + osg::Vec3f normalizedDirection = direction / direction.length(); + mTransform->setPosition(normalizedDirection * mDistance); + + osg::Quat quat; + quat.makeRotate(osg::Vec3f(0.0f, 0.0f, 1.0f), normalizedDirection); + mTransform->setAttitude(quat); + } + +private: + + osg::Vec4f mColor; + osg::ref_ptr mDummyTexture; }; class Moon : public CelestialBody @@ -383,18 +426,57 @@ public: Type_Secunda }; - Moon(osg::Group* parentNode, Resource::SceneManager* sceneManager, float scaleFactor, Type type) - : CelestialBody(parentNode, sceneManager, scaleFactor, 2) + Moon(osg::Group* parentNode, Resource::TextureManager& textureManager, float scaleFactor, Type type) + : CelestialBody(parentNode, scaleFactor, 2) + , mTextureManager(textureManager) , mType(type) , mPhase(MoonState::Phase_Unspecified) + , mTransparency(1.0f) + , mShadowBlend(1.0f) + , mMoonColor(1.0f, 1.0f, 1.0f, 1.0f) { - mUpdater = new MoonUpdater; - mGeode->addUpdateCallback(mUpdater); - setPhase(MoonState::Phase_Full); setVisible(true); } + virtual void setDefaults(osg::StateSet *stateset) + { + stateset->setTextureAttributeAndModes(0, mPhaseTex, osg::StateAttribute::ON); + osg::ref_ptr texEnv = new osg::TexEnvCombine; + texEnv->setCombine_RGB(osg::TexEnvCombine::MODULATE); + texEnv->setSource0_RGB(osg::TexEnvCombine::CONSTANT); + texEnv->setSource1_RGB(osg::TexEnvCombine::TEXTURE); + texEnv->setConstantColor(osg::Vec4f(1.f, 0.f, 0.f, 1.f)); // mShadowBlend * mMoonColor + stateset->setTextureAttributeAndModes(0, texEnv, osg::StateAttribute::ON); + + stateset->setTextureAttributeAndModes(1, mCircleTex, osg::StateAttribute::ON); + osg::ref_ptr texEnv2 = new osg::TexEnvCombine; + texEnv2->setCombine_RGB(osg::TexEnvCombine::ADD); + texEnv2->setCombine_Alpha(osg::TexEnvCombine::MODULATE); + texEnv2->setSource0_Alpha(osg::TexEnvCombine::TEXTURE); + texEnv2->setSource1_Alpha(osg::TexEnvCombine::CONSTANT); + texEnv2->setSource0_RGB(osg::TexEnvCombine::PREVIOUS); + texEnv2->setSource1_RGB(osg::TexEnvCombine::CONSTANT); + texEnv2->setConstantColor(osg::Vec4f(0.f, 0.f, 0.f, 1.f)); // mAtmosphereColor.rgb, mTransparency + stateset->setTextureAttributeAndModes(1, texEnv2, osg::StateAttribute::ON); + + stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + } + + virtual void apply(osg::StateSet *stateset, osg::NodeVisitor*) + { + osg::TexEnvCombine* texEnv = static_cast(stateset->getTextureAttribute(0, osg::StateAttribute::TEXENV)); + texEnv->setConstantColor(mMoonColor * mShadowBlend); + + osg::TexEnvCombine* texEnv2 = static_cast(stateset->getTextureAttribute(1, osg::StateAttribute::TEXENV)); + texEnv2->setConstantColor(osg::Vec4f(mAtmosphereColor.x(), mAtmosphereColor.y(), mAtmosphereColor.z(), mTransparency)); + } + + virtual void adjustTransparency(const float ratio) + { + mTransparency *= ratio; + } + void setState(const MoonState& state) { float radsX = ((state.mRotationFromHorizon) * M_PI) / 180.0f; @@ -404,27 +486,59 @@ public: osg::Quat rotZ(radsZ, osg::Vec3f(0.0f, 0.0f, 1.0f)); osg::Vec3f direction = rotX * rotZ * osg::Vec3f(0.0f, 1.0f, 0.0f); - mTransform->setPosition(direction * 1000.0f); + mTransform->setPosition(direction * mDistance); // The moon quad is initially oriented facing down, so we need to offset its X-axis // rotation to rotate it to face the camera when sitting at the horizon. - osg::Quat attX((-M_PI / 2.0f) + radsX, osg::Vec3f(1,0,0)); + osg::Quat attX((-M_PI / 2.0f) + radsX, osg::Vec3f(1.0f, 0.0f, 0.0f)); mTransform->setAttitude(attX * rotZ); setPhase(state.mPhase); - setTransparency(state.mMoonAlpha); - setShadowBlend(state.mShadowBlend); + mTransparency = state.mMoonAlpha; + mShadowBlend = state.mShadowBlend; } - void setTextures(const std::string& phaseTex, const std::string& circleTex) + void setAtmosphereColor(const osg::Vec4f& color) { - osg::ref_ptr phaseTexPtr = mSceneManager->getTextureManager()->getTexture2D(phaseTex, - osg::Texture::CLAMP, osg::Texture::CLAMP); + mAtmosphereColor = color; + } - osg::ref_ptr circleTexPtr = mSceneManager->getTextureManager()->getTexture2D(circleTex, - osg::Texture::CLAMP, osg::Texture::CLAMP); + void setColor(const osg::Vec4f& color) + { + mMoonColor = color; + } - mUpdater->setTextures(phaseTexPtr, circleTexPtr); + unsigned int getPhaseInt() const + { + if (mPhase == MoonState::Phase_New) return 0; + else if (mPhase == MoonState::Phase_WaxingCrescent) return 1; + else if (mPhase == MoonState::Phase_WaningCrescent) return 1; + else if (mPhase == MoonState::Phase_FirstQuarter) return 2; + else if (mPhase == MoonState::Phase_ThirdQuarter) return 2; + else if (mPhase == MoonState::Phase_WaxingGibbous) return 3; + else if (mPhase == MoonState::Phase_WaningGibbous) return 3; + else if (mPhase == MoonState::Phase_Full) return 4; + return 0; + } + +private: + + Resource::TextureManager& mTextureManager; + Type mType; + MoonState::Phase mPhase; + float mTransparency; + float mShadowBlend; + osg::Vec4f mAtmosphereColor; + osg::Vec4f mMoonColor; + osg::ref_ptr mPhaseTex; + osg::ref_ptr mCircleTex; + + void setTextures(const std::string& phaseTex, const std::string& circleTex) + { + mPhaseTex = mTextureManager.getTexture2D(phaseTex, osg::Texture::CLAMP, osg::Texture::CLAMP); + mCircleTex = mTextureManager.getTexture2D(circleTex, osg::Texture::CLAMP, osg::Texture::CLAMP); + + reset(); } void setPhase(const MoonState::Phase& phase) @@ -454,129 +568,6 @@ public: else setTextures(textureName, "textures/tx_mooncircle_full_m.dds"); } - - void setType(const Type& type) - { - mType = type; - } - - class MoonUpdater : public SceneUtil::StateSetUpdater - { - public: - MoonUpdater() - : mTransparency(1.0f) - , mShadowBlend(1.0f) - , mMoonColor(1,1,1,1) - { - } - - virtual void setDefaults(osg::StateSet *stateset) - { - stateset->setTextureAttributeAndModes(0, mPhaseTex, osg::StateAttribute::ON); - osg::ref_ptr texEnv = new osg::TexEnvCombine; - texEnv->setCombine_RGB(osg::TexEnvCombine::MODULATE); - texEnv->setSource0_RGB(osg::TexEnvCombine::CONSTANT); - texEnv->setSource1_RGB(osg::TexEnvCombine::TEXTURE); - texEnv->setConstantColor(osg::Vec4f(1.f, 0.f, 0.f, 1.f)); // mShadowBlend * mMoonColor - stateset->setTextureAttributeAndModes(0, texEnv, osg::StateAttribute::ON); - - stateset->setTextureAttributeAndModes(1, mCircleTex, osg::StateAttribute::ON); - osg::ref_ptr texEnv2 = new osg::TexEnvCombine; - texEnv2->setCombine_RGB(osg::TexEnvCombine::ADD); - texEnv2->setCombine_Alpha(osg::TexEnvCombine::MODULATE); - texEnv2->setSource0_Alpha(osg::TexEnvCombine::TEXTURE); - texEnv2->setSource1_Alpha(osg::TexEnvCombine::CONSTANT); - texEnv2->setSource0_RGB(osg::TexEnvCombine::PREVIOUS); - texEnv2->setSource1_RGB(osg::TexEnvCombine::CONSTANT); - texEnv2->setConstantColor(osg::Vec4f(0.f, 0.f, 0.f, 1.f)); // mAtmosphereColor.rgb, mTransparency - stateset->setTextureAttributeAndModes(1, texEnv2, osg::StateAttribute::ON); - - stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); - } - - virtual void apply(osg::StateSet *stateset, osg::NodeVisitor*) - { - osg::TexEnvCombine* texEnv = static_cast(stateset->getTextureAttribute(0, osg::StateAttribute::TEXENV)); - texEnv->setConstantColor(mMoonColor * mShadowBlend); - - osg::TexEnvCombine* texEnv2 = static_cast(stateset->getTextureAttribute(1, osg::StateAttribute::TEXENV)); - texEnv2->setConstantColor(osg::Vec4f(mAtmosphereColor.x(), mAtmosphereColor.y(), mAtmosphereColor.z(), mTransparency)); - } - - void setTransparency(const float ratio) - { - mTransparency = ratio; - } - - void setShadowBlend(const float blendFactor) - { - mShadowBlend = blendFactor; - } - - void setAtmosphereColor(const osg::Vec4f& color) - { - mAtmosphereColor = color; - } - - void setMoonColor(const osg::Vec4f& color) - { - mMoonColor = color; - } - - void setTextures(osg::ref_ptr phaseTex, osg::ref_ptr circleTex) - { - mPhaseTex = phaseTex; - mCircleTex = circleTex; - reset(); - } - - private: - float mTransparency; - float mShadowBlend; - osg::Vec4f mAtmosphereColor; - osg::Vec4f mMoonColor; - osg::ref_ptr mPhaseTex; - osg::ref_ptr mCircleTex; - }; - - - void setAtmosphereColor(const osg::Vec4f& color) - { - mUpdater->setAtmosphereColor(color); - } - - void setColor(const osg::Vec4f& color) - { - mUpdater->setMoonColor(color); - } - - void setTransparency(const float ratio) - { - mUpdater->setTransparency(ratio); - } - - void setShadowBlend(const float blendFactor) - { - mUpdater->setShadowBlend(blendFactor); - } - - unsigned int getPhaseInt() const - { - if (mPhase == MoonState::Phase_New) return 0; - else if (mPhase == MoonState::Phase_WaxingCrescent) return 1; - else if (mPhase == MoonState::Phase_WaningCrescent) return 1; - else if (mPhase == MoonState::Phase_FirstQuarter) return 2; - else if (mPhase == MoonState::Phase_ThirdQuarter) return 2; - else if (mPhase == MoonState::Phase_WaxingGibbous) return 3; - else if (mPhase == MoonState::Phase_WaningGibbous) return 3; - else if (mPhase == MoonState::Phase_Full) return 4; - return 0; - } - -private: - Type mType; - MoonState::Phase mPhase; - osg::ref_ptr mUpdater; }; SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager) @@ -641,11 +632,11 @@ void SkyManager::create() mAtmosphereNightUpdater = new AtmosphereNightUpdater(mSceneManager->getTextureManager()); atmosphereNight->addUpdateCallback(mAtmosphereNightUpdater); - mSun.reset(new Sun(mRootNode, mSceneManager)); + mSun = new Sun(mRootNode, *mSceneManager->getTextureManager()); const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback(); - mMasser.reset(new Moon(mRootNode, mSceneManager, fallback->getFallbackFloat("Moons_Masser_Size")/125, Moon::Type_Masser)); - mSecunda.reset(new Moon(mRootNode, mSceneManager, fallback->getFallbackFloat("Moons_Secunda_Size")/125, Moon::Type_Secunda)); + mMasser = new Moon(mRootNode, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Masser_Size")/125, Moon::Type_Masser); + mSecunda = new Moon(mRootNode, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Secunda_Size")/125, Moon::Type_Secunda); mCloudNode = new osg::PositionAttitudeTransform; mRootNode->addChild(mCloudNode); @@ -970,7 +961,7 @@ void SkyManager::updateRainParameters() } } -void SkyManager::setWeather(const MWWorld::WeatherResult& weather) +void SkyManager::setWeather(const WeatherResult& weather) { if (!mCreated) return; @@ -1087,9 +1078,14 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) mCloudSpeed = weather.mCloudSpeed; - if (weather.mNight && mStarsOpacity != weather.mNightFade) + mMasser->adjustTransparency(weather.mCelestialBodyTransparency); + mSecunda->adjustTransparency(weather.mCelestialBodyTransparency); + mSun->adjustTransparency(weather.mCelestialBodyTransparency); + + float nextStarsOpacity = weather.mNightFade * weather.mCelestialBodyTransparency; + if(weather.mNight && mStarsOpacity != nextStarsOpacity) { - mStarsOpacity = weather.mNightFade; + mStarsOpacity = nextStarsOpacity; mAtmosphereNightUpdater->setFade(mStarsOpacity); } diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index eb953d128..16509ef32 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -1,9 +1,11 @@ #ifndef OPENMW_MWRENDER_SKY_H #define OPENMW_MWRENDER_SKY_H -#include +#include -#include "../mwworld/weather.hpp" +#include +#include +#include namespace osg { @@ -33,6 +35,50 @@ namespace MWRender class RainFader; class AlphaFader; + struct WeatherResult + { + std::string mCloudTexture; + std::string mNextCloudTexture; + float mCloudBlendFactor; + + osg::Vec4f mFogColor; + + osg::Vec4f mAmbientColor; + + osg::Vec4f mSkyColor; + + osg::Vec4f mSunColor; + + osg::Vec4f mSunDiscColor; + + float mFogDepth; + + float mWindSpeed; + + float mCloudSpeed; + + float mCloudOpacity; + + float mGlareView; + + bool mNight; // use night skybox + float mNightFade; // fading factor for night skybox + + bool mIsStorm; + + std::string mAmbientLoopSoundID; + float mAmbientSoundVolume; + + std::string mParticleEffect; + std::string mRainEffect; + float mEffectFade; + + float mRainSpeed; + float mRainFrequency; + + float mCelestialBodyTransparency; + }; + struct MoonState { enum Phase @@ -82,7 +128,7 @@ namespace MWRender void setMoonColour (bool red); ///< change Secunda colour to red - void setWeather(const MWWorld::WeatherResult& weather); + void setWeather(const WeatherResult& weather); void sunEnable(); @@ -133,9 +179,9 @@ namespace MWRender osg::ref_ptr mAtmosphereUpdater; - std::auto_ptr mSun; - std::auto_ptr mMasser; - std::auto_ptr mSecunda; + osg::ref_ptr mSun; + osg::ref_ptr mMasser; + osg::ref_ptr mSecunda; osg::ref_ptr mRainNode; osg::ref_ptr mRainParticleSystem; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 0e78edce7..679565e45 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -61,7 +61,7 @@ MWRender::MoonState MoonModel::calculateState(unsigned int daysPassed, float gam { rotationFromHorizon, mAxisOffset, // Reverse engineered from Morrowind's scene graph rotation matrices. - static_cast(phase(daysPassed)), + static_cast(phase(daysPassed, gameHour)), shadowBlend(rotationFromHorizon), earlyMoonShadowAlpha(rotationFromHorizon) * hourlyAlpha(gameHour) }; @@ -130,12 +130,17 @@ inline float MoonModel::rotation(float hours) const return 15.0f * mSpeed * hours; } -inline unsigned int MoonModel::phase(unsigned int daysPassed) const +inline unsigned int MoonModel::phase(unsigned int daysPassed, float gameHour) const { // Morrowind starts with a full moon on 16 Last Seed and then begins to wane 17 Last Seed, working on 3 day phase cycle. // Note: this is an internal helper, and as such we don't want to return MWRender::MoonState::Phase since we can't // forward declare it (C++11 strongly typed enums solve this). - return ((daysPassed + 1) / 3) % 8; + + // If the moon didn't rise yet today, use yesterday's moon phase. + if(gameHour < moonRiseHour(daysPassed)) + return (daysPassed / 3) % 8; + else + return ((daysPassed + 1) / 3) % 8; } inline float MoonModel::shadowBlend(float angle) const @@ -289,44 +294,54 @@ WeatherManager::WeatherManager(MWRender::RenderingManager* rendering, MWWorld::F //Weather Weather clear; + clear.mObstructsCelestialBodies = false; setFallbackWeather(clear,"clear"); Weather cloudy; + cloudy.mObstructsCelestialBodies = false; setFallbackWeather(cloudy,"cloudy"); Weather foggy; + foggy.mObstructsCelestialBodies = false; setFallbackWeather(foggy,"foggy"); Weather thunderstorm; thunderstorm.mAmbientLoopSoundID = "rain heavy"; thunderstorm.mRainEffect = "meshes\\raindrop.nif"; + thunderstorm.mObstructsCelestialBodies = true; setFallbackWeather(thunderstorm,"thunderstorm"); Weather rain; rain.mAmbientLoopSoundID = "rain"; rain.mRainEffect = "meshes\\raindrop.nif"; + rain.mObstructsCelestialBodies = true; setFallbackWeather(rain,"rain"); Weather overcast; + overcast.mObstructsCelestialBodies = true; setFallbackWeather(overcast,"overcast"); Weather ashstorm; ashstorm.mAmbientLoopSoundID = "ashstorm"; ashstorm.mParticleEffect = "meshes\\ashcloud.nif"; + ashstorm.mObstructsCelestialBodies = true; setFallbackWeather(ashstorm,"ashstorm"); Weather blight; blight.mAmbientLoopSoundID = "blight"; blight.mParticleEffect = "meshes\\blightcloud.nif"; + blight.mObstructsCelestialBodies = true; setFallbackWeather(blight,"blight"); Weather snow; snow.mParticleEffect = "meshes\\snow.nif"; + snow.mObstructsCelestialBodies = true; setFallbackWeather(snow, "snow"); Weather blizzard; blizzard.mAmbientLoopSoundID = "BM Blizzard"; blizzard.mParticleEffect = "meshes\\blizzard.nif"; + blizzard.mObstructsCelestialBodies = true; setFallbackWeather(blizzard,"blizzard"); } @@ -460,14 +475,16 @@ void WeatherManager::setResult(const std::string& weatherType) mResult.mNightFade = factor; } } + + mResult.mCelestialBodyTransparency = current.mObstructsCelestialBodies ? 0.0f : 1.0f; } void WeatherManager::transition(float factor) { setResult(mCurrentWeather); - const WeatherResult current = mResult; + const MWRender::WeatherResult current = mResult; setResult(mNextWeather); - const WeatherResult other = mResult; + const MWRender::WeatherResult other = mResult; mResult.mCloudTexture = current.mCloudTexture; mResult.mNextCloudTexture = other.mCloudTexture; @@ -513,6 +530,16 @@ void WeatherManager::transition(float factor) mResult.mEffectFade = mResult.mAmbientSoundVolume; mResult.mAmbientLoopSoundID = other.mAmbientLoopSoundID; } + + const Weather& currentSettings = mWeatherSettings[mCurrentWeather]; + const Weather& nextSettings = mWeatherSettings[mNextWeather]; + + if(currentSettings.mObstructsCelestialBodies && !nextSettings.mObstructsCelestialBodies) + mResult.mCelestialBodyTransparency = factor; + else if(!currentSettings.mObstructsCelestialBodies && nextSettings.mObstructsCelestialBodies) + mResult.mCelestialBodyTransparency = 1 - factor; + else + mResult.mCelestialBodyTransparency = current.mCelestialBodyTransparency; } void WeatherManager::update(float duration, bool paused) diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index 8f7634fbb..1bc3bc357 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -9,6 +9,8 @@ #include "../mwbase/soundmanager.hpp" +#include "../mwrender/sky.hpp" + namespace ESM { struct Region; @@ -19,7 +21,6 @@ namespace ESM namespace MWRender { class RenderingManager; - struct MoonState; } namespace Loading @@ -31,50 +32,6 @@ namespace MWWorld { class Fallback; - /// Defines the actual weather that results from weather setting (see below), time of day and weather transition - struct WeatherResult - { - std::string mCloudTexture; - std::string mNextCloudTexture; - float mCloudBlendFactor; - - osg::Vec4f mFogColor; - - osg::Vec4f mAmbientColor; - - osg::Vec4f mSkyColor; - - osg::Vec4f mSunColor; - - osg::Vec4f mSunDiscColor; - - float mFogDepth; - - float mWindSpeed; - - float mCloudSpeed; - - float mCloudOpacity; - - float mGlareView; - - bool mNight; // use night skybox - float mNightFade; // fading factor for night skybox - - bool mIsStorm; - - std::string mAmbientLoopSoundID; - float mAmbientSoundVolume; - - std::string mParticleEffect; - std::string mRainEffect; - float mEffectFade; - - float mRainSpeed; - float mRainFrequency; - }; - - /// Defines a single weather setting (according to INI) struct Weather { @@ -149,6 +106,9 @@ namespace MWWorld // Note: For Weather Blight, there is a "Disease Chance" (=0.1) setting. But according to MWSFD this feature // is broken in the vanilla game and was disabled. + + // Some weather patterns will obstruct the moons, sun, and stars. + bool mObstructsCelestialBodies; }; class MoonModel @@ -173,7 +133,7 @@ namespace MWWorld float angle(unsigned int daysPassed, float gameHour) const; float moonRiseHour(unsigned int daysPassed) const; float rotation(float hours) const; - unsigned int phase(unsigned int daysPassed) const; + unsigned int phase(unsigned int daysPassed, float gameHour) const; float shadowBlend(float angle) const; float hourlyAlpha(float gameHour) const; float earlyMoonShadowAlpha(float angle) const; @@ -268,7 +228,7 @@ namespace MWWorld void setWeather(const std::string& weatherType, bool instant=false); std::string nextWeather(const ESM::Region* region) const; - WeatherResult mResult; + MWRender::WeatherResult mResult; typedef std::map > RegionModMap; RegionModMap mRegionMods; From f2e51b0579fb44ea391ed439ca4c9010cd098953 Mon Sep 17 00:00:00 2001 From: slothlife Date: Wed, 5 Aug 2015 21:03:21 -0500 Subject: [PATCH 2/5] Use diffuse alpha to fade Sun --- apps/openmw/mwrender/sky.cpp | 39 +++++++++++++----------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 3a2da230f..38b6b9193 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -321,12 +321,12 @@ private: int mMeshType; }; -// A base class for the sun and moons. Must be stored in an osg::ref_ptr due to being -// derived from osg::Referenced. +/// A base class for the sun and moons. +/// \note Must be stored in an osg::ref_ptr due to being derived from osg::Referenced. class CelestialBody : public SceneUtil::StateSetUpdater { public: - CelestialBody(osg::Group* parentNode, float scaleFactor = 1.f, int numUvSets=1) + CelestialBody(osg::Group* parentNode, float scaleFactor, int numUvSets) { mGeode = new osg::Geode; osg::ref_ptr geom = createTexturedQuad(numUvSets); @@ -365,35 +365,26 @@ class Sun : public CelestialBody public: Sun(osg::Group* parentNode, Resource::TextureManager& textureManager) : CelestialBody(parentNode, 1.0f, 1) - , mColor(1.0f, 1.0f, 1.0f, 1.0f) - , mDummyTexture(textureManager.getWarningTexture()) + , mTextureManager(textureManager) + , mColor(0.0f, 0.0f, 0.0f, 1.0f) { - osg::ref_ptr tex = textureManager.getTexture2D("textures/tx_sun_05.dds", - osg::Texture::CLAMP, - osg::Texture::CLAMP); - - mTransform->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); - mTransform->getOrCreateStateSet()->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON); } 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); - texEnv->setConstantColor(osg::Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + osg::ref_ptr tex = mTextureManager.getTexture2D("textures/tx_sun_05.dds", + osg::Texture::CLAMP, + osg::Texture::CLAMP); - stateset->setTextureAttributeAndModes(1, mDummyTexture, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); - stateset->setTextureAttributeAndModes(1, texEnv, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + stateset->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); + stateset->setAttributeAndModes(createAlphaTrackingUnlitMaterial(), + osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); } virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*) { - osg::TexEnvCombine* texEnv = static_cast(stateset->getTextureAttribute(1, osg::StateAttribute::TEXENV)); - texEnv->setConstantColor(mColor); + osg::Material* mat = static_cast(stateset->getAttribute(osg::StateAttribute::MATERIAL)); + mat->setDiffuse(osg::Material::FRONT_AND_BACK, mColor); } virtual void adjustTransparency(const float ratio) @@ -412,9 +403,8 @@ public: } private: - + Resource::TextureManager& mTextureManager; osg::Vec4f mColor; - osg::ref_ptr mDummyTexture; }; class Moon : public CelestialBody @@ -522,7 +512,6 @@ public: } private: - Resource::TextureManager& mTextureManager; Type mType; MoonState::Phase mPhase; From 238ae419a363ef263ffbba13307671a5d30e73f9 Mon Sep 17 00:00:00 2001 From: slothlife Date: Wed, 5 Aug 2015 22:02:54 -0500 Subject: [PATCH 3/5] Fix use of incorrect material for Sun --- apps/openmw/mwrender/sky.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 38b6b9193..f16f97bc2 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -377,7 +377,7 @@ public: osg::Texture::CLAMP); stateset->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); - stateset->setAttributeAndModes(createAlphaTrackingUnlitMaterial(), + stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); } From 3235cecddfe11a1bbe70b231b7e1fa8fb716b1db Mon Sep 17 00:00:00 2001 From: slothlife Date: Fri, 7 Aug 2015 00:08:18 -0500 Subject: [PATCH 4/5] Use Glare View for visibility of celestial bodies Fixed memory leak from Sun and Moon objects by pulling Updaters back out into separate objects. Removed code related to mCelestialBodyTransparency. --- apps/openmw/mwrender/sky.cpp | 233 ++++++++++++++++++-------------- apps/openmw/mwrender/sky.hpp | 9 +- apps/openmw/mwworld/weather.cpp | 22 --- apps/openmw/mwworld/weather.hpp | 6 +- 4 files changed, 139 insertions(+), 131 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index f16f97bc2..788848cc4 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -322,8 +322,7 @@ private: }; /// A base class for the sun and moons. -/// \note Must be stored in an osg::ref_ptr due to being derived from osg::Referenced. -class CelestialBody : public SceneUtil::StateSetUpdater +class CelestialBody { public: CelestialBody(osg::Group* parentNode, float scaleFactor, int numUvSets) @@ -336,14 +335,9 @@ public: mTransform->addChild(mGeode); parentNode->addChild(mTransform); - - mGeode->addUpdateCallback(this); } - virtual ~CelestialBody() - { - mGeode->removeUpdateCallback(this); - } + virtual ~CelestialBody() {} virtual void adjustTransparency(const float ratio) = 0; @@ -365,31 +359,19 @@ class Sun : public CelestialBody public: Sun(osg::Group* parentNode, Resource::TextureManager& textureManager) : CelestialBody(parentNode, 1.0f, 1) - , mTextureManager(textureManager) - , mColor(0.0f, 0.0f, 0.0f, 1.0f) + , mUpdater(new Updater(textureManager)) { + mGeode->addUpdateCallback(mUpdater); } - virtual void setDefaults(osg::StateSet* stateset) + ~Sun() { - osg::ref_ptr tex = mTextureManager.getTexture2D("textures/tx_sun_05.dds", - osg::Texture::CLAMP, - osg::Texture::CLAMP); - - stateset->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); - stateset->setAttributeAndModes(createUnlitMaterial(), - osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); - } - - virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*) - { - osg::Material* mat = static_cast(stateset->getAttribute(osg::StateAttribute::MATERIAL)); - mat->setDiffuse(osg::Material::FRONT_AND_BACK, mColor); + mGeode->removeUpdateCallback(mUpdater); } virtual void adjustTransparency(const float ratio) { - mColor.a() = ratio; + mUpdater->mColor.a() = ratio; } void setDirection(const osg::Vec3f& direction) @@ -403,8 +385,36 @@ public: } private: - Resource::TextureManager& mTextureManager; - osg::Vec4f mColor; + struct Updater : public SceneUtil::StateSetUpdater + { + Resource::TextureManager& mTextureManager; + osg::Vec4f mColor; + + Updater(Resource::TextureManager& textureManager) + : mTextureManager(textureManager) + , mColor(0.0f, 0.0f, 0.0f, 1.0f) + { + } + + virtual void setDefaults(osg::StateSet* stateset) + { + osg::ref_ptr tex = mTextureManager.getTexture2D("textures/tx_sun_05.dds", + osg::Texture::CLAMP, + osg::Texture::CLAMP); + + stateset->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON); + stateset->setAttributeAndModes(createUnlitMaterial(), + osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); + } + + virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*) + { + osg::Material* mat = static_cast(stateset->getAttribute(osg::StateAttribute::MATERIAL)); + mat->setDiffuse(osg::Material::FRONT_AND_BACK, mColor); + } + }; + + osg::ref_ptr mUpdater; }; class Moon : public CelestialBody @@ -418,53 +428,24 @@ public: Moon(osg::Group* parentNode, Resource::TextureManager& textureManager, float scaleFactor, Type type) : CelestialBody(parentNode, scaleFactor, 2) - , mTextureManager(textureManager) , mType(type) , mPhase(MoonState::Phase_Unspecified) - , mTransparency(1.0f) - , mShadowBlend(1.0f) - , mMoonColor(1.0f, 1.0f, 1.0f, 1.0f) + , mUpdater(new Updater(textureManager)) { setPhase(MoonState::Phase_Full); setVisible(true); - } - virtual void setDefaults(osg::StateSet *stateset) - { - stateset->setTextureAttributeAndModes(0, mPhaseTex, osg::StateAttribute::ON); - osg::ref_ptr texEnv = new osg::TexEnvCombine; - texEnv->setCombine_RGB(osg::TexEnvCombine::MODULATE); - texEnv->setSource0_RGB(osg::TexEnvCombine::CONSTANT); - texEnv->setSource1_RGB(osg::TexEnvCombine::TEXTURE); - texEnv->setConstantColor(osg::Vec4f(1.f, 0.f, 0.f, 1.f)); // mShadowBlend * mMoonColor - stateset->setTextureAttributeAndModes(0, texEnv, osg::StateAttribute::ON); - - stateset->setTextureAttributeAndModes(1, mCircleTex, osg::StateAttribute::ON); - osg::ref_ptr texEnv2 = new osg::TexEnvCombine; - texEnv2->setCombine_RGB(osg::TexEnvCombine::ADD); - texEnv2->setCombine_Alpha(osg::TexEnvCombine::MODULATE); - texEnv2->setSource0_Alpha(osg::TexEnvCombine::TEXTURE); - texEnv2->setSource1_Alpha(osg::TexEnvCombine::CONSTANT); - texEnv2->setSource0_RGB(osg::TexEnvCombine::PREVIOUS); - texEnv2->setSource1_RGB(osg::TexEnvCombine::CONSTANT); - texEnv2->setConstantColor(osg::Vec4f(0.f, 0.f, 0.f, 1.f)); // mAtmosphereColor.rgb, mTransparency - stateset->setTextureAttributeAndModes(1, texEnv2, osg::StateAttribute::ON); - - stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + mGeode->addUpdateCallback(mUpdater); } - virtual void apply(osg::StateSet *stateset, osg::NodeVisitor*) + ~Moon() { - osg::TexEnvCombine* texEnv = static_cast(stateset->getTextureAttribute(0, osg::StateAttribute::TEXENV)); - texEnv->setConstantColor(mMoonColor * mShadowBlend); - - osg::TexEnvCombine* texEnv2 = static_cast(stateset->getTextureAttribute(1, osg::StateAttribute::TEXENV)); - texEnv2->setConstantColor(osg::Vec4f(mAtmosphereColor.x(), mAtmosphereColor.y(), mAtmosphereColor.z(), mTransparency)); + mGeode->removeUpdateCallback(mUpdater); } virtual void adjustTransparency(const float ratio) { - mTransparency *= ratio; + mUpdater->mTransparency *= ratio; } void setState(const MoonState& state) @@ -484,18 +465,18 @@ public: mTransform->setAttitude(attX * rotZ); setPhase(state.mPhase); - mTransparency = state.mMoonAlpha; - mShadowBlend = state.mShadowBlend; + mUpdater->mTransparency = state.mMoonAlpha; + mUpdater->mShadowBlend = state.mShadowBlend; } void setAtmosphereColor(const osg::Vec4f& color) { - mAtmosphereColor = color; + mUpdater->mAtmosphereColor = color; } void setColor(const osg::Vec4f& color) { - mMoonColor = color; + mUpdater->mMoonColor = color; } unsigned int getPhaseInt() const @@ -512,50 +493,102 @@ public: } private: - Resource::TextureManager& mTextureManager; - Type mType; - MoonState::Phase mPhase; - float mTransparency; - float mShadowBlend; - osg::Vec4f mAtmosphereColor; - osg::Vec4f mMoonColor; - osg::ref_ptr mPhaseTex; - osg::ref_ptr mCircleTex; + struct Updater : public SceneUtil::StateSetUpdater + { + Resource::TextureManager& mTextureManager; + osg::ref_ptr mPhaseTex; + osg::ref_ptr mCircleTex; + float mTransparency; + float mShadowBlend; + osg::Vec4f mAtmosphereColor; + osg::Vec4f mMoonColor; + + Updater(Resource::TextureManager& textureManager) + : mTextureManager(textureManager) + , mPhaseTex() + , mCircleTex() + , mTransparency(1.0f) + , mShadowBlend(1.0f) + , mAtmosphereColor(1.0f, 1.0f, 1.0f, 1.0f) + , mMoonColor(1.0f, 1.0f, 1.0f, 1.0f) + { + } - void setTextures(const std::string& phaseTex, const std::string& circleTex) - { - mPhaseTex = mTextureManager.getTexture2D(phaseTex, osg::Texture::CLAMP, osg::Texture::CLAMP); - mCircleTex = mTextureManager.getTexture2D(circleTex, osg::Texture::CLAMP, osg::Texture::CLAMP); + virtual void setDefaults(osg::StateSet* stateset) + { + stateset->setTextureAttributeAndModes(0, mPhaseTex, osg::StateAttribute::ON); + osg::ref_ptr texEnv = new osg::TexEnvCombine; + texEnv->setCombine_RGB(osg::TexEnvCombine::MODULATE); + texEnv->setSource0_RGB(osg::TexEnvCombine::CONSTANT); + texEnv->setSource1_RGB(osg::TexEnvCombine::TEXTURE); + texEnv->setConstantColor(osg::Vec4f(1.f, 0.f, 0.f, 1.f)); // mShadowBlend * mMoonColor + stateset->setTextureAttributeAndModes(0, texEnv, osg::StateAttribute::ON); + + stateset->setTextureAttributeAndModes(1, mCircleTex, osg::StateAttribute::ON); + osg::ref_ptr texEnv2 = new osg::TexEnvCombine; + texEnv2->setCombine_RGB(osg::TexEnvCombine::ADD); + texEnv2->setCombine_Alpha(osg::TexEnvCombine::MODULATE); + texEnv2->setSource0_Alpha(osg::TexEnvCombine::TEXTURE); + texEnv2->setSource1_Alpha(osg::TexEnvCombine::CONSTANT); + texEnv2->setSource0_RGB(osg::TexEnvCombine::PREVIOUS); + texEnv2->setSource1_RGB(osg::TexEnvCombine::CONSTANT); + texEnv2->setConstantColor(osg::Vec4f(0.f, 0.f, 0.f, 1.f)); // mAtmosphereColor.rgb, mTransparency + stateset->setTextureAttributeAndModes(1, texEnv2, osg::StateAttribute::ON); + + stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); + } - reset(); - } + virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*) + { + osg::TexEnvCombine* texEnv = static_cast(stateset->getTextureAttribute(0, osg::StateAttribute::TEXENV)); + texEnv->setConstantColor(mMoonColor * mShadowBlend); + + osg::TexEnvCombine* texEnv2 = static_cast(stateset->getTextureAttribute(1, osg::StateAttribute::TEXENV)); + texEnv2->setConstantColor(osg::Vec4f(mAtmosphereColor.x(), mAtmosphereColor.y(), mAtmosphereColor.z(), mTransparency)); + } + + void setTextures(const std::string& phaseTex, const std::string& circleTex) + { + mPhaseTex = mTextureManager.getTexture2D(phaseTex, osg::Texture::CLAMP, osg::Texture::CLAMP); + mCircleTex = mTextureManager.getTexture2D(circleTex, osg::Texture::CLAMP, osg::Texture::CLAMP); + + reset(); + } + }; + + Type mType; + MoonState::Phase mPhase; + osg::ref_ptr mUpdater; void setPhase(const MoonState::Phase& phase) { - if (mPhase == phase) + if(mPhase == phase) return; + mPhase = phase; std::string textureName = "textures/tx_"; - if (mType == Moon::Type_Secunda) textureName += "secunda_"; - else textureName += "masser_"; + if (mType == Moon::Type_Secunda) + textureName += "secunda_"; + else + textureName += "masser_"; - if (phase == MoonState::Phase_New) textureName += "new"; - else if (phase == MoonState::Phase_WaxingCrescent) textureName += "one_wax"; - else if (phase == MoonState::Phase_FirstQuarter) textureName += "half_wax"; - else if (phase == MoonState::Phase_WaxingGibbous) textureName += "three_wax"; - else if (phase == MoonState::Phase_WaningCrescent) textureName += "one_wan"; - else if (phase == MoonState::Phase_ThirdQuarter) textureName += "half_wan"; - else if (phase == MoonState::Phase_WaningGibbous) textureName += "three_wan"; - else if (phase == MoonState::Phase_Full) textureName += "full"; + if (phase == MoonState::Phase_New) textureName += "new"; + else if(phase == MoonState::Phase_WaxingCrescent) textureName += "one_wax"; + else if(phase == MoonState::Phase_FirstQuarter) textureName += "half_wax"; + else if(phase == MoonState::Phase_WaxingGibbous) textureName += "three_wax"; + else if(phase == MoonState::Phase_WaningCrescent) textureName += "one_wan"; + else if(phase == MoonState::Phase_ThirdQuarter) textureName += "half_wan"; + else if(phase == MoonState::Phase_WaningGibbous) textureName += "three_wan"; + else if(phase == MoonState::Phase_Full) textureName += "full"; textureName += ".dds"; if (mType == Moon::Type_Secunda) - setTextures(textureName, "textures/tx_mooncircle_full_s.dds"); + mUpdater->setTextures(textureName, "textures/tx_mooncircle_full_s.dds"); else - setTextures(textureName, "textures/tx_mooncircle_full_m.dds"); + mUpdater->setTextures(textureName, "textures/tx_mooncircle_full_m.dds"); } }; @@ -621,11 +654,11 @@ void SkyManager::create() mAtmosphereNightUpdater = new AtmosphereNightUpdater(mSceneManager->getTextureManager()); atmosphereNight->addUpdateCallback(mAtmosphereNightUpdater); - mSun = new Sun(mRootNode, *mSceneManager->getTextureManager()); + mSun.reset(new Sun(mRootNode, *mSceneManager->getTextureManager())); const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback(); - mMasser = new Moon(mRootNode, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Masser_Size")/125, Moon::Type_Masser); - mSecunda = new Moon(mRootNode, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Secunda_Size")/125, Moon::Type_Secunda); + mMasser.reset(new Moon(mRootNode, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Masser_Size")/125, Moon::Type_Masser)); + mSecunda.reset(new Moon(mRootNode, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Secunda_Size")/125, Moon::Type_Secunda)); mCloudNode = new osg::PositionAttitudeTransform; mRootNode->addChild(mCloudNode); @@ -1067,11 +1100,11 @@ void SkyManager::setWeather(const WeatherResult& weather) mCloudSpeed = weather.mCloudSpeed; - mMasser->adjustTransparency(weather.mCelestialBodyTransparency); - mSecunda->adjustTransparency(weather.mCelestialBodyTransparency); - mSun->adjustTransparency(weather.mCelestialBodyTransparency); + mMasser->adjustTransparency(weather.mGlareView); + mSecunda->adjustTransparency(weather.mGlareView); + mSun->adjustTransparency(weather.mGlareView); - float nextStarsOpacity = weather.mNightFade * weather.mCelestialBodyTransparency; + float nextStarsOpacity = weather.mNightFade * weather.mGlareView; if(weather.mNight && mStarsOpacity != nextStarsOpacity) { mStarsOpacity = nextStarsOpacity; diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index 16509ef32..4b1acadc3 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -2,6 +2,7 @@ #define OPENMW_MWRENDER_SKY_H #include +#include #include #include @@ -75,8 +76,6 @@ namespace MWRender float mRainSpeed; float mRainFrequency; - - float mCelestialBodyTransparency; }; struct MoonState @@ -179,9 +178,9 @@ namespace MWRender osg::ref_ptr mAtmosphereUpdater; - osg::ref_ptr mSun; - osg::ref_ptr mMasser; - osg::ref_ptr mSecunda; + std::auto_ptr mSun; + std::auto_ptr mMasser; + std::auto_ptr mSecunda; osg::ref_ptr mRainNode; osg::ref_ptr mRainParticleSystem; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 679565e45..c571b1d1d 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -294,54 +294,44 @@ WeatherManager::WeatherManager(MWRender::RenderingManager* rendering, MWWorld::F //Weather Weather clear; - clear.mObstructsCelestialBodies = false; setFallbackWeather(clear,"clear"); Weather cloudy; - cloudy.mObstructsCelestialBodies = false; setFallbackWeather(cloudy,"cloudy"); Weather foggy; - foggy.mObstructsCelestialBodies = false; setFallbackWeather(foggy,"foggy"); Weather thunderstorm; thunderstorm.mAmbientLoopSoundID = "rain heavy"; thunderstorm.mRainEffect = "meshes\\raindrop.nif"; - thunderstorm.mObstructsCelestialBodies = true; setFallbackWeather(thunderstorm,"thunderstorm"); Weather rain; rain.mAmbientLoopSoundID = "rain"; rain.mRainEffect = "meshes\\raindrop.nif"; - rain.mObstructsCelestialBodies = true; setFallbackWeather(rain,"rain"); Weather overcast; - overcast.mObstructsCelestialBodies = true; setFallbackWeather(overcast,"overcast"); Weather ashstorm; ashstorm.mAmbientLoopSoundID = "ashstorm"; ashstorm.mParticleEffect = "meshes\\ashcloud.nif"; - ashstorm.mObstructsCelestialBodies = true; setFallbackWeather(ashstorm,"ashstorm"); Weather blight; blight.mAmbientLoopSoundID = "blight"; blight.mParticleEffect = "meshes\\blightcloud.nif"; - blight.mObstructsCelestialBodies = true; setFallbackWeather(blight,"blight"); Weather snow; snow.mParticleEffect = "meshes\\snow.nif"; - snow.mObstructsCelestialBodies = true; setFallbackWeather(snow, "snow"); Weather blizzard; blizzard.mAmbientLoopSoundID = "BM Blizzard"; blizzard.mParticleEffect = "meshes\\blizzard.nif"; - blizzard.mObstructsCelestialBodies = true; setFallbackWeather(blizzard,"blizzard"); } @@ -475,8 +465,6 @@ void WeatherManager::setResult(const std::string& weatherType) mResult.mNightFade = factor; } } - - mResult.mCelestialBodyTransparency = current.mObstructsCelestialBodies ? 0.0f : 1.0f; } void WeatherManager::transition(float factor) @@ -530,16 +518,6 @@ void WeatherManager::transition(float factor) mResult.mEffectFade = mResult.mAmbientSoundVolume; mResult.mAmbientLoopSoundID = other.mAmbientLoopSoundID; } - - const Weather& currentSettings = mWeatherSettings[mCurrentWeather]; - const Weather& nextSettings = mWeatherSettings[mNextWeather]; - - if(currentSettings.mObstructsCelestialBodies && !nextSettings.mObstructsCelestialBodies) - mResult.mCelestialBodyTransparency = factor; - else if(!currentSettings.mObstructsCelestialBodies && nextSettings.mObstructsCelestialBodies) - mResult.mCelestialBodyTransparency = 1 - factor; - else - mResult.mCelestialBodyTransparency = current.mCelestialBodyTransparency; } void WeatherManager::update(float duration, bool paused) diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index 1bc3bc357..d5ac6d801 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -80,7 +80,8 @@ namespace MWWorld // Multiplier for clouds transparency float mCloudsMaximumPercent; - // Value between 0 and 1, defines the strength of the sun glare effect + // Value between 0 and 1, defines the strength of the sun glare effect. + // Also appears to modify how visible the sun, moons, and stars are for various weather effects. float mGlareView; // Sound effect @@ -106,9 +107,6 @@ namespace MWWorld // Note: For Weather Blight, there is a "Disease Chance" (=0.1) setting. But according to MWSFD this feature // is broken in the vanilla game and was disabled. - - // Some weather patterns will obstruct the moons, sun, and stars. - bool mObstructsCelestialBodies; }; class MoonModel From 56b7196beaeb3c1ec8712605fa9d2ca9266f467a Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 7 Aug 2015 15:34:01 +0200 Subject: [PATCH 5/5] Remove incorrect implementation of "Clouds Maximum Percent" weather setting --- apps/openmw/mwrender/sky.cpp | 12 ++++++------ apps/openmw/mwrender/sky.hpp | 3 --- apps/openmw/mwworld/weather.cpp | 3 --- apps/openmw/mwworld/weather.hpp | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 788848cc4..138365ae4 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -605,7 +605,6 @@ SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneMana , mClouds() , mNextClouds() , mCloudBlendFactor(0.0f) - , mCloudOpacity(0.0f) , mCloudSpeed(0.0f) , mStarsOpacity(0.0f) , mRemainingTransitionTime(0.0f) @@ -666,12 +665,15 @@ void SkyManager::create() ModVertexAlphaVisitor modClouds(1); mCloudMesh->accept(modClouds); mCloudUpdater = new CloudUpdater; + mCloudUpdater->setOpacity(1.f); mCloudMesh->addUpdateCallback(mCloudUpdater); mCloudMesh2 = mSceneManager->createInstance("meshes/sky_clouds_01.nif", mCloudNode); mCloudMesh2->accept(modClouds); mCloudUpdater2 = new CloudUpdater; + mCloudUpdater2->setOpacity(0.f); mCloudMesh2->addUpdateCallback(mCloudUpdater2); + mCloudMesh2->setNodeMask(0); osg::ref_ptr depth = new osg::Depth; depth->setWriteMask(false); @@ -1060,14 +1062,12 @@ void SkyManager::setWeather(const WeatherResult& weather) osg::Texture::REPEAT, osg::Texture::REPEAT)); } - if (mCloudBlendFactor != weather.mCloudBlendFactor - || mCloudOpacity != weather.mCloudOpacity) + if (mCloudBlendFactor != weather.mCloudBlendFactor) { mCloudBlendFactor = weather.mCloudBlendFactor; - mCloudOpacity = weather.mCloudOpacity; - mCloudUpdater->setOpacity(mCloudOpacity * (1.f-mCloudBlendFactor)); - mCloudUpdater2->setOpacity(mCloudOpacity * mCloudBlendFactor); + mCloudUpdater->setOpacity((1.f-mCloudBlendFactor)); + mCloudUpdater2->setOpacity(mCloudBlendFactor); mCloudMesh2->setNodeMask(mCloudBlendFactor > 0.f ? ~0 : 0); } diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index 4b1acadc3..3855136a9 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -58,8 +58,6 @@ namespace MWRender float mCloudSpeed; - float mCloudOpacity; - float mGlareView; bool mNight; // use night skybox @@ -204,7 +202,6 @@ namespace MWRender std::string mClouds; std::string mNextClouds; float mCloudBlendFactor; - float mCloudOpacity; float mCloudSpeed; float mStarsOpacity; osg::Vec4f mCloudColour; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index c571b1d1d..8d78b969e 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -374,7 +374,6 @@ void WeatherManager::setResult(const std::string& weatherType) mResult.mCloudTexture = current.mCloudTexture; mResult.mCloudBlendFactor = 0; - mResult.mCloudOpacity = current.mCloudsMaximumPercent; mResult.mWindSpeed = current.mWindSpeed; mResult.mCloudSpeed = current.mCloudSpeed; mResult.mGlareView = current.mGlareView; @@ -478,7 +477,6 @@ void WeatherManager::transition(float factor) mResult.mNextCloudTexture = other.mCloudTexture; mResult.mCloudBlendFactor = factor; - mResult.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity, factor); mResult.mFogColor = lerp(current.mFogColor, other.mFogColor, factor); mResult.mSunColor = lerp(current.mSunColor, other.mSunColor, factor); mResult.mSkyColor = lerp(current.mSkyColor, other.mSkyColor, factor); @@ -488,7 +486,6 @@ void WeatherManager::transition(float factor) mResult.mFogDepth = lerp(current.mFogDepth, other.mFogDepth, factor); mResult.mWindSpeed = lerp(current.mWindSpeed, other.mWindSpeed, factor); mResult.mCloudSpeed = lerp(current.mCloudSpeed, other.mCloudSpeed, factor); - mResult.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity, factor); mResult.mGlareView = lerp(current.mGlareView, other.mGlareView, factor); mResult.mNightFade = lerp(current.mNightFade, other.mNightFade, factor); diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index d5ac6d801..7f4858bc8 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -77,7 +77,7 @@ namespace MWWorld // Cloud animation speed multiplier float mCloudSpeed; - // Multiplier for clouds transparency + // TODO: What is this supposed to do? float mCloudsMaximumPercent; // Value between 0 and 1, defines the strength of the sun glare effect.