From 86888fa46169075b4ee1662f46c6ff219c1d50fe Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 12 Mar 2009 02:30:28 +0000 Subject: [PATCH] changed Scene::calculateLightContribution() to return a Color instead of a double and take into account the color of any semi-transparent objects that are passed through en route to the light source... this leads to shadow colors tainted by the color of the objects through which the light is travelling git-svn-id: svn://anubis/fart/trunk@211 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- .todo | 1 - main/Scene.cc | 15 ++++++++++----- main/Scene.h | 4 ++-- util/Color.cc | 8 ++++++++ util/Color.h | 1 + 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.todo b/.todo index e277410..bddca63 100644 --- a/.todo +++ b/.todo @@ -4,7 +4,6 @@ FART To-Do List High Priority: - Add distribution infrastructure - Multi-threading - - Attenuate color passing through a transparent object by obj. color Medium Priority: - Shape definitions / reusability diff --git a/main/Scene.cc b/main/Scene.cc index eef9559..5bd9a50 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -263,10 +263,12 @@ Color Scene::computePhong(const refptr material, directionToLight.reflect(surfaceNormal); Ray surfaceToLight(surfacePoint, directionToLight); - double light_contribution = + Color light_contribution = calculateLightContribution(surfaceToLight.shift(0.0001), *it); - if (light_contribution > 0.0) + if ( light_contribution.r > 0.0 + || light_contribution.g > 0.0 + || light_contribution.b > 0.0 ) { /* calculate the diffuse term */ double diffuse_coef = directionToLight % surfaceNormal; @@ -301,10 +303,10 @@ Color Scene::computePhong(const refptr material, return result; } -double Scene::calculateLightContribution(const Ray & toLight, +Color Scene::calculateLightContribution(const Ray & toLight, refptr light) { - double contrib = 1.0; + Color contrib(1.0, 1.0, 1.0); double dist_to_light = toLight.getOrigin().dist_to(light->getPosition()); double dist_so_far = 0.0; @@ -323,8 +325,11 @@ double Scene::calculateLightContribution(const Ray & toLight, break; contrib *= hit.shape->getMaterial()->getTransparency(); + contrib *= hit.shape->getMaterial()->getDiffuseColor(); - if ( contrib < SCENE_FACTOR_THRESHOLD ) + if ( contrib.r < SCENE_FACTOR_THRESHOLD + && contrib.g < SCENE_FACTOR_THRESHOLD + && contrib.b < SCENE_FACTOR_THRESHOLD ) break; dist_so_far += offset; diff --git a/main/Scene.h b/main/Scene.h index 9133a58..9eeeb06 100644 --- a/main/Scene.h +++ b/main/Scene.h @@ -42,8 +42,8 @@ class Scene const Ray & viewRay, const Vector & surfacePoint, const Vector & surfaceNormal); - double calculateLightContribution(const Ray & toLight, - refptr light); + Color calculateLightContribution(const Ray & toLight, + refptr light); /* In Scene-load.cc */ void load(const char * filename); diff --git a/util/Color.cc b/util/Color.cc index 1649356..86b8a45 100644 --- a/util/Color.cc +++ b/util/Color.cc @@ -79,6 +79,14 @@ Color & Color::operator*=(double scale) return *this; } +Color & Color::operator*=(const Color & other) +{ + r *= other.r; + g *= other.g; + b *= other.b; + return *this; +} + Color operator+(const Color & c1, const Color & c2) { return Color(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b); diff --git a/util/Color.h b/util/Color.h index 01d19cb..e46b871 100644 --- a/util/Color.h +++ b/util/Color.h @@ -22,6 +22,7 @@ class Color Color & operator+=(const Color & other); Color & operator-=(const Color & other); Color & operator*=(double scale); + Color & operator*=(const Color & other); static const Color black; static const Color white;