X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/3396a44710415bde9509afeb02f3ec10a22c6661..68b3409314cb3fe96300a72a5f2ac04e95c7b7da:/PointLight.cxx?ds=sidebyside diff --git a/PointLight.cxx b/PointLight.cxx index 925a6b5..61e4ec8 100644 --- a/PointLight.cxx +++ b/PointLight.cxx @@ -1,7 +1,7 @@ #include "PointLight.hxx" PointLight::PointLight(Scene* scene, const Vec3f& pos, const Vec3f& intensity) - : Light(scene), + : Light(scene), m_pos(pos), m_intensity(intensity) { @@ -12,27 +12,31 @@ PointLight::~PointLight() } 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) { - Vec3f dir = (ray.origin() + ray.direction() * (ray.t()-Epsilon)) - m_pos; - float dist = dir.norm(); + // 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(); - - float c1 = 1, c2 = 0.5, c3 = 0; - //float f_att = 1 / (dist*dist); - float f_att = 1 / (c1 + c2*dist + c3*dist*dist); - - intensity = m_intensity * f_att; - - // store direction from light to hitpoint - ray.setDir(dir); + shadow_ray.setDir(dir); + return true; } @@ -48,4 +52,8 @@ PointLight::intensity() const return m_intensity; } - +bool +PointLight::IsArea() +{ + return false; +}