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