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
This commit is contained in:
Josh Holtrop 2009-01-31 18:29:28 +00:00
parent 6fbdf46122
commit 7181a894a4
2 changed files with 25 additions and 6 deletions

View File

@ -1,6 +1,8 @@
#include "Lighting.h" #include "Lighting.h"
#include <math.h> /* pow() */ #include <math.h> /* pow() */
#include <iostream>
using namespace std;
Color Lighting::computePhong(const Material & material, Color Lighting::computePhong(const Material & material,
const std::vector<Light *> & lights, const std::vector<Light *> & lights,
@ -26,15 +28,31 @@ Color Lighting::computePhong(const Material & material,
directionToLight.reflect(surfaceNormal); directionToLight.reflect(surfaceNormal);
/* calculate the diffuse term */ /* calculate the diffuse term */
result += diffuseColor double diffuse_coef = directionToLight % surfaceNormal;
* (*it)->getDiffuseColor() if (diffuse_coef > 0.0)
* (directionToLight % surfaceNormal); {
result += diffuseColor
* (*it)->getDiffuseColor()
* diffuse_coef;
}
/* calculate the specular term */ /* calculate the specular term */
result += specularColor double specular_coef = reflectedLightDirection % viewDirection;
* (*it)->getSpecularColor() if (specular_coef > 0.0)
* pow(reflectedLightDirection % viewDirection, shininess); {
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; return result;
} }

View File

@ -25,6 +25,7 @@ Scene::Scene(const map<string, const char *> & options,
m_vfov = 60.0; m_vfov = 60.0;
m_verbose = false; m_verbose = false;
m_data = NULL; m_data = NULL;
m_ambient_light = Color(0.1, 0.1, 0.1);
load(filename); load(filename);