Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Problem Rendering Shadow Map

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    12

    Problem Rendering Shadow Map

    I'm attempting to add shadow mapping to my programs using a spotlight as the light source. I've set up enough to be able to render my shadow map, but whenever I look at it, it's just a black square. I'm certain that I'm rendering it correctly, so the problem is with actually storing depth values in the texture. Does anyone have any ideas what could be causing this?

    Code Snippets:
    Code :
    void ShadowShader::Init(SpotLight Light)
    {
            ...
     
            Source = Light;
            Projection = perspective(Source.Cutoff, 1.0f, 1.f, 20.f);
            View = lookAt(Source.Position_WS, Source.Position_WS + Source.Direction_WS, vec3(0,1,0));
     
            glGenFramebuffers(1, &FrameBufferID);
            glBindFramebuffer(GL_FRAMEBUFFER, FrameBufferID);
     
            glGenTextures(1, &DepthTextureID);
            glBindTexture(GL_TEXTURE_2D, DepthTextureID);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     
            glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, DepthTextureID, 0);
     
            glReadBuffer(GL_NONE);
            glDrawBuffer(GL_NONE);
     
            if( glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE )
            {
                WritetoLog("Failed to Initialize Framebuffer - " + FloatToString(glCheckFramebufferStatus(GL_FRAMEBUFFER)));
                exit(0xBAD);
            }
     
            glBindFramebuffer(GL_FRAMEBUFFER, NULL);
     
            ...
    }

    Code :
    void Display()
    {
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
     
        glEnable(GL_DEPTH_TEST);
     
        ...
     
        //1st Pass
        ShadowProgram.Bind();
        glBindFramebuffer(GL_FRAMEBUFFER, ShadowProgram.GetFrameBufferID());
        glViewport(0,0,1024,1024);
        StandardRendering(); // Draw the scene
        glBindFramebuffer(GL_FRAMEBUFFER, NULL);
        ShadowProgram.UnBind();
     
        //2nd Pass
        glViewport(0,0,WINDOW_DIMENSIONS.x,WINDOW_DIMENSIONS.y);
        StandardProgram.Bind();
     
        Texture Temp;
        Temp.TextureID = ShadowProgram.GetTextureID();
        Temp.ImgHeight = Temp.ImgWidth = Temp.TexHeight = Temp.TexWidth = 1024;
     
        StandardProgram.Scale(30);
        StandardProgram.TransformModel();
        DrawUnitSquare(&Temp);
    }

    ShadowProgram's Shaders:
    Code :
    #version 330 core
     
    layout(location = 0) in vec3 Position;
     
    uniform mat4 depthMVP;
     
    void main()
    {
        gl_Position =  depthMVP * vec4(Position,1);
    }

    Code :
    #version 330 core
     
    layout(location = 0) out float fragmentdepth;
     
    void main()
    {
        fragmentdepth = gl_FragCoord.z;
    }
    Last edited by Niven07; 12-29-2013 at 07:01 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •