SparrowRenderer/src/pbrmaterial.cpp

76 lines
2.4 KiB
C++

#include "pbrmaterial.h"
#include "texture.h"
#include "sparrowrenderer.h"
#include "shader.h"
#include "mesh.h"
#include <glm/ext.hpp>
void PBRMaterial::bindAttributes(Shader* myShader)
{
// TODO store the attributes location
myShader->bindFloat(myShader->getLocation("opacity"), opacity);
if(textures[NORMALS_SLOT] != NULL)
{
textures[NORMALS_SLOT]->bind(NORMALS_SLOT);
myShader->bindInteger(myShader->getLocation("normalMap"), NORMALS_SLOT);
}
if(textures[EMISSION_SLOT] != NULL)
{
textures[EMISSION_SLOT]->bind(EMISSION_SLOT);
myShader->bindInteger(myShader->getLocation("emissionTexture"), EMISSION_SLOT);
}
else
myShader->bindVec3(myShader->getLocation("emission"), emission);
if(textures[ALBEDO_SLOT] != NULL)
{
textures[ALBEDO_SLOT]->bind(ALBEDO_SLOT);
myShader->bindInteger(myShader->getLocation("albedoTexture"), ALBEDO_SLOT);
}
else
myShader->bindVec3(myShader->getLocation("albedo"), albedo);
if(textures[ROUGHNESS_SLOT] != NULL)
{
textures[ROUGHNESS_SLOT]->bind(ROUGHNESS_SLOT);
myShader->bindInteger(myShader->getLocation("roughnessTexture"), ROUGHNESS_SLOT);
}
else
myShader->bindFloat(myShader->getLocation("roughness"), roughness);
if(textures[METALLIC_SLOT] != NULL)
{
textures[METALLIC_SLOT]->bind(METALLIC_SLOT);
myShader->bindInteger(myShader->getLocation("metallicTexture"), METALLIC_SLOT);
}
else
myShader->bindFloat(myShader->getLocation("metallic"), metallic);
if(textures[ALPHA_SLOT] != NULL)
{
textures[ALPHA_SLOT]->bind(ALPHA_SLOT);
myShader->bindInteger(myShader->getLocation("alphaMask"), ALPHA_SLOT);
}
}
unsigned int PBRMaterial::getFlags()
{
unsigned int flags = 1 << Mesh::MATERIAL_PBR;
if(textures[NORMALS_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_PBR_NORMAL_MAP;
if(textures[EMISSION_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_PBR_EMISSION_TEXTURE;
if(textures[ALBEDO_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_PBR_ALBEDO_TEXTURE;
if(textures[ROUGHNESS_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_PBR_ROUGHNESS_TEXTURE;
if(textures[METALLIC_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_PBR_METALLIC_TEXTURE;
if(textures[ALPHA_SLOT] != NULL)
flags |= 1 << Mesh::MATERIAL_ALPHA_MASK;
return flags;
}