diff --git a/main/Scene.cc b/main/Scene.cc index 705cddb..f26c89e 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -159,15 +159,12 @@ Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor) /* compute the Phong lighting for each hit */ refptr material = hit.shape->getMaterial(); - /* TODO: make sure this can be removed */ -#if 0 /* check for backfaces */ - if (ray.getDirection() % surfaceNormal > 0.0) + if (ray.getDirection() % hit.normal > 0.0) { /* if dot product is positive, this is a back-face */ - surfaceNormal = -surfaceNormal; + hit.normal = -hit.normal; } -#endif color = computePhong(material, ray, @@ -252,9 +249,6 @@ Color Scene::computePhong(const refptr material, double shininess = material->getShininess(); const Color & diffuseColor = material->getDiffuseColor(); const Color & specularColor = material->getSpecularColor(); - Vector normal = surfaceNormal; - if (normal % viewRay.getDirection() > 0.0) /* back face */ - normal = -normal; for (std::vector< refptr >::const_iterator it = m_lights.begin(); it != m_lights.end(); @@ -263,7 +257,7 @@ Color Scene::computePhong(const refptr material, Vector directionToLight = (*it)->getPosition() - surfacePoint; directionToLight.normalize(); Vector reflectedLightDirection = - directionToLight.reflect(normal); + directionToLight.reflect(surfaceNormal); Ray surfaceToLight(surfacePoint, directionToLight); Color light_contribution = @@ -274,7 +268,7 @@ Color Scene::computePhong(const refptr material, || light_contribution.b > 0.0 ) { /* calculate the diffuse term */ - double diffuse_coef = directionToLight % normal; + double diffuse_coef = directionToLight % surfaceNormal; if (diffuse_coef > 0.0) { result += diffuseColor diff --git a/scenes/die.fart b/scenes/die.fart index 0930cdb..d16966e 100644 --- a/scenes/die.fart +++ b/scenes/die.fart @@ -8,14 +8,39 @@ scene camera { - position <1.2, -2, 1.2> + position <1.2, -2, 1> look_at <0, 0, 0> } - light { position <10, 4, 10> color <.7, .7, .7> } - light { position <-10, -5, 10> color <.7, .7, .7> } + light { position <10, -12, 8> } - plane { position <0, 0, 1>, 0.501 } + plane + { + position <0, 0, 1>, 0.501 + material + { + color <0.4, 1, 0.4> + reflectance 0.4 + } + } + plane + { + position <1, 0, 0>, 1 + material + { + color <1, 0.4, 0.4> + reflectance 0.4 + } + } + plane + { + position <0, -1, 0>, 1 + material + { + color <0.4, 0.4, 1> + reflectance 0.4 + } + } subtract {