rajaditya_m
rajaditya_m

Reputation: 299

Shadow Mapping is faint

I am trying to do OpenGL GLSL based shadow mapping. The trouble is that after I have finished rendering the shadow map, I am rendering the map to the screen to test whether the rendering works correctly or not i.e I am simply using the newly generated texture as a texture which I am mapping on to the screen. The expected result is that I will see the new texture. But instead, what i am seeing is a white area with the texture drawn but extremely faint. That is, if I tilt the screen at a certain angle only then I can see the faint outlines of the shadow map.

Can anyone tell me if I am doing anything wrong?

Here is relevant parts of my code :

     void Init_FBO() 
    { 
            //glActiveTexture(GL_TEXTURE3);  
        GLfloat border[] = {1.0f, 0.0f, 0.0f, 0.0f};  

        glGenTextures(1, &depthTex);  
        glBindTexture(GL_TEXTURE_2D, depthTex);  
        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,900,900, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);  
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);  
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);  
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);  
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);  
        glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border);  
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);  
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
        glBindTexture(GL_TEXTURE_2D,0); 

        glGenFramebuffers(1, &shadowFBO);  
        glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);  
        glDrawBuffer(GL_NONE);  
        glReadBuffer(GL_NONE);  
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTex, 0);  
        glBindFramebuffer(GL_FRAMEBUFFER, 0); // go back to the default framebuffer  
        // check FBO status 
        GLenum FBOstatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 
        if(FBOstatus != GL_FRAMEBUFFER_COMPLETE) 
        {
            printf("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO\n");
        }
        else
        {
            printf("Frame Buffer Done Succesfully\n");
        } 
    }




    void generateShadowTex()
    {
            //Calculate final ligting properties
        glm::vec4 a_f=light_ambient*mat_ambient;
        glm::vec4 d_f=light_diffuse*mat_diffuse;
        glm::vec4 s_f=light_specular*mat_specular;
        int counter=0;
        glEnable(GL_DEPTH_TEST);    // need depth test to correctly draw 3D objects 
        glClearColor(0,0,0,1); 
        //glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
        glClear(GL_DEPTH_BUFFER_BIT); 
        glCullFace(GL_FRONT);
        if(wframe)
            glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); 
        else
            glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); 


        glUseProgram(programObject);
        //Draw the stuff using Light Position as camera 
        //glutSwapBuffers();
        glActiveTexture(GL_TEXTURE3);
        glBindTexture(GL_TEXTURE_2D,depthTex);
        glUseProgram(0);  

    }

void generateScene()
{
        //Calculate final ligting properties
    glm::vec4 a_f=light_ambient*mat_ambient;
    glm::vec4 d_f=light_diffuse*mat_diffuse;
    glm::vec4 s_f=light_specular*mat_specular;
    int counter=0;
    glEnable(GL_DEPTH_TEST);    // need depth test to correctly draw 3D objects 
    glClearColor(0,0,0,1); 
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 

    //Draw the stuff using camera as camera position

    }
    glutSwapBuffers();
    glUseProgram(0);  

}



void display() 
{
    glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO); 
    generateShadowTex(); 
    glBindFramebuffer(GL_FRAMEBUFFER, 0); 
    generateScene(); 
}

Upvotes: 1

Views: 432

Answers (1)

ChatCloud
ChatCloud

Reputation: 1200

your depth texture is looking normally, depth covers range from near to far clip planes, you can set some reasonable clipping planes using glFrustumf(...)

Upvotes: 1

Related Questions