added an ambient color component to Material, changed Lighting to use it
git-svn-id: svn://anubis/fart/trunk@75 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
7181a894a4
commit
c4509d0594
@ -11,7 +11,7 @@ Color Lighting::computePhong(const Material & material,
|
||||
const Vector & surfaceNormal,
|
||||
const Color & ambientLight)
|
||||
{
|
||||
Color result = ambientLight;
|
||||
Color result = ambientLight * material.getAmbientColor();
|
||||
|
||||
Vector viewDirection = -viewRay.getDirection();
|
||||
double shininess = material.getShininess();
|
||||
|
@ -12,6 +12,12 @@ class Material
|
||||
|
||||
Material();
|
||||
|
||||
void setAmbientColor(const Color & ambient)
|
||||
{
|
||||
m_ambient_color = ambient;
|
||||
}
|
||||
const Color & getAmbientColor() const { return m_ambient_color; }
|
||||
|
||||
void setDiffuseColor(const Color & diffuse)
|
||||
{
|
||||
m_diffuse_color = diffuse;
|
||||
@ -28,6 +34,7 @@ class Material
|
||||
double getShininess() const { return m_shininess; }
|
||||
|
||||
protected:
|
||||
Color m_ambient_color;
|
||||
Color m_diffuse_color;
|
||||
Color m_specular_color;
|
||||
double m_shininess;
|
||||
|
@ -25,7 +25,7 @@ Scene::Scene(const map<string, const char *> & options,
|
||||
m_vfov = 60.0;
|
||||
m_verbose = false;
|
||||
m_data = NULL;
|
||||
m_ambient_light = Color(0.1, 0.1, 0.1);
|
||||
m_ambient_light = Color(0.05, 0.05, 0.05);
|
||||
|
||||
load(filename);
|
||||
|
||||
@ -91,12 +91,17 @@ void Scene::load(const char * filename)
|
||||
Shape * plane = new Plane(0, 0, 1, -2);
|
||||
m_shapes.push_back(plane);
|
||||
|
||||
Material * m = new Material();
|
||||
m->setDiffuseColor(Color::red);
|
||||
m->setAmbientColor(Color::red);
|
||||
|
||||
Shape * shape = new Sphere(1.0);
|
||||
m_transform.translate(1.0, 5.0, 0.5);
|
||||
shape->setTransform(m_transform);
|
||||
shape->setMaterial(m);
|
||||
m_shapes.push_back(shape);
|
||||
|
||||
Light * light = new PointLight(Vector(-1, -1, 1));
|
||||
Light * light = new PointLight(Vector(2, -1, 2));
|
||||
m_lights.push_back(light);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user