diff --git a/main/Lighting.cc b/main/Lighting.cc index 8475efd..0b50d77 100644 --- a/main/Lighting.cc +++ b/main/Lighting.cc @@ -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(); diff --git a/main/Material.h b/main/Material.h index 9bae30d..5bef0db 100644 --- a/main/Material.h +++ b/main/Material.h @@ -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; diff --git a/main/Scene.cc b/main/Scene.cc index 374a87c..8a05a61 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -25,7 +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); + 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); }