0
votes

I switched from render buffer to depth texture in my FBO.But it seem like it doesn't contain any depth data.If I render this texture to a full screen quad everything is black.I am pretty sure the texture and FBO setup is ok.FBO is completed and if I clear depth, let's say to gray :

glClearDepth(0.5f);

Then I see the color in the blit pass, but not the data from the geometry rendering.

Anyway, that is how I create the texture:

                glBindTexture   ( GL_TEXTURE_2D, _id );
            glTexStorage2D(GL_TEXTURE_2D,1,intFmt,theWidth,theHeight);          
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
        glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);   


        glBindTexture(_target,0);

Where intFmt is GL_DEPTH_COMPONENT24 or GL_DEPTH_COMPONENT32 (tried both..)

That is how I attach it to the FBO:

     glBindFramebuffer(GL_FRAMEBUFFER, _frameBuffer);
         glBindTexture(GL_TEXTURE_2D, _id);
     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target,_id, 0);

And this is blit pass fragment shader:

#version 420 
layout(binding=0) uniform sampler2D COLOR_MAP_0;
smooth in vec2 uvsOut;
out vec4 OUTPUT;

void main(void) {

    ivec2 tsize = textureSize(COLOR_MAP_0, 0);
    vec2 screntc = gl_FragCoord.xy * (1.0 / vec2(tsize));
    OUTPUT =  vec4(texture(COLOR_MAP_0, screntc).rrr   ,1) ;

}

Maybe I should explicitly write depth in fragment shader?

I tried to linearize the depth in the blit fragment shader.It works.Now I can see the depth.But I see white and some gray shades without it.In the snapshot:left part is drawn using linearization while the right part samples from depth texture directly. enter image description here

1
How are you displaying your depth texture to verify data? What are near and far clipping planes and distance to geometry you're drawing?keltar
Near is 0.1 ,far 10000 .Distance to geometry is between 0 to 1000.For display depth I just bind depth texture, draw full screen quad using frag shader mentioned above.Michael IV
I don't see anything too wrong with code you've presented. So wrong part is missing. Have you checked that glGetError() is 0 and are you sure your geometry/view matrices are correct?keltar
I am running GL debug extension so getting all the errors right into console.Everything is ok with it.But please see my update.Michael IV
By 'linearize' you mean normalization?keltar

1 Answers

2
votes

It seems okay and normal.

You have to keep in mind that DEPTH is not an RGB data nor it's linear, the actual format depends on what you request ( in the OpenGL context creation ) or the buffer/texture you create for the FBO. DEPTH is always a single channel data however the fragment shader allows you to access however you want .rgb will return data but it'll be incorrect.

The DEPTH data since it's non linear you can think of it as the information is compressed into the closer part to 1.0 so most of the things have values of 0.9998 0.9997, if you you can see the difference in image editor apps but again it's not the way how it should be displayed after all.

To display the DEPTH you need to linearize it so it "makes sense" for that you need to take the near/far plane into account, in that case White == far , Dark ( Black ) == close.