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
This commit is contained in:
parent
a24452af01
commit
86888fa461
1
.todo
1
.todo
@ -4,7 +4,6 @@ FART To-Do List
|
|||||||
High Priority:
|
High Priority:
|
||||||
- Add distribution infrastructure
|
- Add distribution infrastructure
|
||||||
- Multi-threading
|
- Multi-threading
|
||||||
- Attenuate color passing through a transparent object by obj. color
|
|
||||||
|
|
||||||
Medium Priority:
|
Medium Priority:
|
||||||
- Shape definitions / reusability
|
- Shape definitions / reusability
|
||||||
|
@ -263,10 +263,12 @@ Color Scene::computePhong(const refptr<Material> material,
|
|||||||
directionToLight.reflect(surfaceNormal);
|
directionToLight.reflect(surfaceNormal);
|
||||||
|
|
||||||
Ray surfaceToLight(surfacePoint, directionToLight);
|
Ray surfaceToLight(surfacePoint, directionToLight);
|
||||||
double light_contribution =
|
Color light_contribution =
|
||||||
calculateLightContribution(surfaceToLight.shift(0.0001), *it);
|
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 */
|
/* calculate the diffuse term */
|
||||||
double diffuse_coef = directionToLight % surfaceNormal;
|
double diffuse_coef = directionToLight % surfaceNormal;
|
||||||
@ -301,10 +303,10 @@ Color Scene::computePhong(const refptr<Material> material,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Scene::calculateLightContribution(const Ray & toLight,
|
Color Scene::calculateLightContribution(const Ray & toLight,
|
||||||
refptr<Light> light)
|
refptr<Light> 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_to_light = toLight.getOrigin().dist_to(light->getPosition());
|
||||||
double dist_so_far = 0.0;
|
double dist_so_far = 0.0;
|
||||||
|
|
||||||
@ -323,8 +325,11 @@ double Scene::calculateLightContribution(const Ray & toLight,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
contrib *= hit.shape->getMaterial()->getTransparency();
|
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;
|
break;
|
||||||
|
|
||||||
dist_so_far += offset;
|
dist_so_far += offset;
|
||||||
|
@ -42,8 +42,8 @@ class Scene
|
|||||||
const Ray & viewRay,
|
const Ray & viewRay,
|
||||||
const Vector & surfacePoint,
|
const Vector & surfacePoint,
|
||||||
const Vector & surfaceNormal);
|
const Vector & surfaceNormal);
|
||||||
double calculateLightContribution(const Ray & toLight,
|
Color calculateLightContribution(const Ray & toLight,
|
||||||
refptr<Light> light);
|
refptr<Light> light);
|
||||||
|
|
||||||
/* In Scene-load.cc */
|
/* In Scene-load.cc */
|
||||||
void load(const char * filename);
|
void load(const char * filename);
|
||||||
|
@ -79,6 +79,14 @@ Color & Color::operator*=(double scale)
|
|||||||
return *this;
|
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)
|
Color operator+(const Color & c1, const Color & c2)
|
||||||
{
|
{
|
||||||
return Color(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b);
|
return Color(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b);
|
||||||
|
@ -22,6 +22,7 @@ class Color
|
|||||||
Color & operator+=(const Color & other);
|
Color & operator+=(const Color & other);
|
||||||
Color & operator-=(const Color & other);
|
Color & operator-=(const Color & other);
|
||||||
Color & operator*=(double scale);
|
Color & operator*=(double scale);
|
||||||
|
Color & operator*=(const Color & other);
|
||||||
|
|
||||||
static const Color black;
|
static const Color black;
|
||||||
static const Color white;
|
static const Color white;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user