• Advertisement
Sign in to follow this  

Depth cubemaps do not work

This topic is 1916 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[b]EDIT:[/b] See the [url="http://www.gamedev.net/topic/633083-depth-renderbuffer-works-but-depth-texture-does-not/page__p__4992697#entry4992697"]4th[/url] post for an update.

I'm attempting to set up a depth cube map for omnidirectional shadow mapping, but I've run into issues - specifically, I can't write to depth textures; however, using a renderbuffer in the same place works (I know this because I am currently using a depth renderbuffer in my FBO, and when I change it to a depth texture nothing is ever written). This includes both writing via the fragment shader AND a simple glClear() call - so the problem is also not that I'm just drawing my geometry wrong. Additionally, I have made sure to call glDepthMask( GL_TRUE ).

Here is a short section of code which exhibits the issue for me (FBO creation code left out, but I've used that extensively and it works):

[source lang="cpp"]int texID;
// generate depth texture
// attach it to the framebuffer
// check status - returns GL_FRAMEBUFFER_COMPLETE
Log::info() << glCheckFramebufferStatus();
// set the clear depth to 0.5 - should produce gray
// clear the depth buffer - this does not work!!

// bind the depth texture so that glIntercept will write it to disk

However, instead of producing a texture filled with 0.5 depth (would appear gray), it's filled with mostly black and a bit of garbage scattered around the edges.

I've looked at tutorials and I can't seem to find anything I'm doing differently. The example above is pretty much as simple as I could get it. I've also tried different versions of glFramebufferTexture, such as glFramebufferTexture2D, but that didn't make a difference.

My card is ATI HD Radeon 5870 and I have Catalyst 12.8 (ver. 2012.0806.1213.19931). Edited by Gumgo

Share this post

Link to post
Share on other sites
edit: i dont think you can write to depth textures in anything but a renderbuffer
but you can always try R16 or something (by something, i mean something supported by drivers), write to that
but how is that going to be used as depth? and you cant use gl_FragDepth anymore then

im not much help am i :)
seems like someone who actually does shadowmapping should help, im just a simple raycaster guy who never had to deal with that :P Edited by Kaptein

Share this post

Link to post
Share on other sites
I think you should use glFramebufferTexture2D to be able to tell OpenGL it is a GL_TEXTURE_2D.

You can compare with my source code at [url="https://github.com/larspensjo/ephenation-client/blob/master/Source/shadowrender.cpp#L43"]https://github.com/larspensjo/ephenation-client/blob/master/Source/shadowrender.cpp#L43[/url]. Notice that I use a usual sampler, not a shadow map sampler.

Share this post

Link to post
Share on other sites
Well I finally managed to get 2D depth texture writes to work! The issue with that actually turned out to be rather annoying - I had previously been failing to write to cube map depth textures, so I tried binding a dummy 1x1 cubemap color texture to the framebuffer to see if that made a difference, which it did not. When I switched to trying it with 2D depth textures, for some reason I simply changed that dummy texture to 2D rather than remove it entirely. So when I rendered to the depth texture I got a black image with a single gray pixel in the corner. I assumed this meant the whole texture was just "garbage" since I'd gotten similar garbage results before, but it actually turned out that the depth texture [i]was[/i] being clearly - but only the small 1x1 section that overlapped the dummy color texture! I wouldn't have thought this would be the case since I did in fact set the viewport to the size of the depth texture.

So it turns out (I guess) that the region written to the depth buffer is not only determined by the viewport size, but also by the color attachment sizes. Anyway, now that 2D depth textures are working, I'll see what cube map depth textures do...

EDIT: So switching from the 2D depth texture to cube depth texture now appears to screw up future FBO depth buffer operations, as now the main depth (renderbuffer) is completely black (depth = 0) causing nothing to draw. Again, all I am doing is binding a depth cube map to the depth component of the FBO, and then calling glClear( GL_DEPTH_BUFFER_BIT ) with a value of 0.5f. And this seems to mess up future depth buffer operations. However, the cubemap is in fact cleared to 0.5f! (At least it is on the very first frame - I think after that point, depth operations are all messed up, so it ends up as pure black too.)

I tried a few other things as well, including the following:
- Binding a single face of the cube map to the depth attachment using glFramebufferTexture2D(). This DOES work - it clears the single face and doesn't mess up future framebuffer operations.
- Binding a cube map texture (of format RGBA) to a color attachment and clearing it. This DOES work - it clears the color cube map and doesn't mess up future framebuffer operations.
- Binding a 2D texture array to the depth attachment using glFramebufferTexture(). This DOES NOT work - the same behavior as with cube maps is exhibited: on the first frame the whole texture is properly cleared, but after that point all depth operations on the framebuffer get messed up.
- Binding a single layer of a 2D texture array to the depth attachment using glFramebufferTextureLayer(). This DOES work - it clears the single layer and doesn't mess up future framebuffer operations.

So from these results, the problem seems to be only with [b]binding layered depth textures to the depth attachment of a framebuffer.[/b] Specifically, when I do this and then perform a write operation, that single operation works but all future write operations on any depth attachment don't seem to have any effect.

Has anyone experienced behavior like this? It seems to me like a driver bug. I'd really like to get single-pass shadow mapping working with the geometry shader, but it doesn't seem like this is going to work anymore. Edited by Gumgo

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement