fixed a few mistakes
This commit is contained in:
parent
4f4d4da876
commit
a70aaf7a31
@ -33,6 +33,7 @@ void AmbientLight::bindAttributes(Shader *shader, Camera *camera)
|
||||
}
|
||||
|
||||
int DirectionnalLight::m_shaderRefCounter = 0;
|
||||
Shader* DirectionnalLight::m_shaders[4] = {NULL};
|
||||
|
||||
DirectionnalLight::DirectionnalLight(glm::vec3 dir, glm::vec3 lightColor) :
|
||||
m_direction(dir),
|
||||
@ -45,6 +46,7 @@ DirectionnalLight::DirectionnalLight(glm::vec3 dir, glm::vec3 lightColor) :
|
||||
|
||||
void DirectionnalLight::bindAttributes(Shader *shader, Camera *camera)
|
||||
{
|
||||
shader->bindVec3(shader->getLocation("lightColor"), m_color);
|
||||
glm::vec4 direction = glm::vec4(m_direction, 0.f);
|
||||
shader->bindVec3(shader->getLocation("dirLight"), glm::normalize(glm::vec3(camera->getViewMatrix()*direction)));
|
||||
if(m_shadowCaster)
|
||||
@ -53,16 +55,16 @@ void DirectionnalLight::bindAttributes(Shader *shader, Camera *camera)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
m_shadowMap->getTexture(0)->bind(5); // TODO use something else than 5
|
||||
shader->bindInteger(shader->getLocation("shadowMap"), 5);
|
||||
m_shadowMap->getTexture(0)->bind(7); // TODO use something else than 7
|
||||
shader->bindInteger(shader->getLocation("shadowMap"), 7);
|
||||
glm::mat4 viewToLightMatrix = Light::biasMatrix * m_projectionMatrices[0] * m_viewMatrices[0] * glm::inverse(camera->getViewMatrix());
|
||||
shader->bindMat4(shader->getLocation("viewToLightMatrix"), viewToLightMatrix);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
m_shadowMap->getTexture(0)->bind(5); // TODO use something else than 5
|
||||
shader->bindInteger(shader->getLocation("shadowMap"), 5);
|
||||
m_shadowMap->getTexture(0)->bind(7); // TODO use something else than 7
|
||||
shader->bindInteger(shader->getLocation("shadowMap"), 7);
|
||||
glm::mat4 lightMVP;
|
||||
lightMVP = Light::biasMatrix * m_projectionMatrices[0] * (m_viewMatrices[0] * glm::inverse(camera->getViewMatrix()));
|
||||
shader->bindMat4(shader->getLocation("frontShadowMVP"), lightMVP);
|
||||
@ -114,9 +116,15 @@ void DirectionnalLight::initShadowMap(int resolution, bool isCascaded)
|
||||
m_shadowCaster = true;
|
||||
|
||||
if(isCascaded)
|
||||
{
|
||||
m_viewMatrices.resize(3);
|
||||
m_projectionMatrices.resize(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_viewMatrices.resize(1);
|
||||
m_projectionMatrices.resize(1);
|
||||
}
|
||||
|
||||
// Depth buffer
|
||||
Texture *tex = new Texture(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, resolution, resolution, GL_FLOAT, isCascaded ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D);
|
||||
@ -184,27 +192,28 @@ void DirectionnalLight::updateShadowMap(Scene* scene)
|
||||
GeometryNode* node = geometryIt->getItem();
|
||||
if(node->mesh->getFlags() & (1 << Mesh::MESH_SHADOWED))
|
||||
{
|
||||
int hasAlpha = (node->mesh->getFlags() & (1 << Mesh::MATERIAL_ALPHA_MASK)) > 0;
|
||||
int shaderId = (node->mesh->getFlags() & (1 << Mesh::MATERIAL_ALPHA_MASK)) != 0;
|
||||
|
||||
// compute matrix attributes
|
||||
if(hasCascades)
|
||||
{
|
||||
m_shaders[hasAlpha+2]->bind();
|
||||
shaderId += 2;
|
||||
m_shaders[shaderId]->bind();
|
||||
glm::mat4 lightMVP;
|
||||
lightMVP = m_projectionMatrices[0] * (m_viewMatrices[0] * node->modelMatrix);
|
||||
m_shaders[hasAlpha]->bindMat4(m_shaders[hasAlpha]->getLocation("frontShadowMVP"), lightMVP);
|
||||
m_shaders[shaderId]->bindMat4(m_shaders[shaderId]->getLocation("frontShadowMVP"), lightMVP);
|
||||
lightMVP = m_projectionMatrices[1] * (m_viewMatrices[1] * node->modelMatrix);
|
||||
m_shaders[hasAlpha]->bindMat4(m_shaders[hasAlpha]->getLocation("midShadowMVP"), lightMVP);
|
||||
m_shaders[shaderId]->bindMat4(m_shaders[shaderId]->getLocation("midShadowMVP"), lightMVP);
|
||||
lightMVP = m_projectionMatrices[2] * (m_viewMatrices[2] * node->modelMatrix);
|
||||
m_shaders[hasAlpha]->bindMat4(m_shaders[hasAlpha]->getLocation("backShadowMVP"), lightMVP);
|
||||
node->mesh->draw(m_shaders[hasAlpha], false, hasAlpha, false);
|
||||
m_shaders[shaderId]->bindMat4(m_shaders[shaderId]->getLocation("backShadowMVP"), lightMVP);
|
||||
node->mesh->draw(m_shaders[shaderId], false, shaderId, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_shaders[hasAlpha]->bind();
|
||||
m_shaders[shaderId]->bind();
|
||||
glm::mat4 lightMVP = m_projectionMatrices[0] * (m_viewMatrices[0] * node->modelMatrix);
|
||||
m_shaders[hasAlpha]->bindMat4(m_shaders[hasAlpha]->getLocation("MVP"), lightMVP);
|
||||
node->mesh->draw(m_shaders[hasAlpha], false, hasAlpha, false);
|
||||
m_shaders[shaderId]->bindMat4(m_shaders[shaderId]->getLocation("MVP"), lightMVP);
|
||||
node->mesh->draw(m_shaders[shaderId], false, shaderId, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,6 @@ void Texture::setParameter(GLenum parameter, GLenum value)
|
||||
{
|
||||
glBindTexture(m_target, m_texId);
|
||||
glTexParameteri(m_target, parameter, value);
|
||||
glBindTexture(m_target, 0);
|
||||
}
|
||||
|
||||
void Texture::createMipMaps()
|
||||
|
Loading…
x
Reference in New Issue
Block a user