From 7181a894a4274f43505260ca04d352a093e80f47 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 31 Jan 2009 18:29:28 +0000 Subject: [PATCH] capping colors in main/Lighting; colors are maxing out too easily, might need a better reduction method git-svn-id: svn://anubis/fart/trunk@74 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- main/Lighting.cc | 30 ++++++++++++++++++++++++------ main/Scene.cc | 1 + 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/main/Lighting.cc b/main/Lighting.cc index 24b5f88..8475efd 100644 --- a/main/Lighting.cc +++ b/main/Lighting.cc @@ -1,6 +1,8 @@ #include "Lighting.h" #include /* pow() */ +#include +using namespace std; Color Lighting::computePhong(const Material & material, const std::vector & lights, @@ -26,15 +28,31 @@ Color Lighting::computePhong(const Material & material, directionToLight.reflect(surfaceNormal); /* calculate the diffuse term */ - result += diffuseColor - * (*it)->getDiffuseColor() - * (directionToLight % surfaceNormal); + double diffuse_coef = directionToLight % surfaceNormal; + if (diffuse_coef > 0.0) + { + result += diffuseColor + * (*it)->getDiffuseColor() + * diffuse_coef; + } /* calculate the specular term */ - result += specularColor - * (*it)->getSpecularColor() - * pow(reflectedLightDirection % viewDirection, shininess); + double specular_coef = reflectedLightDirection % viewDirection; + if (specular_coef > 0.0) + { + result += specularColor + * (*it)->getSpecularColor() + * pow(specular_coef, shininess); + } } + /* TODO: figure out better scaling */ + if (result.r > 1.0) + result.r = 1.0; + if (result.g > 1.0) + result.g = 1.0; + if (result.b > 1.0) + result.b = 1.0; + return result; } diff --git a/main/Scene.cc b/main/Scene.cc index 330daca..374a87c 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -25,6 +25,7 @@ Scene::Scene(const map & options, m_vfov = 60.0; m_verbose = false; m_data = NULL; + m_ambient_light = Color(0.1, 0.1, 0.1); load(filename);