1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 11:53:51 +00:00

set sky colors according to time of day

This commit is contained in:
scrawl 2012-02-23 19:49:56 +01:00
parent ce98397565
commit a5720e9a4f
4 changed files with 99 additions and 4 deletions

View file

@ -478,4 +478,17 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
mCloudOpacity = weather.mCloudOpacity; mCloudOpacity = weather.mCloudOpacity;
} }
if (mCloudColour != weather.mSunColor)
{
mCloudMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(weather.mAmbientColor);
mCloudColour = weather.mSunColor;
}
if (mSkyColour != weather.mSkyColor)
{
mAtmosphereMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(weather.mSkyColor);
mSkyColour = weather.mSkyColor;
}
mViewport->setBackgroundColour(weather.mFogColor);
} }

View file

@ -145,6 +145,9 @@ namespace MWRender
float mCloudBlendFactor; float mCloudBlendFactor;
float mCloudOpacity; float mCloudOpacity;
Ogre::ColourValue mCloudColour;
Ogre::ColourValue mSkyColour;
float mRemainingTransitionTime; float mRemainingTransitionTime;
void ModVertexAlpha(Ogre::Entity* ent, unsigned int meshType); void ModVertexAlpha(Ogre::Entity* ent, unsigned int meshType);

View file

@ -8,7 +8,7 @@ using namespace MWWorld;
#define TRANSITION_TIME 10 #define TRANSITION_TIME 10
WeatherManager::WeatherManager(MWRender::RenderingManager* rendering) : WeatherManager::WeatherManager(MWRender::RenderingManager* rendering) :
mCurrentWeather("clear") mHour(0), mCurrentWeather("clear")
{ {
mRendering = rendering; mRendering = rendering;
@ -81,7 +81,9 @@ WeatherManager::WeatherManager(MWRender::RenderingManager* rendering) :
*/ */
setWeather("clear", true); setWeather("clear", true);
setWeather("cloudy", false);
// Test transition
//setWeather("cloudy", false);
} }
void WeatherManager::setWeather(const String& weather, bool instant) void WeatherManager::setWeather(const String& weather, bool instant)
@ -106,7 +108,53 @@ WeatherResult WeatherManager::getResult(const String& weather)
result.mCloudTexture = current.mCloudTexture; result.mCloudTexture = current.mCloudTexture;
result.mCloudBlendFactor = 0; result.mCloudBlendFactor = 0;
result.mCloudOpacity = current.mCloudsMaximumPercent; result.mCloudOpacity = current.mCloudsMaximumPercent;
/// \todo result.mWindSpeed = current.mWindSpeed;
result.mCloudSpeed = current.mCloudSpeed;
result.mGlareView = current.mGlareView;
result.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
const float dayTime = 13.f;
const float nightTime = 1.f;
float factor;
/// \todo interpolation
// night
if (mHour <= (mGlobals.mSunriseTime-mGlobals.mSunriseDuration) || mHour >= (mGlobals.mSunsetTime+mGlobals.mSunsetDuration))
{
result.mFogColor = current.mFogNightColor;
result.mAmbientColor = current.mAmbientNightColor;
result.mSunColor = current.mSunNightColor;
result.mSkyColor = current.mSkyNightColor;
}
// sunrise
else if (mHour >= (mGlobals.mSunriseTime-mGlobals.mSunriseDuration) && mHour <= (mGlobals.mSunriseTime+mGlobals.mSunriseDuration))
{
result.mFogColor = current.mFogSunriseColor;
result.mAmbientColor = current.mAmbientSunriseColor;
result.mSunColor = current.mSunSunriseColor;
result.mSkyColor = current.mSkySunriseColor;
}
// day
else if (mHour >= (mGlobals.mSunriseTime+mGlobals.mSunriseDuration) && mHour <= (mGlobals.mSunsetTime-mGlobals.mSunsetDuration))
{
result.mFogColor = current.mFogDayColor;
result.mAmbientColor = current.mAmbientDayColor;
result.mSunColor = current.mSunDayColor;
result.mSkyColor = current.mSkyDayColor;
}
// sunset
else if (mHour >= (mGlobals.mSunsetTime-mGlobals.mSunsetDuration) && mHour <= (mGlobals.mSunsetTime+mGlobals.mSunsetDuration))
{
result.mFogColor = current.mFogSunsetColor;
result.mAmbientColor = current.mAmbientSunsetColor;
result.mSunColor = current.mSunSunsetColor;
result.mSkyColor = current.mSkySunsetColor;
}
return result; return result;
} }
@ -124,8 +172,25 @@ WeatherResult WeatherManager::transition(float factor)
#define lerp(x, y) (x * (1-factor) + y * factor) #define lerp(x, y) (x * (1-factor) + y * factor)
result.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity); result.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity);
result.mFogColor = lerp(current.mFogColor, other.mFogColor);
result.mSunColor = lerp(current.mSunColor, other.mSunColor);
result.mSkyColor = lerp(current.mSkyColor, other.mSkyColor);
/// \todo result.mAmbientColor = lerp(current.mAmbientColor, other.mAmbientColor);
result.mSunDiscColor = lerp(current.mSunDiscColor, other.mSunDiscColor);
result.mFogDepth = lerp(current.mFogDepth, other.mFogDepth);
result.mWindSpeed = lerp(current.mWindSpeed, other.mWindSpeed);
result.mCloudSpeed = lerp(current.mCloudSpeed, other.mCloudSpeed);
result.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity);
result.mGlareView = lerp(current.mGlareView, other.mGlareView);
// sound change behaviour:
// if 'other' has a new sound, switch to it after 1/2 of the transition length
if (other.mAmbientLoopSoundID != "")
result.mAmbientLoopSoundID = factor>0.5 ? other.mAmbientLoopSoundID : current.mAmbientLoopSoundID;
// if 'current' has a sound and 'other' does not have a sound, turn off the sound immediately
else if (current.mAmbientLoopSoundID != "")
result.mAmbientLoopSoundID = "";
return result; return result;
} }
@ -154,6 +219,16 @@ void WeatherManager::update(float duration)
void WeatherManager::setHour(const float hour) void WeatherManager::setHour(const float hour)
{ {
// accelerate a bit for testing
/*
mHour += 0.001;
if (mHour >= 24.f) mHour = 0.f;
#include <iostream>
std::cout << "hour " << mHour << std::endl;
/**/
mHour = hour; mHour = hour;
} }

View file

@ -90,6 +90,8 @@ namespace MWWorld
Ogre::ColourValue mAmbientColor; Ogre::ColourValue mAmbientColor;
Ogre::ColourValue mSkyColor;
Ogre::ColourValue mSunColor; Ogre::ColourValue mSunColor;
Ogre::ColourValue mSunDiscColor; Ogre::ColourValue mSunDiscColor;
@ -204,6 +206,8 @@ namespace MWWorld
std::map<Ogre::String, Weather> mWeatherSettings; std::map<Ogre::String, Weather> mWeatherSettings;
WeatherGlobals mGlobals;
Ogre::String mCurrentWeather; Ogre::String mCurrentWeather;
Ogre::String mNextWeather; Ogre::String mNextWeather;