From 5a7f2a4f1f2fb03d9f72fc0134b00648ec02ffde Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 2 Jun 2015 17:02:56 +0200 Subject: [PATCH] Restore light attenuation settings --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwrender/animation.cpp | 28 +++++++++++++++++++++------ components/sceneutil/lightmanager.cpp | 24 +++++++++++++++++++++++ components/sceneutil/lightmanager.hpp | 3 +++ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 015d0db9a..bb71cb6c9 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -23,7 +23,7 @@ add_openmw_dir (mwrender actors objects renderingmanager animation rotatecontroller sky npcanimation vismask creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation bulletdebugdraw globalmap characterpreview camera localmap water -# occlusionquery shadows ripplesimulation refraction terrainstorage +# occlusionquery shadows ripplesimulation terrainstorage ) add_openmw_dir (mwinput diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 2279375c2..9fe9dd451 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -31,6 +31,8 @@ #include "../mwbase/world.hpp" #include "../mwworld/esmstore.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/fallback.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwmechanics/character.hpp" // FIXME: for MWMechanics::Priority @@ -1000,14 +1002,28 @@ namespace MWRender osg::Light* light = new osg::Light; lightSource->setLight(light); - float realRadius = esmLight->mData.mRadius; + const MWWorld::Fallback* fallback = MWBase::Environment::get().getWorld()->getFallback(); - lightSource->setRadius(realRadius); - light->setLinearAttenuation(10.f/(esmLight->mData.mRadius*2.f)); - //light->setLinearAttenuation(0.05); - light->setConstantAttenuation(0.f); + float radius = esmLight->mData.mRadius; + lightSource->setRadius(radius); - light->setDiffuse(SceneUtil::colourFromRGB(esmLight->mData.mColor)); + static bool outQuadInLin = fallback->getFallbackBool("LightAttenuation_OutQuadInLin"); + static bool useQuadratic = fallback->getFallbackBool("LightAttenuation_UseQuadratic"); + static float quadraticValue = fallback->getFallbackFloat("LightAttenuation_QuadraticValue"); + static float quadraticRadiusMult = fallback->getFallbackFloat("LightAttenuation_QuadraticRadiusMult"); + static bool useLinear = fallback->getFallbackBool("LightAttenuation_UseLinear"); + static float linearRadiusMult = fallback->getFallbackFloat("LightAttenuation_LinearRadiusMult"); + static float linearValue = fallback->getFallbackFloat("LightAttenuation_LinearValue"); + + bool exterior = mPtr.isInCell() && mPtr.getCell()->getCell()->isExterior(); + + SceneUtil::configureLight(light, radius, exterior, outQuadInLin, useQuadratic, quadraticValue, + quadraticRadiusMult, useLinear, linearRadiusMult, linearValue); + + osg::Vec4f diffuse = SceneUtil::colourFromRGB(esmLight->mData.mColor); + if (esmLight->mData.mFlags & ESM::Light::Negative) + diffuse *= -1; + light->setDiffuse(diffuse); light->setAmbient(osg::Vec4f(0,0,0,1)); light->setSpecular(osg::Vec4f(0,0,0,0)); diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index e53a55bf3..6040f9536 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -325,4 +325,28 @@ namespace SceneUtil traverse(node, nv); } + void configureLight(osg::Light *light, float radius, bool isExterior, bool outQuadInLin, bool useQuadratic, + float quadraticValue, float quadraticRadiusMult, bool useLinear, float linearRadiusMult, float linearValue) + { + bool quadratic = useQuadratic && (!outQuadInLin || isExterior); + + float quadraticAttenuation = 0; + float linearAttenuation = 0; + if (quadratic) + { + float r = radius * quadraticRadiusMult; + quadraticAttenuation = quadraticValue / std::pow(r, 2); + } + if (useLinear) + { + float r = radius * linearRadiusMult; + linearAttenuation = linearValue / r; + } + + light->setLinearAttenuation(linearAttenuation); + light->setQuadraticAttenuation(quadraticAttenuation); + light->setConstantAttenuation(0.f); + + } + } diff --git a/components/sceneutil/lightmanager.hpp b/components/sceneutil/lightmanager.hpp index dd0c2d3e6..d5aecdbb6 100644 --- a/components/sceneutil/lightmanager.hpp +++ b/components/sceneutil/lightmanager.hpp @@ -124,6 +124,9 @@ namespace SceneUtil LightManager* mLightManager; }; + /// @brief Configures a light's attenuation according to vanilla Morrowind attenuation settings. + void configureLight(osg::Light* light, float radius, bool isExterior, bool outQuadInLin, bool useQuadratic, float quadraticValue, + float quadraticRadiusMult, bool useLinear, float linearRadiusMult, float linearValue); }