Jump to content

  • Log In with Google      Sign In   
  • Create Account

cubemap depth FBO rendering only to all faces the same view?


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 fread   Members   -  Reputation: 240

Like
0Likes
Like

Posted 20 February 2014 - 12:41 PM

hello guys

As seen in OpenGL debugger, my code renders the camera view to all 6x faces of FBO (everytime it overwites all the faces), while it should render first to first face, second to second face, etc.

What's the problem?

Here's my code:


​/*
     


bool ShadowMapFBO::Init(unsigned int WindowWidth, unsigned int WindowHeight)
{
    // Create the FBO
    glGenFramebuffers(1, &m_fbo);


    // Create the depth buffer
    glGenTextures(1, &m_depth);
    glBindTexture(GL_TEXTURE_CUBE_MAP, m_depth);
    
    for (uint i = 0 ; i < 6 ; i++) {
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT32, WindowWidth, WindowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    }


    glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X, m_depth, 0);


    // Disable writes to the color buffer
    glDrawBuffer(GL_NONE);
    
    GLExitIfError();
       
    // Disable reads from the color buffer
    glReadBuffer(GL_NONE);
    
    GLExitIfError();


    GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);


    if (Status != GL_FRAMEBUFFER_COMPLETE) {
        printf("FB error, status: 0x%x\n", Status);
        return false;
    }


    return GLCheckError();
}




void ShadowMapFBO::BindForWriting(GLenum CubeFace)
{
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+CubeFace, m_depth, 0);
}


void ShadowMapFBO::BindForReading(GLenum TextureUnit, int CubeFace)
{
    glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo);    
    GLExitIfError();        
    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+CubeFace, m_depth, 0);    
    GLExitIfError();           
}




Edited by fread, 21 February 2014 - 12:06 AM.


Sponsor:

#2 3TATUK2   Members   -  Reputation: 722

Like
1Likes
Like

Posted 20 February 2014 - 01:48 PM

You don't even show your render code?

 

Assuming you're using something like

BindForWriting(0);
render();
BindForWriting(1);
render();
BindForWriting(2);
render();
BindForWriting(3);
render();
BindForWriting(4);
render();
BindForWriting(5);
render();

You have to set up the proper view in render() . . . Ie, glLookAt() or etc. like I did in the cubeFrustum() example I pasted you.

 

Also, you're not using glBindTexture() correctly . . . You need to call it INDIVIDUALLY for EACH cubemap side, ie, WITHIN your for() loop - not above it. And you need to save each value (or just the starting value, then increment each time) ... Not just one "m_depth" value. And then you'll also need to bind it before rendering.


Edited by 3TATUK2, 20 February 2014 - 01:55 PM.


#3 fread   Members   -  Reputation: 240

Like
0Likes
Like

Posted 20 February 2014 - 11:13 PM

Yes I am settings a proper view after bindForWriting.

for(int i = 0; i < 6; i++)
{
       CubeMapDepthFBO.BeginWriting(i);
       
       glViewport( .... )
       glClear
       
       glMatrixMode( GL_MODELVIEW )
       glLoadMatrix ( ... )
       glMatrixMode( GL_PROJECTION)
       glLoadMatrix( ... )

       RenderScene();
}

The problem is that *every* call to RenderScene is updating all six sides of cubemap.

I mean: after drawing with i=0, all six sides of cubemap contain depth from i=0 point from view.

After i=1, all six sides of cubemap contain depth from i=1 point from view.

I used gDEBugger GL tool to check it.

So each pass is updating all six sides of cubemap instead of specified one.

but hey, maybe its a gDEBugger bug? 

is there any simple way I can display my cubemap on opengl window to check it contents?



#4 3TATUK2   Members   -  Reputation: 722

Like
0Likes
Like

Posted 21 February 2014 - 01:45 PM

Hm. The only difference I can see it to suggest trying GL_FRAMEBUFFER instead of GL_DRAW_FRAMEBUFFER but I doubt this would fix it. Can't hurt to try.

 

Yeah maybe it's something weird with gDEBUGGER.

 

Just render a textured quad with the cubemap bound.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS