added texture name to material

This commit is contained in:
Anselme 2016-06-20 17:26:04 +02:00
parent 0f568c5eec
commit bb27fb0965
2 changed files with 32 additions and 33 deletions

View File

@ -11,39 +11,39 @@ void PhongMaterial::bindAttributes(Shader* myShader)
// TODO store the attributes location // TODO store the attributes location
myShader->bindFloat(myShader->getLocation("materialNs"), shininess); myShader->bindFloat(myShader->getLocation("materialNs"), shininess);
if(normal_map != NULL) if(textures[NORMALS_SLOT] != NULL)
{ {
normal_map->bind(NORMALS_SLOT); textures[NORMALS_SLOT]->bind(NORMALS_SLOT);
myShader->bindInteger(myShader->getLocation("normalMap"), NORMALS_SLOT); myShader->bindInteger(myShader->getLocation("normalMap"), NORMALS_SLOT);
} }
if(emission_texture != NULL) if(textures[EMISSION_SLOT] != NULL)
{ {
emission_texture->bind(EMISSION_SLOT); textures[EMISSION_SLOT]->bind(EMISSION_SLOT);
myShader->bindInteger(myShader->getLocation("emissionTexture"), EMISSION_SLOT); myShader->bindInteger(myShader->getLocation("emissionTexture"), EMISSION_SLOT);
} }
else else
myShader->bindVec3(myShader->getLocation("materialEmission"), emission); myShader->bindVec3(myShader->getLocation("materialEmission"), emission);
if(diffuse_texture != NULL) if(textures[DIFFUSE_SLOT] != NULL)
{ {
diffuse_texture->bind(DIFFUSE_SLOT); textures[DIFFUSE_SLOT]->bind(DIFFUSE_SLOT);
myShader->bindInteger(myShader->getLocation("diffuseTexture"), DIFFUSE_SLOT); myShader->bindInteger(myShader->getLocation("diffuseTexture"), DIFFUSE_SLOT);
} }
else else
myShader->bindVec3(myShader->getLocation("materialKd"), diffuse); myShader->bindVec3(myShader->getLocation("materialKd"), diffuse);
if(specular_texture != NULL) if(textures[SPECULAR_SLOT] != NULL)
{ {
specular_texture->bind(SPECULAR_SLOT); textures[SPECULAR_SLOT]->bind(SPECULAR_SLOT);
myShader->bindInteger(myShader->getLocation("specularTexture"), SPECULAR_SLOT); myShader->bindInteger(myShader->getLocation("specularTexture"), SPECULAR_SLOT);
} }
else else
myShader->bindVec3(myShader->getLocation("materialKs"), specular); myShader->bindVec3(myShader->getLocation("materialKs"), specular);
if(alpha_mask != NULL) if(textures[ALPHA_SLOT] != NULL)
{ {
alpha_mask->bind(ALPHA_SLOT); textures[ALPHA_SLOT]->bind(ALPHA_SLOT);
myShader->bindInteger(myShader->getLocation("alphaMask"), ALPHA_SLOT); myShader->bindInteger(myShader->getLocation("alphaMask"), ALPHA_SLOT);
} }
} }
@ -51,15 +51,15 @@ void PhongMaterial::bindAttributes(Shader* myShader)
unsigned int PhongMaterial::getFlags() unsigned int PhongMaterial::getFlags()
{ {
unsigned int flags = 1 << Mesh::MATERIAL_PHONG; unsigned int flags = 1 << Mesh::MATERIAL_PHONG;
if(normal_map != NULL) if(textures[NORMALS_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_PHONG_NORMAL_MAP; flags |= 1 << Mesh::MATERIAL_PHONG_NORMAL_MAP;
if(emission_texture != NULL) if(textures[EMISSION_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_PHONG_EMISSION_TEXTURE; flags |= 1 << Mesh::MATERIAL_PHONG_EMISSION_TEXTURE;
if(diffuse_texture != NULL) if(textures[DIFFUSE_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_PHONG_DIFFUSE_TEXTURE; flags |= 1 << Mesh::MATERIAL_PHONG_DIFFUSE_TEXTURE;
if(specular_texture != NULL) if(textures[SPECULAR_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_PHONG_SPECULAR_TEXTURE; flags |= 1 << Mesh::MATERIAL_PHONG_SPECULAR_TEXTURE;
if(alpha_mask != NULL) if(textures[ALPHA_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_ALPHA_MASK; flags |= 1 << Mesh::MATERIAL_ALPHA_MASK;
return flags; return flags;
} }

View File

@ -3,21 +3,12 @@
#include "material.h" #include "material.h"
#include "glm/vec3.hpp" #include "glm/vec3.hpp"
#include <string>
class Texture; class Texture;
struct PhongMaterial : public Material struct PhongMaterial : public Material
{ {
glm::vec3 emission;
glm::vec3 diffuse;
glm::vec3 specular;
float shininess;
Texture* emission_texture;
Texture* diffuse_texture;
Texture* specular_texture;
Texture* normal_map;
Texture* alpha_mask;
enum TextureSlots enum TextureSlots
{ {
DIFFUSE_SLOT, DIFFUSE_SLOT,
@ -28,22 +19,30 @@ struct PhongMaterial : public Material
NB_PHONG_SLOTS NB_PHONG_SLOTS
}; };
glm::vec3 emission;
glm::vec3 diffuse;
glm::vec3 specular;
float shininess;
Texture* textures[NB_PHONG_SLOTS];
std::string textureNames[NB_PHONG_SLOTS];
PhongMaterial() : PhongMaterial() :
emission(0), emission(0),
diffuse(0.5f), diffuse(0.5f),
specular(0.5f), specular(0.5f),
shininess(10), shininess(10)
emission_texture(NULL), {
diffuse_texture(NULL), for(int i=0; i<NB_PHONG_SLOTS; ++i)
specular_texture(NULL), textures[i] = NULL;
normal_map(NULL), }
alpha_mask(NULL)
{} void setTexture(TextureSlots slot, Texture* texture = NULL, const std::string &name = "")
{ textures[slot] = texture; textureNames[slot] = name; }
virtual ~PhongMaterial() {} virtual ~PhongMaterial() {}
virtual void bindAttributes(Shader* myShader); virtual void bindAttributes(Shader* myShader);
virtual unsigned int getFlags(); virtual unsigned int getFlags();
}; };