Moving material paramters from graphics to material class.
This commit is contained in:
parent
21b144a72b
commit
34d925cdfe
@ -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();
|
||||
|
2
level.cc
2
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),
|
||||
|
23
material.cc
23
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;
|
||||
}
|
||||
|
11
material.hh
11
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
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user