X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/49b259147e3ece2ed0aa4ad72b686970031cfc46..0db0dec898ba811c966267d4cb12dad33a1e3545:/PointLight.cxx diff --git a/PointLight.cxx b/PointLight.cxx index 1ce5f0b..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,17 +12,32 @@ 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) { - - 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& @@ -37,4 +52,8 @@ PointLight::intensity() const return m_intensity; } - +bool +PointLight::IsArea() +{ + return false; +}