forked from mirror/openmw-tes3mp
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b74a14211f
4 changed files with 230 additions and 210 deletions
|
@ -8,7 +8,6 @@
|
|||
#include <osg/Depth>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Material>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/TexEnvCombine>
|
||||
#include <osg/TexMat>
|
||||
#include <osg/Version>
|
||||
|
@ -322,11 +321,11 @@ private:
|
|||
int mMeshType;
|
||||
};
|
||||
|
||||
/// A base class for the sun and moons.
|
||||
class CelestialBody
|
||||
{
|
||||
public:
|
||||
CelestialBody(osg::Group* parentNode, Resource::SceneManager* sceneManager, float scaleFactor = 1.f, int numUvSets=1)
|
||||
: mSceneManager(sceneManager)
|
||||
CelestialBody(osg::Group* parentNode, float scaleFactor, int numUvSets)
|
||||
{
|
||||
mGeode = new osg::Geode;
|
||||
osg::ref_ptr<osg::Geometry> geom = createTexturedQuad(numUvSets);
|
||||
|
@ -338,15 +337,9 @@ public:
|
|||
parentNode->addChild(mTransform);
|
||||
}
|
||||
|
||||
void setDirection(const osg::Vec3f& direction)
|
||||
{
|
||||
osg::Vec3f normalizedDirection = direction / direction.length();
|
||||
mTransform->setPosition(normalizedDirection*1000.f);
|
||||
virtual ~CelestialBody() {}
|
||||
|
||||
osg::Quat quat;
|
||||
quat.makeRotate(osg::Vec3f(0,0,1), normalizedDirection);
|
||||
mTransform->setAttitude(quat);
|
||||
}
|
||||
virtual void adjustTransparency(const float ratio) = 0;
|
||||
|
||||
void setVisible(bool visible)
|
||||
{
|
||||
|
@ -354,24 +347,74 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
static const float mDistance;
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> mTransform;
|
||||
osg::ref_ptr<osg::Geode> 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)
|
||||
, mUpdater(new Updater(textureManager))
|
||||
{
|
||||
osg::ref_ptr<osg::Texture2D> tex = mSceneManager->getTextureManager()->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);
|
||||
mGeode->addUpdateCallback(mUpdater);
|
||||
}
|
||||
|
||||
~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
|
||||
|
@ -383,16 +426,26 @@ 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)
|
||||
, mType(type)
|
||||
, mPhase(MoonState::Phase_Unspecified)
|
||||
, mUpdater(new Updater(textureManager))
|
||||
{
|
||||
mUpdater = new MoonUpdater;
|
||||
mGeode->addUpdateCallback(mUpdater);
|
||||
|
||||
setPhase(MoonState::Phase_Full);
|
||||
setVisible(true);
|
||||
|
||||
mGeode->addUpdateCallback(mUpdater);
|
||||
}
|
||||
|
||||
~Moon()
|
||||
{
|
||||
mGeode->removeUpdateCallback(mUpdater);
|
||||
}
|
||||
|
||||
virtual void adjustTransparency(const float ratio)
|
||||
{
|
||||
mUpdater->mTransparency *= ratio;
|
||||
}
|
||||
|
||||
void setState(const MoonState& state)
|
||||
|
@ -404,73 +457,64 @@ 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);
|
||||
mUpdater->mTransparency = state.mMoonAlpha;
|
||||
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,
|
||||
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);
|
||||
mUpdater->mAtmosphereColor = color;
|
||||
}
|
||||
|
||||
void setPhase(const MoonState::Phase& phase)
|
||||
void setColor(const osg::Vec4f& color)
|
||||
{
|
||||
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)
|
||||
setTextures(textureName, "textures/tx_mooncircle_full_s.dds");
|
||||
else
|
||||
setTextures(textureName, "textures/tx_mooncircle_full_m.dds");
|
||||
mUpdater->mMoonColor = color;
|
||||
}
|
||||
|
||||
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:
|
||||
MoonUpdater()
|
||||
: mTransparency(1.0f)
|
||||
Resource::TextureManager& mTextureManager;
|
||||
osg::ref_ptr<osg::Texture2D> mPhaseTex;
|
||||
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)
|
||||
, 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);
|
||||
osg::ref_ptr<osg::TexEnvCombine> texEnv = new osg::TexEnvCombine;
|
||||
|
@ -494,7 +538,7 @@ public:
|
|||
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));
|
||||
texEnv->setConstantColor(mMoonColor * mShadowBlend);
|
||||
|
@ -503,80 +547,49 @@ public:
|
|||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
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)
|
||||
|
@ -592,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)
|
||||
|
@ -641,11 +653,11 @@ void SkyManager::create()
|
|||
mAtmosphereNightUpdater = new AtmosphereNightUpdater(mSceneManager->getTextureManager());
|
||||
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();
|
||||
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.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);
|
||||
|
@ -653,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<osg::Depth> depth = new osg::Depth;
|
||||
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;
|
||||
|
||||
|
@ -1047,14 +1062,12 @@ void SkyManager::setWeather(const MWWorld::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);
|
||||
}
|
||||
|
||||
|
@ -1087,9 +1100,14 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#ifndef 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
|
||||
{
|
||||
|
@ -33,6 +36,46 @@ 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 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
|
||||
{
|
||||
enum Phase
|
||||
|
@ -82,7 +125,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();
|
||||
|
||||
|
@ -159,7 +202,6 @@ namespace MWRender
|
|||
std::string mClouds;
|
||||
std::string mNextClouds;
|
||||
float mCloudBlendFactor;
|
||||
float mCloudOpacity;
|
||||
float mCloudSpeed;
|
||||
float mStarsOpacity;
|
||||
osg::Vec4f mCloudColour;
|
||||
|
|
|
@ -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<MWRender::MoonState::Phase>(phase(daysPassed)),
|
||||
static_cast<MWRender::MoonState::Phase>(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
|
||||
|
@ -369,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;
|
||||
|
@ -465,15 +469,14 @@ void WeatherManager::setResult(const std::string& weatherType)
|
|||
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;
|
||||
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);
|
||||
|
@ -483,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);
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
@ -120,10 +77,11 @@ 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
|
||||
// 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
|
||||
|
@ -173,7 +131,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 +226,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<std::string,std::vector<char> > RegionModMap;
|
||||
RegionModMap mRegionMods;
|
||||
|
|
Loading…
Reference in a new issue