2013-12-08 16:56:59 +00:00
|
|
|
#include "LightStatus.h"
|
|
|
|
|
2013-12-08 19:54:34 +00:00
|
|
|
#include "LightingManager.h"
|
|
|
|
#include "Color.h"
|
|
|
|
#include "SurfaceMaterial.h"
|
|
|
|
|
2013-12-08 16:56:59 +00:00
|
|
|
LightStatus::LightStatus(LightingManager *manager, const Vector3 &location, const Vector3 &eye)
|
|
|
|
{
|
2013-12-26 18:03:19 +00:00
|
|
|
this->max_power = 0.0;
|
2013-12-08 16:56:59 +00:00
|
|
|
this->manager = manager;
|
|
|
|
this->location = location;
|
|
|
|
this->eye = eye;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LightStatus::pushComponent(LightComponent component)
|
|
|
|
{
|
2013-12-26 18:03:19 +00:00
|
|
|
double power = component.color.getPower();
|
|
|
|
if (component.altered && (power < max_power * 0.05 || power < 0.001))
|
|
|
|
{
|
|
|
|
// Exclude filtered lights that are owerpowered by a previous one
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-08 19:54:34 +00:00
|
|
|
if (manager->alterLight(component, location))
|
2013-12-08 16:56:59 +00:00
|
|
|
{
|
2013-12-26 18:03:19 +00:00
|
|
|
if (power > max_power)
|
|
|
|
{
|
|
|
|
max_power = power;
|
|
|
|
}
|
2013-12-08 19:54:34 +00:00
|
|
|
components.push_back(component);
|
2013-12-08 16:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Color LightStatus::apply(const Vector3 &normal, const SurfaceMaterial &material)
|
|
|
|
{
|
2013-12-20 16:30:27 +00:00
|
|
|
Color final(0.0, 0.0, 0.0, 0.0);
|
2013-12-08 16:56:59 +00:00
|
|
|
|
|
|
|
for (auto component: components)
|
|
|
|
{
|
2013-12-08 19:54:34 +00:00
|
|
|
final = final.add(manager->applyFinalComponent(component, eye, location, normal, material));
|
2013-12-08 16:56:59 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 19:54:34 +00:00
|
|
|
final.a = material.base.a;
|
2013-12-08 16:56:59 +00:00
|
|
|
return final;
|
|
|
|
}
|