forked from mirror/openmw-tes3mp
Implement SunDiscSunsetColor, fade the sun during sunrise & sunset
This commit is contained in:
parent
f7e5a40143
commit
385f4f729c
4 changed files with 48 additions and 19 deletions
|
@ -402,6 +402,13 @@ public:
|
||||||
destroySunGlare();
|
destroySunGlare();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setColor(const osg::Vec4f& color)
|
||||||
|
{
|
||||||
|
mUpdater->mColor.r() = color.r();
|
||||||
|
mUpdater->mColor.g() = color.g();
|
||||||
|
mUpdater->mColor.b() = color.b();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void adjustTransparency(const float ratio)
|
virtual void adjustTransparency(const float ratio)
|
||||||
{
|
{
|
||||||
mUpdater->mColor.a() = ratio;
|
mUpdater->mColor.a() = ratio;
|
||||||
|
@ -576,7 +583,7 @@ private:
|
||||||
osg::Vec4f mColor;
|
osg::Vec4f mColor;
|
||||||
|
|
||||||
Updater()
|
Updater()
|
||||||
: mColor(1.f, 1.f, 1.f, 1.0f)
|
: mColor(1.f, 1.f, 1.f, 1.f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,7 +595,8 @@ private:
|
||||||
virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*)
|
virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*)
|
||||||
{
|
{
|
||||||
osg::Material* mat = static_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
|
osg::Material* mat = static_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
|
||||||
mat->setDiffuse(osg::Material::FRONT_AND_BACK, mColor);
|
mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(0,0,0,mColor.a()));
|
||||||
|
mat->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4f(mColor.r(), mColor.g(), mColor.b(), 1));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1464,15 +1472,8 @@ void SkyManager::setWeather(const WeatherResult& weather)
|
||||||
mMasser->adjustTransparency(weather.mGlareView);
|
mMasser->adjustTransparency(weather.mGlareView);
|
||||||
mSecunda->adjustTransparency(weather.mGlareView);
|
mSecunda->adjustTransparency(weather.mGlareView);
|
||||||
|
|
||||||
/*
|
mSun->setColor(weather.mSunDiscColor);
|
||||||
float timeofday_angle = std::abs(mSun->getPosition().z/mSunGlare->getPosition().length());
|
mSun->adjustTransparency(weather.mGlareView * weather.mSunDiscColor.a());
|
||||||
float strength;
|
|
||||||
if (timeofday_angle <= 0.44)
|
|
||||||
strength = timeofday_angle/0.44f;
|
|
||||||
else
|
|
||||||
strength = 1.f;
|
|
||||||
*/
|
|
||||||
mSun->adjustTransparency(weather.mGlareView);
|
|
||||||
|
|
||||||
float nextStarsOpacity = weather.mNightFade * weather.mGlareView;
|
float nextStarsOpacity = weather.mNightFade * weather.mGlareView;
|
||||||
if(weather.mNight && mStarsOpacity != nextStarsOpacity)
|
if(weather.mNight && mStarsOpacity != nextStarsOpacity)
|
||||||
|
|
|
@ -48,8 +48,10 @@ namespace MWRender
|
||||||
|
|
||||||
osg::Vec4f mSkyColor;
|
osg::Vec4f mSkyColor;
|
||||||
|
|
||||||
|
// sun light color
|
||||||
osg::Vec4f mSunColor;
|
osg::Vec4f mSunColor;
|
||||||
|
|
||||||
|
// alpha is the sun transparency
|
||||||
osg::Vec4f mSunDiscColor;
|
osg::Vec4f mSunDiscColor;
|
||||||
|
|
||||||
float mFogDepth;
|
float mFogDepth;
|
||||||
|
|
|
@ -432,6 +432,7 @@ WeatherManager::WeatherManager(MWRender::RenderingManager& rendering, const MWWo
|
||||||
, mSunsetTime(fallback.getFallbackFloat("Weather_Sunset_Time"))
|
, mSunsetTime(fallback.getFallbackFloat("Weather_Sunset_Time"))
|
||||||
, mSunriseDuration(fallback.getFallbackFloat("Weather_Sunrise_Duration"))
|
, mSunriseDuration(fallback.getFallbackFloat("Weather_Sunrise_Duration"))
|
||||||
, mSunsetDuration(fallback.getFallbackFloat("Weather_Sunset_Duration"))
|
, mSunsetDuration(fallback.getFallbackFloat("Weather_Sunset_Duration"))
|
||||||
|
, mSunPreSunsetTime(fallback.getFallbackFloat("Weather_Sun_Pre-Sunset_Time"))
|
||||||
, mNightStart(mSunsetTime + mSunsetDuration)
|
, mNightStart(mSunsetTime + mSunsetDuration)
|
||||||
, mNightEnd(mSunriseTime - 0.5f)
|
, mNightEnd(mSunriseTime - 0.5f)
|
||||||
, mDayStart(mSunriseTime + mSunriseDuration)
|
, mDayStart(mSunriseTime + mSunriseDuration)
|
||||||
|
@ -966,7 +967,6 @@ inline void WeatherManager::calculateResult(const int weatherID, const float gam
|
||||||
mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
|
mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
|
||||||
mResult.mAmbientSoundVolume = 1.f;
|
mResult.mAmbientSoundVolume = 1.f;
|
||||||
mResult.mEffectFade = 1.f;
|
mResult.mEffectFade = 1.f;
|
||||||
mResult.mSunColor = current.mSunDiscSunsetColor;
|
|
||||||
|
|
||||||
mResult.mIsStorm = current.mIsStorm;
|
mResult.mIsStorm = current.mIsStorm;
|
||||||
|
|
||||||
|
@ -980,6 +980,7 @@ inline void WeatherManager::calculateResult(const int weatherID, const float gam
|
||||||
|
|
||||||
mResult.mFogDepth = mResult.mNight ? current.mLandFogNightDepth : current.mLandFogDayDepth;
|
mResult.mFogDepth = mResult.mNight ? current.mLandFogNightDepth : current.mLandFogDayDepth;
|
||||||
|
|
||||||
|
// TODO: use pre/post sunset/sunrise time values in [Weather] section
|
||||||
// night
|
// night
|
||||||
if (gameHour <= mNightEnd || gameHour >= mNightStart + 1)
|
if (gameHour <= mNightEnd || gameHour >= mNightStart + 1)
|
||||||
{
|
{
|
||||||
|
@ -1050,6 +1051,36 @@ inline void WeatherManager::calculateResult(const int weatherID, const float gam
|
||||||
mResult.mNightFade = factor;
|
mResult.mNightFade = factor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gameHour >= mSunsetTime - mSunPreSunsetTime)
|
||||||
|
{
|
||||||
|
float factor = (gameHour - (mSunsetTime - mSunPreSunsetTime)) / mSunPreSunsetTime;
|
||||||
|
factor = std::min(1.f, factor);
|
||||||
|
mResult.mSunDiscColor = lerp(osg::Vec4f(1,1,1,1), current.mSunDiscSunsetColor, factor);
|
||||||
|
// The SunDiscSunsetColor in the INI isn't exactly the resulting color on screen, most likely because
|
||||||
|
// MW applied the color to the ambient term as well. After the ambient and emissive terms are added together, the fixed pipeline
|
||||||
|
// would then clamp the total lighting to (1,1,1). A noticable change in color tone can be observed when only one of the color components gets clamped.
|
||||||
|
// Unfortunately that means we can't use the INI color as is, have to replicate the above nonsense.
|
||||||
|
mResult.mSunDiscColor = mResult.mSunDiscColor + osg::componentMultiply(mResult.mSunDiscColor, mResult.mAmbientColor);
|
||||||
|
for (int i=0; i<3; ++i)
|
||||||
|
mResult.mSunDiscColor[i] = std::min(1.f, mResult.mSunDiscColor[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mResult.mSunDiscColor = osg::Vec4f(1,1,1,1);
|
||||||
|
|
||||||
|
if (gameHour >= mSunsetTime)
|
||||||
|
{
|
||||||
|
float fade = std::min(1.f, (gameHour - mSunsetTime) / 2.f);
|
||||||
|
fade = fade*fade;
|
||||||
|
mResult.mSunDiscColor.a() = 1.f - fade;
|
||||||
|
}
|
||||||
|
else if (gameHour >= mSunriseTime && gameHour <= mSunriseTime + 1)
|
||||||
|
{
|
||||||
|
mResult.mSunDiscColor.a() = gameHour - mSunriseTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mResult.mSunDiscColor.a() = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void WeatherManager::calculateTransitionResult(const float factor, const float gameHour)
|
inline void WeatherManager::calculateTransitionResult(const float factor, const float gameHour)
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace MWWorld
|
||||||
float mLandFogDayDepth;
|
float mLandFogDayDepth;
|
||||||
float mLandFogNightDepth;
|
float mLandFogNightDepth;
|
||||||
|
|
||||||
// Color modulation for the sun itself during sunset (not completely sure)
|
// Color modulation for the sun itself during sunset
|
||||||
osg::Vec4f mSunDiscSunsetColor;
|
osg::Vec4f mSunDiscSunsetColor;
|
||||||
|
|
||||||
// Used by scripts to animate signs, etc based on the wind (GetWindSpeed)
|
// Used by scripts to animate signs, etc based on the wind (GetWindSpeed)
|
||||||
|
@ -242,12 +242,7 @@ namespace MWWorld
|
||||||
float mSunsetTime;
|
float mSunsetTime;
|
||||||
float mSunriseDuration;
|
float mSunriseDuration;
|
||||||
float mSunsetDuration;
|
float mSunsetDuration;
|
||||||
// Some useful values
|
float mSunPreSunsetTime;
|
||||||
/* TODO: Use pre-sunrise_time, pre-sunset_time,
|
|
||||||
* post-sunrise_time, and post-sunset_time to better
|
|
||||||
* describe sunrise/sunset time.
|
|
||||||
* These values are fallbacks attached to weather.
|
|
||||||
*/
|
|
||||||
float mNightStart;
|
float mNightStart;
|
||||||
float mNightEnd;
|
float mNightEnd;
|
||||||
float mDayStart;
|
float mDayStart;
|
||||||
|
|
Loading…
Reference in a new issue