Merge remote-tracking branch 'origin/master'

This commit is contained in:
Marc Zinnschlag 2015-08-08 10:42:02 +02:00
commit b74a14211f
4 changed files with 230 additions and 210 deletions

View file

@ -8,7 +8,6 @@
#include <osg/Depth> #include <osg/Depth>
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/Material> #include <osg/Material>
#include <osg/PositionAttitudeTransform>
#include <osg/TexEnvCombine> #include <osg/TexEnvCombine>
#include <osg/TexMat> #include <osg/TexMat>
#include <osg/Version> #include <osg/Version>
@ -322,11 +321,11 @@ private:
int mMeshType; int mMeshType;
}; };
/// A base class for the sun and moons.
class CelestialBody class CelestialBody
{ {
public: public:
CelestialBody(osg::Group* parentNode, Resource::SceneManager* sceneManager, float scaleFactor = 1.f, int numUvSets=1) CelestialBody(osg::Group* parentNode, float scaleFactor, int numUvSets)
: mSceneManager(sceneManager)
{ {
mGeode = new osg::Geode; mGeode = new osg::Geode;
osg::ref_ptr<osg::Geometry> geom = createTexturedQuad(numUvSets); osg::ref_ptr<osg::Geometry> geom = createTexturedQuad(numUvSets);
@ -338,15 +337,9 @@ public:
parentNode->addChild(mTransform); parentNode->addChild(mTransform);
} }
void setDirection(const osg::Vec3f& direction) virtual ~CelestialBody() {}
{
osg::Vec3f normalizedDirection = direction / direction.length();
mTransform->setPosition(normalizedDirection*1000.f);
osg::Quat quat; virtual void adjustTransparency(const float ratio) = 0;
quat.makeRotate(osg::Vec3f(0,0,1), normalizedDirection);
mTransform->setAttitude(quat);
}
void setVisible(bool visible) void setVisible(bool visible)
{ {
@ -354,24 +347,74 @@ public:
} }
protected: protected:
static const float mDistance;
osg::ref_ptr<osg::PositionAttitudeTransform> mTransform; osg::ref_ptr<osg::PositionAttitudeTransform> mTransform;
osg::ref_ptr<osg::Geode> mGeode; osg::ref_ptr<osg::Geode> mGeode;
Resource::SceneManager* mSceneManager;
}; };
const float CelestialBody::mDistance = 1000.0f;
class Sun : public CelestialBody class Sun : public CelestialBody
{ {
public: public:
Sun(osg::Group* parentNode, Resource::SceneManager* sceneManager) Sun(osg::Group* parentNode, Resource::TextureManager& textureManager)
: CelestialBody(parentNode, sceneManager, 1.f, 1) : CelestialBody(parentNode, 1.0f, 1)
, mUpdater(new Updater(textureManager))
{ {
osg::ref_ptr<osg::Texture2D> tex = mSceneManager->getTextureManager()->getTexture2D("textures/tx_sun_05.dds", mGeode->addUpdateCallback(mUpdater);
osg::Texture::CLAMP, osg::Texture::CLAMP);
mTransform->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON);
mTransform->getOrCreateStateSet()->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON);
} }
~Sun()
{
mGeode->removeUpdateCallback(mUpdater);
}
virtual void adjustTransparency(const float ratio)
{
mUpdater->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:
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<osg::Texture2D> 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<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
mat->setDiffuse(osg::Material::FRONT_AND_BACK, mColor);
}
};
osg::ref_ptr<Updater> mUpdater;
}; };
class Moon : public CelestialBody class Moon : public CelestialBody
@ -383,16 +426,26 @@ public:
Type_Secunda Type_Secunda
}; };
Moon(osg::Group* parentNode, Resource::SceneManager* sceneManager, float scaleFactor, Type type) Moon(osg::Group* parentNode, Resource::TextureManager& textureManager, float scaleFactor, Type type)
: CelestialBody(parentNode, sceneManager, scaleFactor, 2) : CelestialBody(parentNode, scaleFactor, 2)
, mType(type) , mType(type)
, mPhase(MoonState::Phase_Unspecified) , mPhase(MoonState::Phase_Unspecified)
, mUpdater(new Updater(textureManager))
{ {
mUpdater = new MoonUpdater;
mGeode->addUpdateCallback(mUpdater);
setPhase(MoonState::Phase_Full); setPhase(MoonState::Phase_Full);
setVisible(true); setVisible(true);
mGeode->addUpdateCallback(mUpdater);
}
~Moon()
{
mGeode->removeUpdateCallback(mUpdater);
}
virtual void adjustTransparency(const float ratio)
{
mUpdater->mTransparency *= ratio;
} }
void setState(const MoonState& state) void setState(const MoonState& state)
@ -404,73 +457,64 @@ public:
osg::Quat rotZ(radsZ, osg::Vec3f(0.0f, 0.0f, 1.0f)); 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); 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 // 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. // 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); mTransform->setAttitude(attX * rotZ);
setPhase(state.mPhase); setPhase(state.mPhase);
setTransparency(state.mMoonAlpha); mUpdater->mTransparency = state.mMoonAlpha;
setShadowBlend(state.mShadowBlend); mUpdater->mShadowBlend = state.mShadowBlend;
} }
void setTextures(const std::string& phaseTex, const std::string& circleTex) void setAtmosphereColor(const osg::Vec4f& color)
{ {
osg::ref_ptr<osg::Texture2D> phaseTexPtr = mSceneManager->getTextureManager()->getTexture2D(phaseTex, mUpdater->mAtmosphereColor = color;
osg::Texture::CLAMP, osg::Texture::CLAMP);
osg::ref_ptr<osg::Texture2D> circleTexPtr = mSceneManager->getTextureManager()->getTexture2D(circleTex,
osg::Texture::CLAMP, osg::Texture::CLAMP);
mUpdater->setTextures(phaseTexPtr, circleTexPtr);
} }
void setPhase(const MoonState::Phase& phase) void setColor(const osg::Vec4f& color)
{ {
if (mPhase == phase) mUpdater->mMoonColor = color;
return;
mPhase = phase;
std::string textureName = "textures/tx_";
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";
textureName += ".dds";
if (mType == Moon::Type_Secunda)
setTextures(textureName, "textures/tx_mooncircle_full_s.dds");
else
setTextures(textureName, "textures/tx_mooncircle_full_m.dds");
} }
void setType(const Type& type) unsigned int getPhaseInt() const
{ {
mType = type; 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;
} }
class MoonUpdater : public SceneUtil::StateSetUpdater private:
struct Updater : public SceneUtil::StateSetUpdater
{ {
public: Resource::TextureManager& mTextureManager;
MoonUpdater() osg::ref_ptr<osg::Texture2D> mPhaseTex;
: mTransparency(1.0f) osg::ref_ptr<osg::Texture2D> 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) , mShadowBlend(1.0f)
, mMoonColor(1,1,1,1) , mAtmosphereColor(1.0f, 1.0f, 1.0f, 1.0f)
, mMoonColor(1.0f, 1.0f, 1.0f, 1.0f)
{ {
} }
virtual void setDefaults(osg::StateSet *stateset) virtual void setDefaults(osg::StateSet* stateset)
{ {
stateset->setTextureAttributeAndModes(0, mPhaseTex, osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(0, mPhaseTex, osg::StateAttribute::ON);
osg::ref_ptr<osg::TexEnvCombine> texEnv = new osg::TexEnvCombine; osg::ref_ptr<osg::TexEnvCombine> texEnv = new osg::TexEnvCombine;
@ -494,7 +538,7 @@ public:
stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
} }
virtual void apply(osg::StateSet *stateset, osg::NodeVisitor*) virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*)
{ {
osg::TexEnvCombine* texEnv = static_cast<osg::TexEnvCombine*>(stateset->getTextureAttribute(0, osg::StateAttribute::TEXENV)); osg::TexEnvCombine* texEnv = static_cast<osg::TexEnvCombine*>(stateset->getTextureAttribute(0, osg::StateAttribute::TEXENV));
texEnv->setConstantColor(mMoonColor * mShadowBlend); texEnv->setConstantColor(mMoonColor * mShadowBlend);
@ -503,80 +547,49 @@ public:
texEnv2->setConstantColor(osg::Vec4f(mAtmosphereColor.x(), mAtmosphereColor.y(), mAtmosphereColor.z(), mTransparency)); texEnv2->setConstantColor(osg::Vec4f(mAtmosphereColor.x(), mAtmosphereColor.y(), mAtmosphereColor.z(), mTransparency));
} }
void setTransparency(const float ratio) void setTextures(const std::string& phaseTex, const std::string& circleTex)
{ {
mTransparency = ratio; mPhaseTex = mTextureManager.getTexture2D(phaseTex, osg::Texture::CLAMP, osg::Texture::CLAMP);
} mCircleTex = mTextureManager.getTexture2D(circleTex, osg::Texture::CLAMP, osg::Texture::CLAMP);
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<osg::Texture2D> phaseTex, osg::ref_ptr<osg::Texture2D> circleTex)
{
mPhaseTex = phaseTex;
mCircleTex = circleTex;
reset(); reset();
} }
private:
float mTransparency;
float mShadowBlend;
osg::Vec4f mAtmosphereColor;
osg::Vec4f mMoonColor;
osg::ref_ptr<osg::Texture2D> mPhaseTex;
osg::ref_ptr<osg::Texture2D> 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; Type mType;
MoonState::Phase mPhase; MoonState::Phase mPhase;
osg::ref_ptr<MoonUpdater> mUpdater; osg::ref_ptr<Updater> mUpdater;
void setPhase(const MoonState::Phase& phase)
{
if(mPhase == phase)
return;
mPhase = phase;
std::string textureName = "textures/tx_";
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";
textureName += ".dds";
if (mType == Moon::Type_Secunda)
mUpdater->setTextures(textureName, "textures/tx_mooncircle_full_s.dds");
else
mUpdater->setTextures(textureName, "textures/tx_mooncircle_full_m.dds");
}
}; };
SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager) SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager)
@ -592,7 +605,6 @@ SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneMana
, mClouds() , mClouds()
, mNextClouds() , mNextClouds()
, mCloudBlendFactor(0.0f) , mCloudBlendFactor(0.0f)
, mCloudOpacity(0.0f)
, mCloudSpeed(0.0f) , mCloudSpeed(0.0f)
, mStarsOpacity(0.0f) , mStarsOpacity(0.0f)
, mRemainingTransitionTime(0.0f) , mRemainingTransitionTime(0.0f)
@ -641,11 +653,11 @@ void SkyManager::create()
mAtmosphereNightUpdater = new AtmosphereNightUpdater(mSceneManager->getTextureManager()); mAtmosphereNightUpdater = new AtmosphereNightUpdater(mSceneManager->getTextureManager());
atmosphereNight->addUpdateCallback(mAtmosphereNightUpdater); atmosphereNight->addUpdateCallback(mAtmosphereNightUpdater);
mSun.reset(new Sun(mRootNode, mSceneManager)); mSun.reset(new Sun(mRootNode, *mSceneManager->getTextureManager()));
const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback(); const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback();
mMasser.reset(new Moon(mRootNode, mSceneManager, fallback->getFallbackFloat("Moons_Masser_Size")/125, Moon::Type_Masser)); mMasser.reset(new Moon(mRootNode, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Masser_Size")/125, Moon::Type_Masser));
mSecunda.reset(new Moon(mRootNode, mSceneManager, fallback->getFallbackFloat("Moons_Secunda_Size")/125, Moon::Type_Secunda)); mSecunda.reset(new Moon(mRootNode, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Secunda_Size")/125, Moon::Type_Secunda));
mCloudNode = new osg::PositionAttitudeTransform; mCloudNode = new osg::PositionAttitudeTransform;
mRootNode->addChild(mCloudNode); mRootNode->addChild(mCloudNode);
@ -653,12 +665,15 @@ void SkyManager::create()
ModVertexAlphaVisitor modClouds(1); ModVertexAlphaVisitor modClouds(1);
mCloudMesh->accept(modClouds); mCloudMesh->accept(modClouds);
mCloudUpdater = new CloudUpdater; mCloudUpdater = new CloudUpdater;
mCloudUpdater->setOpacity(1.f);
mCloudMesh->addUpdateCallback(mCloudUpdater); mCloudMesh->addUpdateCallback(mCloudUpdater);
mCloudMesh2 = mSceneManager->createInstance("meshes/sky_clouds_01.nif", mCloudNode); mCloudMesh2 = mSceneManager->createInstance("meshes/sky_clouds_01.nif", mCloudNode);
mCloudMesh2->accept(modClouds); mCloudMesh2->accept(modClouds);
mCloudUpdater2 = new CloudUpdater; mCloudUpdater2 = new CloudUpdater;
mCloudUpdater2->setOpacity(0.f);
mCloudMesh2->addUpdateCallback(mCloudUpdater2); mCloudMesh2->addUpdateCallback(mCloudUpdater2);
mCloudMesh2->setNodeMask(0);
osg::ref_ptr<osg::Depth> depth = new osg::Depth; osg::ref_ptr<osg::Depth> depth = new osg::Depth;
depth->setWriteMask(false); depth->setWriteMask(false);
@ -970,7 +985,7 @@ void SkyManager::updateRainParameters()
} }
} }
void SkyManager::setWeather(const MWWorld::WeatherResult& weather) void SkyManager::setWeather(const WeatherResult& weather)
{ {
if (!mCreated) return; if (!mCreated) return;
@ -1047,14 +1062,12 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
osg::Texture::REPEAT, osg::Texture::REPEAT)); osg::Texture::REPEAT, osg::Texture::REPEAT));
} }
if (mCloudBlendFactor != weather.mCloudBlendFactor if (mCloudBlendFactor != weather.mCloudBlendFactor)
|| mCloudOpacity != weather.mCloudOpacity)
{ {
mCloudBlendFactor = weather.mCloudBlendFactor; mCloudBlendFactor = weather.mCloudBlendFactor;
mCloudOpacity = weather.mCloudOpacity;
mCloudUpdater->setOpacity(mCloudOpacity * (1.f-mCloudBlendFactor)); mCloudUpdater->setOpacity((1.f-mCloudBlendFactor));
mCloudUpdater2->setOpacity(mCloudOpacity * mCloudBlendFactor); mCloudUpdater2->setOpacity(mCloudBlendFactor);
mCloudMesh2->setNodeMask(mCloudBlendFactor > 0.f ? ~0 : 0); mCloudMesh2->setNodeMask(mCloudBlendFactor > 0.f ? ~0 : 0);
} }
@ -1087,9 +1100,14 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
mCloudSpeed = weather.mCloudSpeed; mCloudSpeed = weather.mCloudSpeed;
if (weather.mNight && mStarsOpacity != weather.mNightFade) mMasser->adjustTransparency(weather.mGlareView);
mSecunda->adjustTransparency(weather.mGlareView);
mSun->adjustTransparency(weather.mGlareView);
float nextStarsOpacity = weather.mNightFade * weather.mGlareView;
if(weather.mNight && mStarsOpacity != nextStarsOpacity)
{ {
mStarsOpacity = weather.mNightFade; mStarsOpacity = nextStarsOpacity;
mAtmosphereNightUpdater->setFade(mStarsOpacity); mAtmosphereNightUpdater->setFade(mStarsOpacity);
} }

