#include "PointLight.hxx"
PointLight::PointLight(Scene* scene, const Vec3f& pos, const Vec3f& intensity)
- : Light(scene),
+ : Light(scene),
m_pos(pos),
m_intensity(intensity)
{
}
PointLight::PointLight()
- : Light(0),
+ : Light(0),
m_pos(Vec3f()),
m_intensity(Vec3f())
{
}
bool
-PointLight::Illuminate(Ray& ray, Vec3f& intensity)
+PointLight::Illuminate(Ray& shadow_ray, Vec3f& intensity)
{
- float dist = ((ray.origin() + ray.direction() * ray.t()) - m_pos).norm();
-
- float c1 = 1, c2 = 0.5, c3 = 0;
- float in = 1 / (c1 + c2*dist + c3*dist*dist);
-
- intensity = Vec3f(in, in, in);
- return false;
+ // distance to light source
+ Vec3f dir = m_pos-shadow_ray.origin();
+ float r = dir.norm()-Epsilon;
+ float falloff = 1.0f/(r*r);
+
+
+ intensity = m_intensity * falloff;
+
+ // modify ray for shadow computation
+ shadow_ray.setHit(0);
+ // for shadow calculation
+ shadow_ray.setT(r);
+ // set direction to light source
+ dir.normalize();
+ shadow_ray.setDir(dir);
+
+ return true;
}
const Vec3f&
return m_intensity;
}
-
+bool
+PointLight::IsArea()
+{
+ return false;
+}