0

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 :

enter image description here

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) :

enter image description here

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 ?

genpfault
  • 51,148
  • 11
  • 85
  • 139
user1364743
  • 5,283
  • 6
  • 51
  • 90
  • 1
    First of all, you may think that setting the vertex attrib pointer is what sends the vertices to your GLSL program, but this is not the case. Vertex Array state is persistent, unless you changed the attrib pointer state elsewhere it is going to continue drawing using the old state (it is probably the case that setting the attrib pointer in the first snippet of code was redundant). There's also something else fundamentally different about how you are transforming the scene in the two screenshots, as the "1" is rotated 90 degrees clockwise. – Andon M. Coleman Sep 06 '13 at 17:54
  • Thanks for your answer. It's normal the scene is rotating permanently around the Y axe. – user1364743 Sep 07 '13 at 19:18

0 Answers0