mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
Restore light attenuation settings
This commit is contained in:
parent
01944c33f5
commit
5a7f2a4f1f
4 changed files with 50 additions and 7 deletions
|
@ -23,7 +23,7 @@ add_openmw_dir (mwrender
|
||||||
actors objects renderingmanager animation rotatecontroller sky npcanimation vismask
|
actors objects renderingmanager animation rotatecontroller sky npcanimation vismask
|
||||||
creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation
|
creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation
|
||||||
bulletdebugdraw globalmap characterpreview camera localmap water
|
bulletdebugdraw globalmap characterpreview camera localmap water
|
||||||
# occlusionquery shadows ripplesimulation refraction terrainstorage
|
# occlusionquery shadows ripplesimulation terrainstorage
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwinput
|
add_openmw_dir (mwinput
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
#include "../mwworld/fallback.hpp"
|
||||||
|
#include "../mwworld/cellstore.hpp"
|
||||||
|
|
||||||
#include "../mwmechanics/character.hpp" // FIXME: for MWMechanics::Priority
|
#include "../mwmechanics/character.hpp" // FIXME: for MWMechanics::Priority
|
||||||
|
|
||||||
|
@ -1000,14 +1002,28 @@ namespace MWRender
|
||||||
osg::Light* light = new osg::Light;
|
osg::Light* light = new osg::Light;
|
||||||
lightSource->setLight(light);
|
lightSource->setLight(light);
|
||||||
|
|
||||||
float realRadius = esmLight->mData.mRadius;
|
const MWWorld::Fallback* fallback = MWBase::Environment::get().getWorld()->getFallback();
|
||||||
|
|
||||||
lightSource->setRadius(realRadius);
|
float radius = esmLight->mData.mRadius;
|
||||||
light->setLinearAttenuation(10.f/(esmLight->mData.mRadius*2.f));
|
lightSource->setRadius(radius);
|
||||||
//light->setLinearAttenuation(0.05);
|
|
||||||
light->setConstantAttenuation(0.f);
|
|
||||||
|
|
||||||
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->setAmbient(osg::Vec4f(0,0,0,1));
|
||||||
light->setSpecular(osg::Vec4f(0,0,0,0));
|
light->setSpecular(osg::Vec4f(0,0,0,0));
|
||||||
|
|
||||||
|
|
|
@ -325,4 +325,28 @@ namespace SceneUtil
|
||||||
traverse(node, nv);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,9 @@ namespace SceneUtil
|
||||||
LightManager* mLightManager;
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue