From a88d56148b45a6ddb1c4cb95ab75f112550fac58 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 13 Oct 2015 16:35:31 +0200 Subject: [PATCH] Read the Sun Glare Fader ini settings --- apps/openmw/mwrender/sky.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 6f1b26733..a8aeeb930 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -724,7 +724,17 @@ private: , mTimeOfDayFade(1.f) , mGlareView(1.f) { - + const MWWorld::Fallback* fallback = MWBase::Environment::get().getWorld()->getFallback(); + mColor = fallback->getFallbackColour("Weather_Sun_Glare_Fader_Color"); + mSunGlareFaderMax = fallback->getFallbackFloat("Weather_Sun_Glare_Fader_Max"); + mSunGlareFaderAngleMax = fallback->getFallbackFloat("Weather_Sun_Glare_Fader_Angle_Max"); + + // Replicating a design flaw in MW. The color was being set on both ambient and emissive properties, which multiplies the result by two, + // then finally gets clamped by the fixed function pipeline. With the default INI settings, only the red component gets clamped, + // so the resulting color looks more orange than red. + mColor *= 2; + for (int i=0; i<3; ++i) + mColor[i] = std::min(1.f, mColor[i]); } virtual void operator ()(osg::Node* node, osg::NodeVisitor* nv) @@ -734,12 +744,10 @@ private: float angleRadians = getAngleToSunInRadians(cv->getCurrentCamera()); float visibleRatio = getVisibleRatio(cv->getCurrentCamera()); - const float angleMaxRadians = osg::DegreesToRadians(30.f); // Sun Glare Fader Angle Max + const float angleMaxRadians = osg::DegreesToRadians(mSunGlareFaderAngleMax); float value = 1.f - std::min(1.f, angleRadians / angleMaxRadians); - - const float sunGlareFaderMax = 0.5f; - float fade = value * sunGlareFaderMax; + float fade = value * mSunGlareFaderMax; fade *= mTimeOfDayFade * mGlareView * visibleRatio; @@ -754,17 +762,8 @@ private: osg::ref_ptr mat (createUnlitMaterial()); - osg::Vec4f sunGlareFaderColor (222/255.f, 95/255.f, 39/255.f, 1); - - // Replicating a design flaw in MW. The color was being set on both ambient and emissive properties, which multiplies the result by two, - // then finally gets clamped by the fixed function pipeline. With the default INI settings, only the red component gets clamped, - // so the resulting color looks more orange than red. - sunGlareFaderColor *= 2; - for (int i=0; i<3; ++i) - sunGlareFaderColor[i] = std::min(1.f, sunGlareFaderColor[i]); - mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(0,0,0,fade)); - mat->setEmission(osg::Material::FRONT_AND_BACK, sunGlareFaderColor); + mat->setEmission(osg::Material::FRONT_AND_BACK, mColor); stateset->setAttributeAndModes(mat, osg::StateAttribute::ON); @@ -802,6 +801,9 @@ private: osg::ref_ptr mSunTransform; float mTimeOfDayFade; float mGlareView; + osg::Vec4f mColor; + float mSunGlareFaderMax; + float mSunGlareFaderAngleMax; }; osg::ref_ptr mUpdater;