I've integrated basic shadow mapping. However I noticed a strange behaviour with the rendering. To summarize, the shadow mapping technics requires 2 step. The first to render the scene from the light point of view (filling of a depth texture) and the second from the camera point of view. Here's the C++ code foir the first step :
void Basic::GLSLRenderSystem::renderSceneFromLight(void)
{
SceneNodeList::iterator nodeListIt = this->m_pScene->getRootNode()->begin();
for (; nodeListIt != this->m_pScene->getRootNode()->end(); ++nodeListIt)
{
EntityList::const_iterator Ite = (*nodeListIt)->getListEntity().begin();
(*nodeListIt)->beginTransformations();
(*nodeListIt)->applyTransformations();
for (; Ite != (*nodeListIt)->getListEntity().end(); ++Ite)
{
//Send matrix
glm::mat4 modelMatrix = (*nodeListIt)->getModelMatrix();
glm::mat4 modelViewMatrix = this->m_ViewMatrix * modelMatrix;
glm::mat4 MVPMatrix = this->m_ProjectionMatrix * modelViewMatrix;
this->m_pShadowProgram->setUniform("MVP", MVPMatrix);
(*Ite)->getMesh()->getVertices()->lock();
//Send vertice positions
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), OFFSET_BUFFER(0));
(*Ite)->getMesh()->getVertices()->unlock();
//Draw primitive
if ((*Ite)->getMesh()->getVertices()->getCount() == 2)
glDrawArrays(GL_LINES, 0, (*Ite)->getMesh()->getVertices()->getSize());
else if ((*Ite)->getMesh()->getVertices()->getCount() == 3)
glDrawArrays(GL_TRIANGLES, 0, (*Ite)->getMesh()->getVertices()->getSize());
else if ((*Ite)->getMesh()->getVertices()->getCount() == 4)
glDrawArrays(GL_QUADS, 0, (*Ite)->getMesh()->getVertices()->getSize());
}
(*nodeListIt)->endTransformations();
}
}
Here's the output :
There's acnee on the floor. But now if I erase the code below the part corresponding the sending of the vertices to the program shader :
void Basic::GLSLRenderSystem::renderSceneFromLight(void)
{
SceneNodeList::iterator nodeListIt = this->m_pScene->getRootNode()->begin();
for (; nodeListIt != this->m_pScene->getRootNode()->end(); ++nodeListIt)
{
EntityList::const_iterator Ite = (*nodeListIt)->getListEntity().begin();
(*nodeListIt)->beginTransformations();
(*nodeListIt)->applyTransformations();
for (; Ite != (*nodeListIt)->getListEntity().end(); ++Ite)
{
//Send matrix
glm::mat4 modelMatrix = (*nodeListIt)->getModelMatrix();
glm::mat4 modelViewMatrix = this->m_ViewMatrix * modelMatrix;
glm::mat4 MVPMatrix = this->m_ProjectionMatrix * modelViewMatrix;
this->m_pShadowProgram->setUniform("MVP", MVPMatrix);
//Draw primitive
if ((*Ite)->getMesh()->getVertices()->getCount() == 2)
glDrawArrays(GL_LINES, 0, (*Ite)->getMesh()->getVertices()->getSize());
else if ((*Ite)->getMesh()->getVertices()->getCount() == 3)
glDrawArrays(GL_TRIANGLES, 0, (*Ite)->getMesh()->getVertices()->getSize());
else if ((*Ite)->getMesh()->getVertices()->getCount() == 4)
glDrawArrays(GL_QUADS, 0, (*Ite)->getMesh()->getVertices()->getSize());
}
(*nodeListIt)->endTransformations();
}
}
I have the following output (with no acnee) :
Here's is the vertex shader :
#version 400
layout (location = 0) in vec3 VertexPosition;
uniform mat4 MVP;
void main(void)
{
gl_Position = MVP * vec4(VertexPosition, 1.0f);
}
As you can see I transform my vertices in light (view) position. So in my C++ code if I don't send (in the second case) the vertices I wonder how it works ! (I just send the light MVP matrix !) And the most amazing thing is there is no more acnee! How can you explain this behaviour ? Do I send the vertices to the shader like in the first case (and find a solution to erase the acnee on the floor) or not ?