|
|
|
@ -192,19 +192,43 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, f
|
|
|
|
|
Ogre::Light *light = mRenderer.getScene()->createLight();
|
|
|
|
|
light->setDiffuseColour (r, g, b);
|
|
|
|
|
|
|
|
|
|
ESMS::LiveCellRef<ESM::Light, MWWorld::RefData> *ref =
|
|
|
|
|
ptr.get<ESM::Light>();
|
|
|
|
|
|
|
|
|
|
LightInfo info;
|
|
|
|
|
info.name = light->getName();
|
|
|
|
|
info.radius = radius;
|
|
|
|
|
info.colour = Ogre::ColourValue(r, g, b);
|
|
|
|
|
mLights.push_back(info);
|
|
|
|
|
|
|
|
|
|
if (ref->base->data.flags & ESM::Light::Negative)
|
|
|
|
|
info.colour *= -1;
|
|
|
|
|
|
|
|
|
|
info.interior = (ptr.getCell()->cell->data.flags & ESM::Cell::Interior);
|
|
|
|
|
|
|
|
|
|
if (ref->base->data.flags & ESM::Light::Flicker)
|
|
|
|
|
info.type = LT_Flicker;
|
|
|
|
|
else if (ref->base->data.flags & ESM::Light::FlickerSlow)
|
|
|
|
|
info.type = LT_FlickerSlow;
|
|
|
|
|
else if (ref->base->data.flags & ESM::Light::Pulse)
|
|
|
|
|
info.type = LT_Pulse;
|
|
|
|
|
else if (ref->base->data.flags & ESM::Light::PulseSlow)
|
|
|
|
|
info.type = LT_PulseSlow;
|
|
|
|
|
else
|
|
|
|
|
info.type = LT_Normal;
|
|
|
|
|
|
|
|
|
|
// random starting phase for the animation
|
|
|
|
|
info.time = Ogre::Math::RangeRandom(0, 2 * M_PI);
|
|
|
|
|
|
|
|
|
|
// adjust the lights depending if we're in an interior or exterior cell
|
|
|
|
|
// quadratic means the light intensity falls off quite fast, resulting in a
|
|
|
|
|
// dark, atmospheric environment (perfect for exteriors)
|
|
|
|
|
// for interiors, we want more "warm" lights, so use linear attenuation.
|
|
|
|
|
bool quadratic = false;
|
|
|
|
|
if (!lightOutQuadInLin)
|
|
|
|
|
quadratic = lightQuadratic;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
quadratic = !mInterior;
|
|
|
|
|
quadratic = !info.interior;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!quadratic)
|
|
|
|
@ -221,6 +245,7 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, f
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insert->attachObject(light);
|
|
|
|
|
mLights.push_back(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Objects::deleteObject (const MWWorld::Ptr& ptr)
|
|
|
|
@ -329,17 +354,8 @@ void Objects::disableLights()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Objects::setInterior(const bool interior)
|
|
|
|
|
{
|
|
|
|
|
mInterior = interior;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Objects::update(const float dt)
|
|
|
|
|
{
|
|
|
|
|
// adjust the lights depending if we're in an interior or exterior cell
|
|
|
|
|
// quadratic means the light intensity falls off quite fast, resulting in a
|
|
|
|
|
// dark, atmospheric environment (perfect for exteriors)
|
|
|
|
|
// for interiors, we want more "warm" lights, so use linear attenuation.
|
|
|
|
|
std::vector<LightInfo>::iterator it = mLights.begin();
|
|
|
|
|
while (it != mLights.end())
|
|
|
|
|
{
|
|
|
|
@ -347,26 +363,77 @@ void Objects::update(const float dt)
|
|
|
|
|
{
|
|
|
|
|
Ogre::Light* light = mMwRoot->getCreator()->getLight(it->name);
|
|
|
|
|
|
|
|
|
|
bool quadratic = false;
|
|
|
|
|
if (!lightOutQuadInLin)
|
|
|
|
|
quadratic = lightQuadratic;
|
|
|
|
|
else
|
|
|
|
|
// Light animation (pulse & flicker)
|
|
|
|
|
it->time += dt;
|
|
|
|
|
const float phase = std::fmod(it->time, (32 * 2 * M_PI)) * 20;
|
|
|
|
|
float pulseConstant;
|
|
|
|
|
|
|
|
|
|
// These formulas are just guesswork, but they work pretty well
|
|
|
|
|
if (it->type == LT_Normal)
|
|
|
|
|
{
|
|
|
|
|
quadratic = !mInterior;
|
|
|
|
|
// Less than 1/255 light modifier for a constant light:
|
|
|
|
|
pulseConstant = (const float)(1.0 + sin(phase) / 255.0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!quadratic)
|
|
|
|
|
else if (it->type == LT_Flicker)
|
|
|
|
|
{
|
|
|
|
|
float radius = it->radius * lightLinearRadiusMult;
|
|
|
|
|
float attenuation = lightLinearValue / it->radius;
|
|
|
|
|
light->setAttenuation(radius*10, 0, attenuation, 0);
|
|
|
|
|
// Let's do a 50% -> 100% sine wave pulse over 1 second:
|
|
|
|
|
// This is 75% +/- 25%
|
|
|
|
|
pulseConstant = (const float)(0.75 + sin(phase) * 0.25);
|
|
|
|
|
|
|
|
|
|
// Then add a 25% flicker variation:
|
|
|
|
|
it->resetTime -= dt;
|
|
|
|
|
if (it->resetTime < 0)
|
|
|
|
|
{
|
|
|
|
|
it->flickerVariation = (rand() % 1000) / 1000 * 0.25;
|
|
|
|
|
it->resetTime = 0.5;
|
|
|
|
|
}
|
|
|
|
|
if (it->resetTime > 0.25)
|
|
|
|
|
{
|
|
|
|
|
pulseConstant = (pulseConstant+it->flickerVariation) * (1-it->resetTime * 2.0f) + pulseConstant * it->resetTime * 2.0f;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pulseConstant = (pulseConstant+it->flickerVariation) * (it->resetTime * 2.0f) + pulseConstant * (1-it->resetTime * 2.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
else if (it->type == LT_FlickerSlow)
|
|
|
|
|
{
|
|
|
|
|
// Let's do a 50% -> 100% sine wave pulse over 1 second:
|
|
|
|
|
// This is 75% +/- 25%
|
|
|
|
|
pulseConstant = (const float)(0.75 + sin(phase / 4.0) * 0.25);
|
|
|
|
|
|
|
|
|
|
// Then add a 25% flicker variation:
|
|
|
|
|
it->resetTime -= dt;
|
|
|
|
|
if (it->resetTime < 0)
|
|
|
|
|
{
|
|
|
|
|
it->flickerVariation = (rand() % 1000) / 1000 * 0.25;
|
|
|
|
|
it->resetTime = 0.5;
|
|
|
|
|
}
|
|
|
|
|
if (it->resetTime > 0.5)
|
|
|
|
|
{
|
|
|
|
|
pulseConstant = (pulseConstant+it->flickerVariation) * (1-it->resetTime) + pulseConstant * it->resetTime;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pulseConstant = (pulseConstant+it->flickerVariation) * (it->resetTime) + pulseConstant * (1-it->resetTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (it->type == LT_Pulse)
|
|
|
|
|
{
|
|
|
|
|
float radius = it->radius * lightQuadraticRadiusMult;
|
|
|
|
|
float attenuation = lightQuadraticValue / pow(it->radius, 2);
|
|
|
|
|
light->setAttenuation(radius*10, 0, 0, attenuation);
|
|
|
|
|
// Let's do a 75% -> 125% sine wave pulse over 1 second:
|
|
|
|
|
// This is 100% +/- 25%
|
|
|
|
|
pulseConstant = (const float)(1.0 + sin(phase) * 0.25);
|
|
|
|
|
}
|
|
|
|
|
else if (it->type == LT_PulseSlow)
|
|
|
|
|
{
|
|
|
|
|
// Let's do a 75% -> 125% sine wave pulse over 1 second:
|
|
|
|
|
// This is 100% +/- 25%
|
|
|
|
|
pulseConstant = (const float)(1.0 + sin(phase / 4.0) * 0.25);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
assert(0 && "Invalid light type");
|
|
|
|
|
|
|
|
|
|
light->setDiffuseColour( it->colour * pulseConstant );
|
|
|
|
|
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|