Moving material paramters from graphics to material class.

This commit is contained in:
Faerbit 2014-11-08 01:44:24 +01:00
parent 21b144a72b
commit 34d925cdfe
5 changed files with 37 additions and 7 deletions

View File

@ -76,11 +76,7 @@ void draw( float runTime )
// set Material Parameters // set Material Parameters
shader.getReference()->setUniform("ambientColor", level.getAmbientLight()); 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("camera", glm::vec3(0.0f, 0.0f, 0.0f));
shader.getReference()->setUniform("shininess", 3.0f);
// render the level(currently only a bunny): // render the level(currently only a bunny):
level.render(); level.render();

View File

@ -20,7 +20,7 @@ void Level::load(Shader shader) {
// load the geometry of the stanford bunny and build a VAO: // load the geometry of the stanford bunny and build a VAO:
Model model = Model("Bunny.obj"); Model model = Model("Bunny.obj");
// load a texture: // load a texture:
Material material = Material("clownfishBunny.png"); Material material = Material("clownfishBunny.png", 0.1f, 0.5f, 0.5f, 3.0f);
//Create object //Create object
Object object = Object(model, material, glm::vec3(0.0f, 0.0f, 0.0f), 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), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),

View File

@ -1,7 +1,12 @@
#include "material.hh" #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)); reference = ACGL::OpenGL::Texture2DFileManager::the()->get(ACGL::OpenGL::Texture2DCreator(filePath));
this->ambientFactor = ambientFactor;
this->diffuseFactor = diffuseFactor;
this->specularFactor = specularFactor;
this->shininess = shininess;
} }
Material::Material() { Material::Material() {
@ -13,3 +18,19 @@ Material::~Material() {
ACGL::OpenGL::SharedTexture2D Material::getReference() { ACGL::OpenGL::SharedTexture2D Material::getReference() {
return reference; return reference;
} }
float Material::getAmbientFactor(){
return ambientFactor;
}
float Material::getDiffuseFactor(){
return diffuseFactor;
}
float Material::getSpecularFactor() {
return specularFactor;
}
float Material::getShininess() {
return shininess;
}

View File

@ -8,12 +8,21 @@
class Material{ class Material{
public: public:
Material(std::string filePath); Material(std::string filePath, float ambientFactor,
float diffuseFactor, float specularFactor, float shininess);
Material(); Material();
ACGL::OpenGL::SharedTexture2D getReference(); ACGL::OpenGL::SharedTexture2D getReference();
~Material(); ~Material();
float getAmbientFactor();
float getDiffuseFactor();
float getSpecularFactor();
float getShininess();
private: private:
ACGL::OpenGL::SharedTexture2D reference; ACGL::OpenGL::SharedTexture2D reference;
float ambientFactor;
float diffuseFactor;
float specularFactor;
float shininess;
}; };
#endif #endif

View File

@ -17,6 +17,10 @@ Object::~Object() {
} }
void Object::render() { 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); shader->setTexture("uTexture", material.getReference(), 0);
model->render(); model->render();
} }