added texture name to material
This commit is contained in:
parent
0f568c5eec
commit
bb27fb0965
@ -11,39 +11,39 @@ void PhongMaterial::bindAttributes(Shader* myShader)
|
||||
// TODO store the attributes location
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
else
|
||||
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);
|
||||
}
|
||||
else
|
||||
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);
|
||||
}
|
||||
else
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -51,15 +51,15 @@ void PhongMaterial::bindAttributes(Shader* myShader)
|
||||
unsigned int PhongMaterial::getFlags()
|
||||
{
|
||||
unsigned int flags = 1 << Mesh::MATERIAL_PHONG;
|
||||
if(normal_map != NULL)
|
||||
if(textures[NORMALS_SLOT] != NULL)
|
||||
flags |= 1 << Mesh::MATERIAL_PHONG_NORMAL_MAP;
|
||||
if(emission_texture != NULL)
|
||||
if(textures[EMISSION_SLOT] != NULL)
|
||||
flags |= 1 << Mesh::MATERIAL_PHONG_EMISSION_TEXTURE;
|
||||
if(diffuse_texture != NULL)
|
||||
if(textures[DIFFUSE_SLOT] != NULL)
|
||||
flags |= 1 << Mesh::MATERIAL_PHONG_DIFFUSE_TEXTURE;
|
||||
if(specular_texture != NULL)
|
||||
if(textures[SPECULAR_SLOT] != NULL)
|
||||
flags |= 1 << Mesh::MATERIAL_PHONG_SPECULAR_TEXTURE;
|
||||
if(alpha_mask != NULL)
|
||||
if(textures[ALPHA_SLOT] != NULL)
|
||||
flags |= 1 << Mesh::MATERIAL_ALPHA_MASK;
|
||||
return flags;
|
||||
}
|
||||
|
@ -3,21 +3,12 @@
|
||||
|
||||
#include "material.h"
|
||||
#include "glm/vec3.hpp"
|
||||
#include <string>
|
||||
|
||||
class Texture;
|
||||
|
||||
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
|
||||
{
|
||||
DIFFUSE_SLOT,
|
||||
@ -28,22 +19,30 @@ struct PhongMaterial : public Material
|
||||
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() :
|
||||
emission(0),
|
||||
diffuse(0.5f),
|
||||
specular(0.5f),
|
||||
shininess(10),
|
||||
emission_texture(NULL),
|
||||
diffuse_texture(NULL),
|
||||
specular_texture(NULL),
|
||||
normal_map(NULL),
|
||||
alpha_mask(NULL)
|
||||
{}
|
||||
shininess(10)
|
||||
{
|
||||
for(int i=0; i<NB_PHONG_SLOTS; ++i)
|
||||
textures[i] = NULL;
|
||||
}
|
||||
|
||||
void setTexture(TextureSlots slot, Texture* texture = NULL, const std::string &name = "")
|
||||
{ textures[slot] = texture; textureNames[slot] = name; }
|
||||
|
||||
virtual ~PhongMaterial() {}
|
||||
|
||||
virtual void bindAttributes(Shader* myShader);
|
||||
|
||||
|
||||
virtual unsigned int getFlags();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user