|
|
@ -5,6 +5,7 @@
|
|
|
|
#include <osg/ComputeBoundsVisitor>
|
|
|
|
#include <osg/ComputeBoundsVisitor>
|
|
|
|
|
|
|
|
|
|
|
|
#include <components/esm/loadligh.hpp>
|
|
|
|
#include <components/esm/loadligh.hpp>
|
|
|
|
|
|
|
|
#include <components/fallback/fallback.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#include "lightmanager.hpp"
|
|
|
|
#include "lightmanager.hpp"
|
|
|
|
#include "lightcontroller.hpp"
|
|
|
|
#include "lightcontroller.hpp"
|
|
|
@ -15,32 +16,43 @@
|
|
|
|
namespace SceneUtil
|
|
|
|
namespace SceneUtil
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
void configureLight(osg::Light *light, float radius, bool isExterior, bool outQuadInLin, bool useQuadratic,
|
|
|
|
void configureLight(osg::Light *light, float radius, bool isExterior)
|
|
|
|
float quadraticValue, float quadraticRadiusMult, bool useLinear, float linearRadiusMult, float linearValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool quadratic = useQuadratic && (!outQuadInLin || isExterior);
|
|
|
|
float quadraticAttenuation = 0.f;
|
|
|
|
|
|
|
|
float linearAttenuation = 0.f;
|
|
|
|
|
|
|
|
float constantAttenuation = 0.f;
|
|
|
|
|
|
|
|
|
|
|
|
float quadraticAttenuation = 0;
|
|
|
|
const bool useConstant = Fallback::Map::getBool("LightAttenuation_UseConstant");
|
|
|
|
float linearAttenuation = 0;
|
|
|
|
if (useConstant)
|
|
|
|
if (quadratic)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
float r = radius * quadraticRadiusMult;
|
|
|
|
constantAttenuation = Fallback::Map::getFloat("LightAttenuation_ConstantValue");
|
|
|
|
quadraticAttenuation = quadraticValue / std::pow(r, 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const bool useLinear = Fallback::Map::getBool("LightAttenuation_UseLinear");
|
|
|
|
if (useLinear)
|
|
|
|
if (useLinear)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
const float linearValue = Fallback::Map::getFloat("LightAttenuation_LinearValue");
|
|
|
|
|
|
|
|
const float linearRadiusMult = Fallback::Map::getFloat("LightAttenuation_LinearRadiusMult");
|
|
|
|
float r = radius * linearRadiusMult;
|
|
|
|
float r = radius * linearRadiusMult;
|
|
|
|
linearAttenuation = linearValue / r;
|
|
|
|
if (r) linearAttenuation = linearValue / r;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const bool useQuadratic = Fallback::Map::getBool("LightAttenuation_UseQuadratic");
|
|
|
|
|
|
|
|
const bool outQuadInLin = Fallback::Map::getBool("LightAttenuation_OutQuadInLin");
|
|
|
|
|
|
|
|
if (useQuadratic && (!outQuadInLin || isExterior))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const float quadraticValue = Fallback::Map::getFloat("LightAttenuation_QuadraticValue");
|
|
|
|
|
|
|
|
const float quadraticRadiusMult = Fallback::Map::getFloat("LightAttenuation_QuadraticRadiusMult");
|
|
|
|
|
|
|
|
float r = radius * quadraticRadiusMult;
|
|
|
|
|
|
|
|
if (r) quadraticAttenuation = quadraticValue / std::pow(r, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
light->setConstantAttenuation(constantAttenuation);
|
|
|
|
light->setLinearAttenuation(linearAttenuation);
|
|
|
|
light->setLinearAttenuation(linearAttenuation);
|
|
|
|
light->setQuadraticAttenuation(quadraticAttenuation);
|
|
|
|
light->setQuadraticAttenuation(quadraticAttenuation);
|
|
|
|
light->setConstantAttenuation(0.f);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void addLight (osg::Group* node, const ESM::Light* esmLight, unsigned int partsysMask, unsigned int lightMask, bool isExterior, bool outQuadInLin, bool useQuadratic,
|
|
|
|
void addLight (osg::Group* node, const ESM::Light* esmLight, unsigned int partsysMask, unsigned int lightMask, bool isExterior)
|
|
|
|
float quadraticValue, float quadraticRadiusMult, bool useLinear, float linearRadiusMult,
|
|
|
|
|
|
|
|
float linearValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SceneUtil::FindByNameVisitor visitor("AttachLight");
|
|
|
|
SceneUtil::FindByNameVisitor visitor("AttachLight");
|
|
|
|
node->accept(visitor);
|
|
|
|
node->accept(visitor);
|
|
|
@ -67,13 +79,11 @@ namespace SceneUtil
|
|
|
|
attachTo = trans;
|
|
|
|
attachTo = trans;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<LightSource> lightSource = createLightSource(esmLight, lightMask, isExterior, outQuadInLin, useQuadratic, quadraticValue,
|
|
|
|
osg::ref_ptr<LightSource> lightSource = createLightSource(esmLight, lightMask, isExterior);
|
|
|
|
quadraticRadiusMult, useLinear, linearRadiusMult, linearValue);
|
|
|
|
|
|
|
|
attachTo->addChild(lightSource);
|
|
|
|
attachTo->addChild(lightSource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<LightSource> createLightSource(const ESM::Light* esmLight, unsigned int lightMask, bool isExterior, bool outQuadInLin, bool useQuadratic, float quadraticValue,
|
|
|
|
osg::ref_ptr<LightSource> createLightSource(const ESM::Light* esmLight, unsigned int lightMask, bool isExterior, const osg::Vec4f& ambient)
|
|
|
|
float quadraticRadiusMult, bool useLinear, float linearRadiusMult, float linearValue, const osg::Vec4f& ambient)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
osg::ref_ptr<SceneUtil::LightSource> lightSource (new SceneUtil::LightSource);
|
|
|
|
osg::ref_ptr<SceneUtil::LightSource> lightSource (new SceneUtil::LightSource);
|
|
|
|
osg::ref_ptr<osg::Light> light (new osg::Light);
|
|
|
|
osg::ref_ptr<osg::Light> light (new osg::Light);
|
|
|
@ -82,8 +92,7 @@ namespace SceneUtil
|
|
|
|
float radius = esmLight->mData.mRadius;
|
|
|
|
float radius = esmLight->mData.mRadius;
|
|
|
|
lightSource->setRadius(radius);
|
|
|
|
lightSource->setRadius(radius);
|
|
|
|
|
|
|
|
|
|
|
|
configureLight(light, radius, isExterior, outQuadInLin, useQuadratic, quadraticValue,
|
|
|
|
configureLight(light, radius, isExterior);
|
|
|
|
quadraticRadiusMult, useLinear, linearRadiusMult, linearValue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::Vec4f diffuse = SceneUtil::colourFromRGB(esmLight->mData.mColor);
|
|
|
|
osg::Vec4f diffuse = SceneUtil::colourFromRGB(esmLight->mData.mColor);
|
|
|
|
if (esmLight->mData.mFlags & ESM::Light::Negative)
|
|
|
|
if (esmLight->mData.mFlags & ESM::Light::Negative)
|
|
|
|