Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Depth cubemaps do not work

4: Adsense

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 Gumgo   Members   


Posted 20 October 2012 - 01:50 AM

EDIT: See the 4th 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 textureglGenTextures(1,&texID);glBindTexture(GL_TEXTURE_2D,texID);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_MIN_FILTER,GL_NEAREST);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,32,32,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL);// attach it to the framebufferglFramebufferTexture(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,texID,0);// check status - returns GL_FRAMEBUFFER_COMPLETELog::info() << glCheckFramebufferStatus();// set the clear depth to 0.5 - should produce grayglClearDepth(0.5f);// clear the depth buffer - this does not work!!glClear(GL_DEPTH_BUFFER_BIT);// bind the depth texture so that glIntercept will write it to diskglBindTexture(GL_TEXTURE_2D,texID);[/source]

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, 22 October 2012 - 01:01 PM.

#2 Kaptein   Prime Members   


Posted 20 October 2012 - 03:19 AM

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, 20 October 2012 - 03:34 AM.

#3 larspensjo   Members   


Posted 21 October 2012 - 01:25 AM

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 https://github.com/larspensjo/ephenation-client/blob/master/Source/shadowrender.cpp#L43. Notice that I use a usual sampler, not a shadow map sampler.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#4 Gumgo   Members   


Posted 22 October 2012 - 01:29 AM

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 was 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 binding layered depth textures to the depth attachment of a framebuffer. 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, 22 October 2012 - 12:59 PM.

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.