View file

@ -1,9 +1,12 @@
#ifndef OPENMW_MWRENDER_SKY_H #ifndef OPENMW_MWRENDER_SKY_H
#define OPENMW_MWRENDER_SKY_H #define OPENMW_MWRENDER_SKY_H
#include <osg/ref_ptr> #include <string>
#include <memory>
#include "../mwworld/weather.hpp" #include <osg/ref_ptr>
#include <osg/Vec4f>
#include <osg/PositionAttitudeTransform>
namespace osg namespace osg
{ {
@ -33,6 +36,46 @@ namespace MWRender
class RainFader; class RainFader;
class AlphaFader; 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 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;
};
struct MoonState struct MoonState
{ {
enum Phase enum Phase
@ -82,7 +125,7 @@ namespace MWRender
void setMoonColour (bool red); void setMoonColour (bool red);
///< change Secunda colour to red ///< change Secunda colour to red
void setWeather(const MWWorld::WeatherResult& weather); void setWeather(const WeatherResult& weather);
void sunEnable(); void sunEnable();
@ -159,7 +202,6 @@ namespace MWRender
std::string mClouds; std::string mClouds;
std::string mNextClouds; std::string mNextClouds;
float mCloudBlendFactor; float mCloudBlendFactor;
float mCloudOpacity;
float mCloudSpeed; float mCloudSpeed;
float mStarsOpacity; float mStarsOpacity;
osg::Vec4f mCloudColour; osg::Vec4f mCloudColour;

View file

@ -61,7 +61,7 @@ MWRender::MoonState MoonModel::calculateState(unsigned int daysPassed, float gam
{ {
rotationFromHorizon, rotationFromHorizon,
mAxisOffset, // Reverse engineered from Morrowind's scene graph rotation matrices. mAxisOffset, // Reverse engineered from Morrowind's scene graph rotation matrices.
static_cast<MWRender::MoonState::Phase>(phase(daysPassed)), static_cast<MWRender::MoonState::Phase>(phase(daysPassed, gameHour)),
shadowBlend(rotationFromHorizon), shadowBlend(rotationFromHorizon),
earlyMoonShadowAlpha(rotationFromHorizon) * hourlyAlpha(gameHour) earlyMoonShadowAlpha(rotationFromHorizon) * hourlyAlpha(gameHour)
}; };
@ -130,12 +130,17 @@ inline float MoonModel::rotation(float hours) const
return 15.0f * mSpeed * hours; 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. // 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 // 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). // 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 inline float MoonModel::shadowBlend(float angle) const
@ -369,7 +374,6 @@ void WeatherManager::setResult(const std::string& weatherType)
mResult.mCloudTexture = current.mCloudTexture; mResult.mCloudTexture = current.mCloudTexture;
mResult.mCloudBlendFactor = 0; mResult.mCloudBlendFactor = 0;
mResult.mCloudOpacity = current.mCloudsMaximumPercent;
mResult.mWindSpeed = current.mWindSpeed; mResult.mWindSpeed = current.mWindSpeed;
mResult.mCloudSpeed = current.mCloudSpeed; mResult.mCloudSpeed = current.mCloudSpeed;
mResult.mGlareView = current.mGlareView; mResult.mGlareView = current.mGlareView;
@ -465,15 +469,14 @@ void WeatherManager::setResult(const std::string& weatherType)
void WeatherManager::transition(float factor) void WeatherManager::transition(float factor)
{ {
setResult(mCurrentWeather); setResult(mCurrentWeather);
const WeatherResult current = mResult; const MWRender::WeatherResult current = mResult;
setResult(mNextWeather); setResult(mNextWeather);
const WeatherResult other = mResult; const MWRender::WeatherResult other = mResult;
mResult.mCloudTexture = current.mCloudTexture; mResult.mCloudTexture = current.mCloudTexture;
mResult.mNextCloudTexture = other.mCloudTexture; mResult.mNextCloudTexture = other.mCloudTexture;
mResult.mCloudBlendFactor = factor; mResult.mCloudBlendFactor = factor;
mResult.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity, factor);
mResult.mFogColor = lerp(current.mFogColor, other.mFogColor, factor); mResult.mFogColor = lerp(current.mFogColor, other.mFogColor, factor);
mResult.mSunColor = lerp(current.mSunColor, other.mSunColor, factor); mResult.mSunColor = lerp(current.mSunColor, other.mSunColor, factor);
mResult.mSkyColor = lerp(current.mSkyColor, other.mSkyColor, factor); mResult.mSkyColor = lerp(current.mSkyColor, other.mSkyColor, factor);
@ -483,7 +486,6 @@ void WeatherManager::transition(float factor)
mResult.mFogDepth = lerp(current.mFogDepth, other.mFogDepth, factor); mResult.mFogDepth = lerp(current.mFogDepth, other.mFogDepth, factor);
mResult.mWindSpeed = lerp(current.mWindSpeed, other.mWindSpeed, factor); mResult.mWindSpeed = lerp(current.mWindSpeed, other.mWindSpeed, factor);
mResult.mCloudSpeed = lerp(current.mCloudSpeed, other.mCloudSpeed, 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.mGlareView = lerp(current.mGlareView, other.mGlareView, factor);
mResult.mNightFade = lerp(current.mNightFade, other.mNightFade, factor); mResult.mNightFade = lerp(current.mNightFade, other.mNightFade, factor);

View file

@ -9,6 +9,8 @@
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwrender/sky.hpp"
namespace ESM namespace ESM
{ {
struct Region; struct Region;
@ -19,7 +21,6 @@ namespace ESM
namespace MWRender namespace MWRender
{ {
class RenderingManager; class RenderingManager;
struct MoonState;
} }
namespace Loading namespace Loading
@ -31,50 +32,6 @@ namespace MWWorld
{ {
class Fallback; 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) /// Defines a single weather setting (according to INI)
struct Weather struct Weather
{ {
@ -120,10 +77,11 @@ namespace MWWorld
// Cloud animation speed multiplier // Cloud animation speed multiplier
float mCloudSpeed; float mCloudSpeed;
// Multiplier for clouds transparency // TODO: What is this supposed to do?
float mCloudsMaximumPercent; 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; float mGlareView;
// Sound effect // Sound effect
@ -173,7 +131,7 @@ namespace MWWorld
float angle(unsigned int daysPassed, float gameHour) const; float angle(unsigned int daysPassed, float gameHour) const;
float moonRiseHour(unsigned int daysPassed) const; float moonRiseHour(unsigned int daysPassed) const;
float rotation(float hours) 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 shadowBlend(float angle) const;
float hourlyAlpha(float gameHour) const; float hourlyAlpha(float gameHour) const;
float earlyMoonShadowAlpha(float angle) const; float earlyMoonShadowAlpha(float angle) const;
@ -268,7 +226,7 @@ namespace MWWorld
void setWeather(const std::string& weatherType, bool instant=false); void setWeather(const std::string& weatherType, bool instant=false);
std::string nextWeather(const ESM::Region* region) const; std::string nextWeather(const ESM::Region* region) const;
WeatherResult mResult; MWRender::WeatherResult mResult;
typedef std::map<std::string,std::vector<char> > RegionModMap; typedef std::map<std::string,std::vector<char> > RegionModMap;
RegionModMap mRegionMods; RegionModMap mRegionMods;