diff --git a/graphics.cc b/graphics.cc index 0b67f79..37b899d 100644 --- a/graphics.cc +++ b/graphics.cc @@ -76,11 +76,7 @@ void draw( float runTime ) // set Material Parameters shader.getReference()->setUniform("ambientColor", level.getAmbientLight()); - shader.getReference()->setUniform("ambientFactor", 0.1f); - shader.getReference()->setUniform("diffuseFactor", 0.5f); - shader.getReference()->setUniform("specularFactor", 0.5f); shader.getReference()->setUniform("camera", glm::vec3(0.0f, 0.0f, 0.0f)); - shader.getReference()->setUniform("shininess", 3.0f); // render the level(currently only a bunny): level.render(); diff --git a/level.cc b/level.cc index f87186d..fd1038f 100644 --- a/level.cc +++ b/level.cc @@ -20,7 +20,7 @@ void Level::load(Shader shader) { // load the geometry of the stanford bunny and build a VAO: Model model = Model("Bunny.obj"); // load a texture: - Material material = Material("clownfishBunny.png"); + Material material = Material("clownfishBunny.png", 0.1f, 0.5f, 0.5f, 3.0f); //Create object Object object = Object(model, material, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), diff --git a/material.cc b/material.cc index a2b2077..b8639fd 100644 --- a/material.cc +++ b/material.cc @@ -1,7 +1,12 @@ #include "material.hh" -Material::Material(std::string filePath) { +Material::Material(std::string filePath, float ambientFactor, float diffuseFactor, + float specularFactor, float shininess) { reference = ACGL::OpenGL::Texture2DFileManager::the()->get(ACGL::OpenGL::Texture2DCreator(filePath)); + this->ambientFactor = ambientFactor; + this->diffuseFactor = diffuseFactor; + this->specularFactor = specularFactor; + this->shininess = shininess; } Material::Material() { @@ -13,3 +18,19 @@ Material::~Material() { ACGL::OpenGL::SharedTexture2D Material::getReference() { return reference; } + +float Material::getAmbientFactor(){ + return ambientFactor; +} + +float Material::getDiffuseFactor(){ + return diffuseFactor; +} + +float Material::getSpecularFactor() { + return specularFactor; +} + +float Material::getShininess() { + return shininess; +} diff --git a/material.hh b/material.hh index e5aced5..5c80b73 100644 --- a/material.hh +++ b/material.hh @@ -8,12 +8,21 @@ class Material{ public: - Material(std::string filePath); + Material(std::string filePath, float ambientFactor, + float diffuseFactor, float specularFactor, float shininess); Material(); ACGL::OpenGL::SharedTexture2D getReference(); ~Material(); + float getAmbientFactor(); + float getDiffuseFactor(); + float getSpecularFactor(); + float getShininess(); private: ACGL::OpenGL::SharedTexture2D reference; + float ambientFactor; + float diffuseFactor; + float specularFactor; + float shininess; }; #endif diff --git a/object.cc b/object.cc index abbce98..d61fe5e 100644 --- a/object.cc +++ b/object.cc @@ -17,6 +17,10 @@ Object::~Object() { } void Object::render() { + shader->setUniform("ambientFactor", material.getAmbientFactor()); + shader->setUniform("diffuseFactor", material.getDiffuseFactor()); + shader->setUniform("specularFactor", material.getSpecularFactor()); + shader->setUniform("shininess", material.getShininess()); shader->setTexture("uTexture", material.getReference(), 0); model->render(); }